File size: 934 Bytes
3574d28
 
 
 
 
 
 
 
 
 
 
 
8fdc949
 
 
 
 
 
3574d28
 
 
 
 
 
 
 
 
8fdc949
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
import gradio as gr
from transformers import pipeline

# Load GPT-2 model from Hugging Face
generator = pipeline("text-generation", model="gpt2")

def text_to_emoji(text):
    prompt = f"Convert this sentence to emojis: {text} ->"
    
    # Generate emoji output
    result = generator(prompt, max_length=50, num_return_sequences=1)
    
    # Extract the emoji part from the generated text
    emoji_output = result[0]['generated_text']
    
    # Clean the output, removing unnecessary parts and keeping only emojis
    emoji_output = emoji_output.split("->")[-1].strip()
    
    return emoji_output

# Gradio Interface
iface = gr.Interface(fn=text_to_emoji, 
                     inputs=gr.Textbox(label="Enter Text"), 
                     outputs=gr.Textbox(label="Emoji Output"),
                     title="Text-to-Emoji AI",
                     description="Enter a sentence and get the emoji equivalent!")

iface.launch()