pentarosarium commited on
Commit
118a5c5
·
1 Parent(s): 931613d
Files changed (1) hide show
  1. app.py +15 -18
app.py CHANGED
@@ -90,20 +90,12 @@ class EventDetector:
90
 
91
  def process_file(file):
92
  try:
93
- gr.Info("Starting file processing...")
94
- if isinstance(file, str):
95
- df = pd.read_excel(file, sheet_name='Публикации')
96
- else:
97
- df = pd.read_excel(file.name, sheet_name='Публикации')
98
-
99
  detector = EventDetector()
100
  processed_rows = []
101
  total = len(df)
102
 
103
  for idx, row in df.iterrows():
104
- if idx % 10 == 0:
105
- gr.Info(f"Processing {idx}/{total} rows...")
106
-
107
  text = str(row.get('Выдержки из текста', ''))
108
  entity = str(row.get('Объект', ''))
109
 
@@ -118,9 +110,13 @@ def process_file(file):
118
  'Event_Summary': event_summary,
119
  'Текст': text
120
  })
 
 
 
 
121
 
122
  result_df = pd.DataFrame(processed_rows)
123
- gr.Info("File processing complete!")
124
  return result_df
125
 
126
  except Exception as e:
@@ -163,7 +159,7 @@ def create_interface():
163
  file_input = gr.File(
164
  label="Загрузите Excel файл",
165
  file_types=[".xlsx"],
166
- type="binary" # Changed from "file" to "binary"
167
  )
168
 
169
  with gr.Row():
@@ -175,7 +171,8 @@ def create_interface():
175
  with gr.Row():
176
  progress = gr.Textbox(
177
  label="Статус",
178
- interactive=False
 
179
  )
180
 
181
  with gr.Row():
@@ -194,17 +191,17 @@ def create_interface():
194
  def analyze(file):
195
  if file is None:
196
  gr.Warning("Пожалуйста, загрузите файл")
197
- return None, None, None, "Ожидание файла"
198
  try:
199
- progress.update("Обработка начата...")
200
- # Modified file handling for binary type
201
- temp_file = file.name # For binary type, file.name contains the path
202
  df = process_file(temp_file)
 
203
  if df.empty:
204
  return None, None, None, "Нет данных для обработки"
205
 
206
  fig_sentiment, fig_events = create_visualizations(df)
207
- return df, fig_sentiment, fig_events, "Обработка завершена"
208
 
209
  except Exception as e:
210
  logger.error(f"Analysis error: {e}")
@@ -212,7 +209,7 @@ def create_interface():
212
  return None, None, None, f"Ошибка: {str(e)}"
213
 
214
  analyze_btn.click(
215
- analyze,
216
  inputs=[file_input],
217
  outputs=[stats, sentiment_plot, events_plot, progress]
218
  )
 
90
 
91
  def process_file(file):
92
  try:
93
+ df = pd.read_excel(file, sheet_name='Публикации')
 
 
 
 
 
94
  detector = EventDetector()
95
  processed_rows = []
96
  total = len(df)
97
 
98
  for idx, row in df.iterrows():
 
 
 
99
  text = str(row.get('Выдержки из текста', ''))
100
  entity = str(row.get('Объект', ''))
101
 
 
110
  'Event_Summary': event_summary,
111
  'Текст': text
112
  })
113
+
114
+ # Log progress to console instead of updating UI directly
115
+ if idx % 10 == 0:
116
+ logger.info(f"Processed {idx}/{total} rows")
117
 
118
  result_df = pd.DataFrame(processed_rows)
119
+ logger.info("File processing complete!")
120
  return result_df
121
 
122
  except Exception as e:
 
159
  file_input = gr.File(
160
  label="Загрузите Excel файл",
161
  file_types=[".xlsx"],
162
+ type="binary"
163
  )
164
 
165
  with gr.Row():
 
171
  with gr.Row():
172
  progress = gr.Textbox(
173
  label="Статус",
174
+ interactive=False,
175
+ value="Ожидание файла..."
176
  )
177
 
178
  with gr.Row():
 
191
  def analyze(file):
192
  if file is None:
193
  gr.Warning("Пожалуйста, загрузите файл")
194
+ return None, None, None, "Ожидание файла..."
195
  try:
196
+ # Instead of updating progress directly, we return new values
197
+ temp_file = file.name
 
198
  df = process_file(temp_file)
199
+
200
  if df.empty:
201
  return None, None, None, "Нет данных для обработки"
202
 
203
  fig_sentiment, fig_events = create_visualizations(df)
204
+ return df, fig_sentiment, fig_events, "Обработка завершена успешно!"
205
 
206
  except Exception as e:
207
  logger.error(f"Analysis error: {e}")
 
209
  return None, None, None, f"Ошибка: {str(e)}"
210
 
211
  analyze_btn.click(
212
+ fn=analyze,
213
  inputs=[file_input],
214
  outputs=[stats, sentiment_plot, events_plot, progress]
215
  )