File size: 867 Bytes
e8a2d7c
 
 
 
6c5550d
e8a2d7c
 
 
6f98bcd
e8a2d7c
6c5550d
e8a2d7c
6c5550d
e8a2d7c
 
 
 
 
 
6c5550d
e8a2d7c
6c5550d
 
e8a2d7c
 
 
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
import gradio as gr
from huggingface_hub import InferenceClient
import os

# Load API key from environment variables
HF_API_TOKEN = os.getenv("HUG_TOKEN_READ")

# Hugging Face Inference API Client
client = InferenceClient(model="mistralai/Mistral-7B-Instruct-v0.1", token=HF_API_TOKEN)

# Function to translate text into emojis
def text_to_emoji(text):
    prompt = f"Convert this sentence into an emoji-sequence of the same meaning and return only the emojis, no explanation:\n\n\"{text}\""
    response = client.text_generation(prompt, max_new_tokens=50)
    return response

# Gradio UI
iface = gr.Interface(
    fn=text_to_emoji,
    inputs=gr.Textbox(lines=2, placeholder="Enter a sentence..."),
    outputs="text",
    title="AI-Powered Emoji Translator",
    description="Enter a sentence, and the AI will transform it into an emoji-version!"
)

iface.launch()