|
|
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"""
|
|
|
|
|
|
model_manager = ModelManager()
|
|
|
prediction_engine = PredictionEngine(model_manager)
|
|
|
|
|
|
|
|
|
with gr.Blocks(css=get_custom_css(), title="π§ Financial Sentiment Analyzer", theme=gr.themes.Base()) as interface:
|
|
|
|
|
|
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>
|
|
|
""")
|
|
|
|
|
|
|
|
|
with gr.Row():
|
|
|
|
|
|
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"]
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
gr.Examples(
|
|
|
examples=EXAMPLE_DATA,
|
|
|
inputs=[text_input, model_choice],
|
|
|
label="π‘ Try these examples:",
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
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")
|
|
|
|
|
|
|
|
|
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
|
|
|
)
|
|
|
|
|
|
|
|
|
interface.load(StatsManager.get_stats, None, stats_display)
|
|
|
|
|
|
|
|
|
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 |