Spaces:
Runtime error
Runtime error
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +36 -38
src/streamlit_app.py
CHANGED
|
@@ -41,47 +41,9 @@ st.altair_chart(alt.Chart(df, height=700, width=700)
|
|
| 41 |
size=alt.Size("rand", legend=None, scale=alt.Scale(range=[1, 150])),
|
| 42 |
))
|
| 43 |
|
| 44 |
-
'''
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
import streamlit as st
|
| 49 |
-
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
| 50 |
-
import torch
|
| 51 |
-
import torch.nn.functional as F
|
| 52 |
-
import os
|
| 53 |
-
|
| 54 |
-
st.set_page_config(page_title="💰 FinBERT: Financial Sentiment Analysis", layout="centered")
|
| 55 |
-
st.title("💰 FinBERT: Financial Sentiment Analysis")
|
| 56 |
-
st.markdown("Модель: `yiyanghkust/finbert-tone` — обучена на финансовых текстах")
|
| 57 |
-
|
| 58 |
-
@st.cache_resource
|
| 59 |
-
def load_model():
|
| 60 |
-
# Установка кастомного пути к кэшу
|
| 61 |
-
cache_dir = "/tmp/huggingface"
|
| 62 |
-
os.makedirs(cache_dir, exist_ok=True)
|
| 63 |
-
|
| 64 |
-
tokenizer = AutoTokenizer.from_pretrained("yiyanghkust/finbert-tone", cache_dir=cache_dir)
|
| 65 |
-
model = AutoModelForSequenceClassification.from_pretrained("yiyanghkust/finbert-tone", cache_dir=cache_dir)
|
| 66 |
-
return tokenizer, model
|
| 67 |
-
|
| 68 |
-
tokenizer, model = load_model()
|
| 69 |
-
|
| 70 |
-
text = st.text_area("Введите финансовую новость или отчёт:", height=150)
|
| 71 |
-
|
| 72 |
-
if st.button("Анализировать тональность") and text.strip():
|
| 73 |
-
inputs = tokenizer(text, return_tensors="pt", truncation=True, padding=True)
|
| 74 |
-
with torch.no_grad():
|
| 75 |
-
outputs = model(**inputs)
|
| 76 |
-
probs = F.softmax(outputs.logits, dim=1).squeeze()
|
| 77 |
-
|
| 78 |
-
labels = ["📉 Negative", "😐 Neutral", "📈 Positive"]
|
| 79 |
-
for label, prob in zip(labels, probs):
|
| 80 |
-
st.write(f"**{label}:** {prob.item():.3f}")
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
-
'''
|
| 85 |
import streamlit as st
|
| 86 |
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
| 87 |
import torch
|
|
@@ -445,3 +407,39 @@ st.markdown("""
|
|
| 445 |
|
| 446 |
'''
|
| 447 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
size=alt.Size("rand", legend=None, scale=alt.Scale(range=[1, 150])),
|
| 42 |
))
|
| 43 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
|
| 45 |
|
| 46 |
|
|
|
|
| 47 |
import streamlit as st
|
| 48 |
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
| 49 |
import torch
|
|
|
|
| 407 |
|
| 408 |
'''
|
| 409 |
|
| 410 |
+
|
| 411 |
+
|
| 412 |
+
import streamlit as st
|
| 413 |
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
| 414 |
+
import torch
|
| 415 |
+
import torch.nn.functional as F
|
| 416 |
+
import os
|
| 417 |
+
|
| 418 |
+
st.set_page_config(page_title="💰 FinBERT: Financial Sentiment Analysis", layout="centered")
|
| 419 |
+
st.title("💰 FinBERT: Financial Sentiment Analysis")
|
| 420 |
+
st.markdown("Модель: `yiyanghkust/finbert-tone` — обучена на финансовых текстах")
|
| 421 |
+
|
| 422 |
+
@st.cache_resource
|
| 423 |
+
def load_model():
|
| 424 |
+
# Установка кастомного пути к кэшу
|
| 425 |
+
cache_dir = "/tmp/huggingface"
|
| 426 |
+
os.makedirs(cache_dir, exist_ok=True)
|
| 427 |
+
|
| 428 |
+
tokenizer = AutoTokenizer.from_pretrained("yiyanghkust/finbert-tone", cache_dir=cache_dir)
|
| 429 |
+
model = AutoModelForSequenceClassification.from_pretrained("yiyanghkust/finbert-tone", cache_dir=cache_dir)
|
| 430 |
+
return tokenizer, model
|
| 431 |
+
|
| 432 |
+
tokenizer, model = load_model()
|
| 433 |
+
|
| 434 |
+
text = st.text_area("Введите финансовую новость или отчёт:", height=150)
|
| 435 |
+
|
| 436 |
+
if st.button("Анализировать тональность") and text.strip():
|
| 437 |
+
inputs = tokenizer(text, return_tensors="pt", truncation=True, padding=True)
|
| 438 |
+
with torch.no_grad():
|
| 439 |
+
outputs = model(**inputs)
|
| 440 |
+
probs = F.softmax(outputs.logits, dim=1).squeeze()
|
| 441 |
+
|
| 442 |
+
labels = ["📉 Negative", "😐 Neutral", "📈 Positive"]
|
| 443 |
+
for label, prob in zip(labels, probs):
|
| 444 |
+
st.write(f"**{label}:** {prob.item():.3f}")
|
| 445 |
+
|