File size: 3,864 Bytes
fe63ba2 6bc68ba fe63ba2 6bc68ba fe63ba2 49dead4 fe63ba2 49dead4 fe63ba2 49dead4 fe63ba2 49dead4 fe63ba2 49dead4 fe63ba2 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
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 |