File size: 1,276 Bytes
db90c16
 
6149112
 
a75bec5
6149112
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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()