pentarosarium commited on
Commit
94c8f6d
·
1 Parent(s): 10f44f6

4.17 + finberts

Browse files
Files changed (1) hide show
  1. app.py +23 -8
app.py CHANGED
@@ -36,6 +36,21 @@ import plotly.graph_objects as go
36
  from datetime import datetime
37
  import plotly.express as px
38
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
39
 
40
  class ProcessControl:
41
  def __init__(self):
@@ -1024,7 +1039,7 @@ def process_file(uploaded_file, model_choice, translation_method=None):
1024
  result_df['Сводка'] = svodka_df.to_dict('records')
1025
  result_df['Публикации'] = processed_rows_df.to_dict('records')
1026
 
1027
- output = create_output_file(processed_rows_df, uploaded_file)
1028
  if output is not None:
1029
  st.download_button(
1030
  label=f"📊 Скачать результат ({processed_rows} из {total_rows} строк)",
@@ -1152,9 +1167,9 @@ def display_sentiment_results(row, sentiment, impact=None, reasoning=None):
1152
 
1153
 
1154
  # Initialize sentiment analyzers
1155
- finbert = pipeline("sentiment-analysis", model="ProsusAI/finbert")
1156
- roberta = pipeline("sentiment-analysis", model="cardiffnlp/twitter-roberta-base-sentiment")
1157
- finbert_tone = pipeline("sentiment-analysis", model="yiyanghkust/finbert-tone")
1158
 
1159
 
1160
  def get_mapped_sentiment(result):
@@ -1170,13 +1185,13 @@ def get_mapped_sentiment(result):
1170
  def analyze_sentiment(text):
1171
  try:
1172
  finbert_result = get_mapped_sentiment(
1173
- finbert(text, truncation=True, max_length=512)[0]
1174
  )
1175
  roberta_result = get_mapped_sentiment(
1176
- roberta(text, truncation=True, max_length=512)[0]
1177
  )
1178
  finbert_tone_result = get_mapped_sentiment(
1179
- finbert_tone(text, truncation=True, max_length=512)[0]
1180
  )
1181
 
1182
  # Count occurrences of each sentiment
@@ -1532,7 +1547,7 @@ def main():
1532
  st.set_page_config(layout="wide")
1533
 
1534
  with st.sidebar:
1535
- st.title("::: AI-анализ мониторинга новостей (v.4.16):::")
1536
  st.subheader("по материалам СКАН-ИНТЕРФАКС")
1537
 
1538
  model_choice = st.radio(
 
36
  from datetime import datetime
37
  import plotly.express as px
38
 
39
+ def get_finbert():
40
+ if "finbert" not in st.session_state:
41
+ st.session_state.finbert = pipeline("sentiment-analysis", model="ProsusAI/finbert")
42
+ return st.session_state.finbert
43
+
44
+ def get_roberta():
45
+ if "roberta" not in st.session_state:
46
+ st.session_state.roberta = pipeline("sentiment-analysis", model="cardiffnlp/twitter-roberta-base-sentiment")
47
+ return st.session_state.roberta
48
+
49
+ def get_finbert_tone():
50
+ if "finbert_tone" not in st.session_state:
51
+ st.session_state.finbert_tone = pipeline("sentiment-analysis", model="yiyanghkust/finbert-tone")
52
+ return st.session_state.finbert_tone
53
+
54
 
55
  class ProcessControl:
56
  def __init__(self):
 
1039
  result_df['Сводка'] = svodka_df.to_dict('records')
1040
  result_df['Публикации'] = processed_rows_df.to_dict('records')
1041
 
1042
+ output = create_output_file(result_df, uploaded_file)
1043
  if output is not None:
1044
  st.download_button(
1045
  label=f"📊 Скачать результат ({processed_rows} из {total_rows} строк)",
 
1167
 
1168
 
1169
  # Initialize sentiment analyzers
1170
+ #finbert = pipeline("sentiment-analysis", model="ProsusAI/finbert")
1171
+ #roberta = pipeline("sentiment-analysis", model="cardiffnlp/twitter-roberta-base-sentiment")
1172
+ #finbert_tone = pipeline("sentiment-analysis", model="yiyanghkust/finbert-tone")
1173
 
1174
 
1175
  def get_mapped_sentiment(result):
 
1185
  def analyze_sentiment(text):
1186
  try:
1187
  finbert_result = get_mapped_sentiment(
1188
+ get_finbert()(text, truncation=True, max_length=512)[0]
1189
  )
1190
  roberta_result = get_mapped_sentiment(
1191
+ get_roberta()(text, truncation=True, max_length=512)[0]
1192
  )
1193
  finbert_tone_result = get_mapped_sentiment(
1194
+ get_finbert_tone()(text, truncation=True, max_length=512)[0]
1195
  )
1196
 
1197
  # Count occurrences of each sentiment
 
1547
  st.set_page_config(layout="wide")
1548
 
1549
  with st.sidebar:
1550
+ st.title("::: AI-анализ мониторинга новостей (v.4.17):::")
1551
  st.subheader("по материалам СКАН-ИНТЕРФАКС")
1552
 
1553
  model_choice = st.radio(