Spaces:
Sleeping
Sleeping
Dan Mo
Refactor application structure: implement EmojiProcessor, enhance Gradio interface, and add configuration management
cf957e4
""" | |
Main application file for the Emoji Mashup app. | |
This module handles the Gradio interface and application setup. | |
""" | |
import gradio as gr | |
from utils import logger | |
from emoji_processor import EmojiProcessor | |
class EmojiMashupApp: | |
def __init__(self): | |
"""Initialize the Gradio application.""" | |
logger.info("Initializing Emoji Mashup App") | |
self.processor = EmojiProcessor() | |
self.processor.load_emoji_dictionaries() | |
def create_interface(self): | |
"""Create and configure the Gradio interface. | |
Returns: | |
Gradio Interface object | |
""" | |
return gr.Interface( | |
fn=self.processor.sentence_to_emojis, | |
inputs=gr.Textbox(lines=2, placeholder="Type a sentence..."), | |
outputs=[ | |
gr.Text(label="Top Emotion Emoji"), | |
gr.Text(label="Top Event Emoji"), | |
gr.Image(label="Mashup Emoji") | |
], | |
title="Sentence → Emoji Mashup", | |
description="Get the top emotion and event emoji from your sentence, and view the mashup!", | |
examples=[ | |
["I feel so happy today!"], | |
["I'm really angry right now"], | |
["Feeling tired after a long day"] | |
] | |
) | |
def run(self, share=True): | |
"""Launch the Gradio application. | |
Args: | |
share: Whether to create a public sharing link | |
""" | |
logger.info("Starting Emoji Mashup App") | |
interface = self.create_interface() | |
interface.launch(share=share) | |
# Main entry point | |
if __name__ == "__main__": | |
app = EmojiMashupApp() | |
app.run(share=True) |