Spaces:
Sleeping
Sleeping
| import streamlit as st | |
| import requests | |
| import json | |
| import pandas as pd | |
| import plotly.express as px | |
| import os | |
| # ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| # CONFIG | |
| # ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| API_URL = os.getenv("API_URL", "http://api:8000") | |
| st.set_page_config( | |
| page_title="Financial Sentiment Analysis", | |
| page_icon="π", | |
| layout="wide" | |
| ) | |
| # ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| # UI HELPERS | |
| # ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| def get_prediction(text): | |
| try: | |
| response = requests.post(f"{API_URL}/predict", json={"text": text}) | |
| if response.status_code == 200: | |
| return response.json() | |
| else: | |
| st.error(f"API Error: {response.status_code}") | |
| return None | |
| except Exception as e: | |
| st.error(f"Connection Error: {e}") | |
| return None | |
| # ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| # MAIN UI | |
| # ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| st.title("π Financial Sentiment Analysis") | |
| st.markdown(""" | |
| Bu dashboard, finansal haberler ve tweetler ΓΌzerindeki duyguyu (sentiment) | |
| analiz etmek iΓ§in eΔitilmiΕ bir **FinBERT** modelini kullanΔ±r. | |
| """) | |
| col1, col2 = st.columns([2, 1]) | |
| with col1: | |
| user_input = st.text_area( | |
| "Analiz edilecek finansal metni girin:", | |
| placeholder="Γrn: The company reported strong quarterly earnings with a 20% increase in revenue...", | |
| height=150 | |
| ) | |
| analyze_button = st.button("Analiz Et", type="primary") | |
| if analyze_button and user_input: | |
| with st.spinner("Model analiz ediyor..."): | |
| result = get_prediction(user_input) | |
| if result: | |
| st.success("Analiz TamamlandΔ±!") | |
| # Ana SonuΓ§ | |
| sentiment = result["sentiment"].upper() | |
| confidence = result["confidence"] | |
| st.metric("Tahmin Edilen Duygu", sentiment, f"{confidence:.2%} Confidence") | |
| # Skorlar | |
| scores = result["scores"] | |
| df_scores = pd.DataFrame({ | |
| "Sentiment": list(scores.keys()), | |
| "Score": list(scores.values()) | |
| }) | |
| with col2: | |
| st.subheader("OlasΔ±lΔ±k DaΔΔ±lΔ±mΔ±") | |
| fig = px.pie( | |
| df_scores, | |
| values="Score", | |
| names="Sentiment", | |
| color="Sentiment", | |
| color_discrete_map={ | |
| "positive": "#00CC96", | |
| "neutral": "#636EFA", | |
| "negative": "#EF553B" | |
| } | |
| ) | |
| st.plotly_chart(fig, use_container_width=True) | |
| st.json(result) | |
| elif analyze_button and not user_input: | |
| st.warning("LΓΌtfen bir metin girin.") | |
| # Sidebar - API Health | |
| st.sidebar.header("Sistem Durumu") | |
| try: | |
| health = requests.get(f"{API_URL}/health").json() | |
| st.sidebar.success("API: BaΔlΔ± β ") | |
| st.sidebar.info(f"Cihaz: {health.get('device', 'unknown')}") | |
| except: | |
| st.sidebar.error("API: BaΔlantΔ± Kesildi β") | |
| st.sidebar.markdown("---") | |
| st.sidebar.caption("v1.0.0 | Financial Sentiment API") | |