import gradio as gr | |
import requests | |
API_URL = "https://api-inference.huggingface.co/models/Karim-Gamal/switch-base-8-finetuned-SemEval-2018-emojis-cen-2" | |
headers = {"Authorization": "Bearer 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"} | |
def query(payload): | |
response = requests.post(API_URL, headers=headers, json=payload) | |
return response.json() | |
def sketch_recognition(text): | |
output_temp = query({ | |
"inputs": text, | |
}) | |
text_to_emoji = {'red' : 'β€', 'face': 'π', 'joy':'π', 'love':'π', 'fire':'π₯', 'smile':'π', 'sunglasses':'π', 'sparkle':'β¨', 'blue':'π', 'kiss':'π', 'camera':'π·', 'USA':'πΊπΈ', 'sun':'β' , 'purple':'π', 'blink':'π', 'hundred':'π―', 'beam':'π', 'tree':'π', 'flash':'πΈ', 'tongue':'π'} | |
# Extract the dictionary from the list | |
d = output_temp[0] | |
# Extract the text from the 'generated_text' key | |
text = d['generated_text'] | |
return text_to_emoji[text.split(' ')[0]] | |
# Split the text into individual words | |
# pass# Implement your sketch recognition model here... | |
gr.Interface(fn=sketch_recognition, inputs="text", outputs="text").launch() | |
# gr.Interface.load("models/Karim-Gamal/switch-base-8-finetuned-SemEval-2018-emojis-cen-1").launch() |