Karim-Gamal commited on
Commit
6149112
Β·
1 Parent(s): db90c16

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -1
app.py CHANGED
@@ -1,3 +1,34 @@
1
  import gradio as gr
2
 
3
- gr.Interface.load("models/Karim-Gamal/switch-base-8-finetuned-SemEval-2018-emojis-cen-2").launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
 
3
+ import requests
4
+
5
+ API_URL = "https://api-inference.huggingface.co/models/Karim-Gamal/switch-base-8-finetuned-SemEval-2018-emojis-cen-1"
6
+ headers = {"Authorization": "Bearer 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"}
7
+
8
+
9
+ def query(payload):
10
+ response = requests.post(API_URL, headers=headers, json=payload)
11
+ return response.json()
12
+
13
+
14
+ def sketch_recognition(text):
15
+
16
+ output_temp = query({
17
+ "inputs": text,
18
+ })
19
+
20
+ text_to_emoji = {'red' : '❀', 'face': '😍', 'joy':'πŸ˜‚', 'love':'πŸ’•', 'fire':'πŸ”₯', 'smile':'😊', 'sunglasses':'😎', 'sparkle':'✨', 'blue':'πŸ’™', 'kiss':'😘', 'camera':'πŸ“·', 'USA':'πŸ‡ΊπŸ‡Έ', 'sun':'β˜€' , 'purple':'πŸ’œ', 'blink':'πŸ˜‰', 'hundred':'πŸ’―', 'beam':'😁', 'tree':'πŸŽ„', 'flash':'πŸ“Έ', 'tongue':'😜'}
21
+
22
+ # Extract the dictionary from the list
23
+ d = output_temp[0]
24
+
25
+ # Extract the text from the 'generated_text' key
26
+ text = d['generated_text']
27
+
28
+ return text_to_emoji[text.split(' ')[0]]
29
+ # Split the text into individual words
30
+ # pass# Implement your sketch recognition model here...
31
+
32
+ gr.Interface(fn=sketch_recognition, inputs="text", outputs="text").launch()
33
+
34
+ # gr.Interface.load("models/Karim-Gamal/switch-base-8-finetuned-SemEval-2018-emojis-cen-1").launch()