Yousif22's picture
Upload folder using huggingface_hub
6bc68ba verified
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("""
<div class="header">
<h1>🧠 Financial News Sentiment Analyzer</h1>
<p>Powered by AI β€’ Analyze financial news sentiment with advanced ML models</p>
</div>
""")
# 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="<div style='text-align: center; padding: 3rem; color: var(--text-inverse);'>πŸ‘† Enter text and click analyze to see results</div>",
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("""
<div class="footer">
<h3 class="stats-title">πŸ‘¨β€πŸ’» Developed by Yousif Al Nasser</h3>
<div class="social-links">
<a href="https://yousif.engineer" target="_blank">🌐 Portfolio Website</a>
<a href="https://linkedin.com/in/yalnasser" target="_blank">πŸ’Ό LinkedIn Profile</a>
<button class="theme-toggle" onclick="document.body.classList.toggle('dark-mode')">
πŸŒ“ Toggle Theme
</button>
</div>
</div>
""")
return interface, model_manager