Spaces:
Sleeping
Sleeping
| 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() | |