import gradio as gr from models import ModelManager from prediction import PredictionEngine from stats import StatsManager from css import get_custom_css from examples import EXAMPLE_DATA def create_interface(): """Create and configure the Gradio interface""" # Initialize components model_manager = ModelManager() prediction_engine = PredictionEngine(model_manager) # Create interface with gr.Blocks(css=get_custom_css(), title="🧠 Financial Sentiment Analyzer", theme=gr.themes.Base()) as interface: # Header gr.HTML("""

🧠 Financial News Sentiment Analyzer

Powered by AI • Analyze financial news sentiment with advanced ML models

""") # Main content with gr.Row(): # Input column with gr.Column(scale=2): text_input = gr.Textbox( lines=4, placeholder="💼 Enter financial news headline or text...\n\nExample: 'Apple stock surges after strong earnings report'", label="📝 Financial News Text" ) model_choice = gr.Radio( choices=["Naive Bayes", "BERT"], value=model_manager.default_model, label="🤖 Select AI Model", info="Choose between Naive Bayes (fast) or BERT (advanced)" ) predict_btn = gr.Button( "🔍 Analyze Sentiment", variant="primary", elem_classes=["submit-btn"] ) # Examples gr.Examples( examples=EXAMPLE_DATA, inputs=[text_input, model_choice], label="💡 Try these examples:", ) # Output column with gr.Column(scale=1): output = gr.HTML( value="
👆 Enter text and click analyze to see results
", label="📊 Analysis Result" ) stats_display = gr.HTML( label="📈 Usage Statistics" ) refresh_stats_btn = gr.Button("🔄 Refresh Stats", variant="secondary") # Event handlers predict_btn.click( fn=prediction_engine.predict_sentiment, inputs=[text_input, model_choice], outputs=output ) refresh_stats_btn.click( fn=StatsManager.get_stats, inputs=None, outputs=stats_display ) # Load initial stats interface.load(StatsManager.get_stats, None, stats_display) # Footer gr.HTML(""" """) return interface, model_manager