Commit
Β·
6149112
1
Parent(s):
db90c16
Update app.py
Browse files
app.py
CHANGED
@@ -1,3 +1,34 @@
|
|
1 |
import gradio as gr
|
2 |
|
3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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()
|