Spaces:
Sleeping
Sleeping
File size: 4,041 Bytes
7701077 | 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 103 104 | 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")
|