ResearchEngineering commited on
Commit
596bb4b
·
verified ·
1 Parent(s): 5060e11

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +8 -4
src/streamlit_app.py CHANGED
@@ -47,6 +47,7 @@ import streamlit as st
47
  from transformers import AutoTokenizer, AutoModelForSequenceClassification
48
  import torch
49
  import torch.nn.functional as F
 
50
 
51
  st.set_page_config(page_title="FinBERT Sentiment", layout="centered")
52
  st.title("💰 FinBERT: Financial Sentiment Analysis")
@@ -54,14 +55,17 @@ st.markdown("Модель: `yiyanghkust/finbert-tone` — обучена на ф
54
 
55
  @st.cache_resource
56
  def load_model():
57
- tokenizer = AutoTokenizer.from_pretrained("yiyanghkust/finbert-tone")
58
- model = AutoModelForSequenceClassification.from_pretrained("yiyanghkust/finbert-tone")
 
 
 
 
59
  return tokenizer, model
60
 
61
  tokenizer, model = load_model()
62
 
63
- # Ввод текста
64
- text = st.text_area("Введите финансовую новость, заголовок или отчёт:", height=150)
65
 
66
  if st.button("Анализировать тональность") and text.strip():
67
  inputs = tokenizer(text, return_tensors="pt", truncation=True, padding=True)
 
47
  from transformers import AutoTokenizer, AutoModelForSequenceClassification
48
  import torch
49
  import torch.nn.functional as F
50
+ import os
51
 
52
  st.set_page_config(page_title="FinBERT Sentiment", layout="centered")
53
  st.title("💰 FinBERT: Financial Sentiment Analysis")
 
55
 
56
  @st.cache_resource
57
  def load_model():
58
+ # Установка кастомного пути к кэшу
59
+ cache_dir = "/tmp/huggingface"
60
+ os.makedirs(cache_dir, exist_ok=True)
61
+
62
+ tokenizer = AutoTokenizer.from_pretrained("yiyanghkust/finbert-tone", cache_dir=cache_dir)
63
+ model = AutoModelForSequenceClassification.from_pretrained("yiyanghkust/finbert-tone", cache_dir=cache_dir)
64
  return tokenizer, model
65
 
66
  tokenizer, model = load_model()
67
 
68
+ text = st.text_area("Введите финансовую новость или отчёт:", height=150)
 
69
 
70
  if st.button("Анализировать тональность") and text.strip():
71
  inputs = tokenizer(text, return_tensors="pt", truncation=True, padding=True)