pentarosarium commited on
Commit
b9a262a
·
1 Parent(s): 55b2d76

progress more (3.12a)

Browse files
Files changed (2) hide show
  1. app.py +30 -4
  2. sample_file.xlsx +0 -0
app.py CHANGED
@@ -18,6 +18,26 @@ import pdfkit
18
  from jinja2 import Template
19
 
20
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
  def create_download_section(excel_data, pdf_data):
22
  st.markdown("""
23
  <div class="download-container">
@@ -290,7 +310,7 @@ def process_file(uploaded_file):
290
  st.write("Генерация отчета...")
291
 
292
  # 1. Generate Excel
293
- excel_output = create_output_file(df, uploaded_file)
294
 
295
  # 2. Generate PDF
296
  #st.write("Создание PDF протокола...")
@@ -336,7 +356,7 @@ def create_analysis_data(df):
336
  'Текст сообщения'
337
  ])
338
 
339
- def create_output_file(df, uploaded_file):
340
  wb = load_workbook("sample_file.xlsx")
341
 
342
  # Sort entities by number of negative publications
@@ -390,6 +410,12 @@ def create_output_file(df, uploaded_file):
390
  ws.cell(row=row_idx, column=5, value=row['Объект']) # Column E
391
  ws.cell(row=row_idx, column=6, value=row['Заголовок']) # Column F
392
  ws.cell(row=row_idx, column=7, value="Риск убытка") # Column G
 
 
 
 
 
 
393
  ws.cell(row=row_idx, column=9, value=row['Выдержки из текста']) # Column I
394
  row_idx += 1
395
 
@@ -410,7 +436,7 @@ def create_output_file(df, uploaded_file):
410
  def main():
411
 
412
  with st.sidebar:
413
- st.title("::: AI-анализ мониторинга новостей (v.3.12):::")
414
  st.subheader("по материалам СКАН-ИНТЕРФАКС ")
415
  st.markdown(
416
  """
@@ -469,7 +495,7 @@ def main():
469
  st.subheader("Анализ")
470
  st.dataframe(analysis_df)
471
 
472
- output = create_output_file(st.session_state.processed_df, uploaded_file)
473
 
474
  end_time = time.time()
475
  elapsed_time = end_time - start_time
 
18
  from jinja2 import Template
19
 
20
 
21
+ def translate_reasoning_to_russian(llm, text):
22
+ template = """
23
+ Translate this English explanation to Russian, maintaining a formal business style:
24
+ "{text}"
25
+
26
+ Your response should contain only the Russian translation.
27
+ """
28
+ prompt = PromptTemplate(template=template, input_variables=["text"])
29
+ chain = prompt | llm | RunnablePassthrough()
30
+ response = chain.invoke({"text": text})
31
+
32
+ # Handle different response types
33
+ if hasattr(response, 'content'):
34
+ return response.content.strip()
35
+ elif isinstance(response, str):
36
+ return response.strip()
37
+ else:
38
+ return str(response).strip()
39
+
40
+
41
  def create_download_section(excel_data, pdf_data):
42
  st.markdown("""
43
  <div class="download-container">
 
310
  st.write("Генерация отчета...")
311
 
312
  # 1. Generate Excel
313
+ excel_output = create_output_file(df, uploaded_file, llm)
314
 
315
  # 2. Generate PDF
316
  #st.write("Создание PDF протокола...")
 
356
  'Текст сообщения'
357
  ])
358
 
359
+ def create_output_file(df, uploaded_file, llm):
360
  wb = load_workbook("sample_file.xlsx")
361
 
362
  # Sort entities by number of negative publications
 
410
  ws.cell(row=row_idx, column=5, value=row['Объект']) # Column E
411
  ws.cell(row=row_idx, column=6, value=row['Заголовок']) # Column F
412
  ws.cell(row=row_idx, column=7, value="Риск убытка") # Column G
413
+
414
+ # Translate reasoning if it exists
415
+ if pd.notna(row['Reasoning']):
416
+ translated_reasoning = translate_reasoning_to_russian(llm, row['Reasoning'])
417
+ ws.cell(row=row_idx, column=8, value=translated_reasoning) # Column H
418
+
419
  ws.cell(row=row_idx, column=9, value=row['Выдержки из текста']) # Column I
420
  row_idx += 1
421
 
 
436
  def main():
437
 
438
  with st.sidebar:
439
+ st.title("::: AI-анализ мониторинга новостей (v.3.12a):::")
440
  st.subheader("по материалам СКАН-ИНТЕРФАКС ")
441
  st.markdown(
442
  """
 
495
  st.subheader("Анализ")
496
  st.dataframe(analysis_df)
497
 
498
+ output = create_output_file(st.session_state.processed_df, uploaded_file, llm)
499
 
500
  end_time = time.time()
501
  elapsed_time = end_time - start_time
sample_file.xlsx CHANGED
Binary files a/sample_file.xlsx and b/sample_file.xlsx differ