pentarosarium commited on
Commit
18fcf1b
·
1 Parent(s): f17b493

progress more (3.8)

Browse files
Files changed (1) hide show
  1. app.py +10 -71
app.py CHANGED
@@ -39,17 +39,7 @@ def create_download_section(excel_data, pdf_data):
39
  else:
40
  st.error("Ошибка при создании Excel файла")
41
 
42
- with col2:
43
- if pdf_data is not None:
44
- st.download_button(
45
- label="📄 Скачать PDF протокол",
46
- data=pdf_data,
47
- file_name="протокол_анализа.pdf",
48
- mime="application/pdf",
49
- key="pdf_download"
50
- )
51
- else:
52
- st.error("Ошибка при создании PDF файла")
53
 
54
 
55
  def display_sentiment_results(row, sentiment, impact=None, reasoning=None):
@@ -79,59 +69,8 @@ def display_sentiment_results(row, sentiment, impact=None, reasoning=None):
79
  st.write("---")
80
 
81
 
82
- class StreamlitCapture:
83
- def __init__(self):
84
- self.texts = []
85
-
86
- def write(self, text):
87
- if text and str(text).strip(): # Only capture non-empty text
88
- self.texts.append(str(text))
89
-
90
- def flush(self):
91
- pass
92
 
93
 
94
-
95
- def generate_pdf_report(texts):
96
- try:
97
- import pdfkit
98
- from jinja2 import Template
99
-
100
- st.write("Подготовка PDF...")
101
-
102
- html_content = """
103
- <html>
104
- <head>
105
- <meta charset="UTF-8">
106
- <style>
107
- body { font-family: Arial, sans-serif; }
108
- .content { margin: 20px; }
109
- </style>
110
- </head>
111
- <body>
112
- <div class="content">
113
- {% for text in texts %}
114
- <p>{{ text }}</p>
115
- {% endfor %}
116
- </div>
117
- </body>
118
- </html>
119
- """
120
-
121
- template = Template(html_content)
122
- rendered_html = template.render(texts=texts)
123
-
124
- # Create PDF in memory
125
- st.write("Конвертация в PDF...")
126
- pdf_data = pdfkit.from_string(rendered_html, False) # False means return PDF as bytes
127
- st.write("PDF успешно создан")
128
- return pdf_data
129
-
130
- except Exception as e:
131
- st.warning(f"Не удалось создать PDF отчет: {str(e)}")
132
- st.write("Создание текстового отчета вместо PDF...")
133
- # Return the text as bytes if PDF generation fails
134
- return '\n'.join(texts).encode('utf-8')
135
 
136
  # Initialize sentiment analyzers
137
  finbert = pipeline("sentiment-analysis", model="ProsusAI/finbert")
@@ -348,26 +287,26 @@ def process_file(uploaded_file):
348
 
349
 
350
  # Generate all output files
351
- st.write("Генерация отчетов...")
352
 
353
  # 1. Generate Excel
354
  excel_output = create_output_file(df, uploaded_file)
355
 
356
  # 2. Generate PDF
357
- st.write("Создание PDF протокола...")
358
- pdf_data = generate_pdf_report(output_capture.texts)
359
 
360
  # Save PDF to disk
361
- if pdf_data:
362
- with open("result.pdf", "wb") as f:
363
- f.write(pdf_data)
364
- st.success("PDF протокол сохранен как 'result.pdf'")
365
 
366
  # Show success message
367
- st.success(f"✅ Обработка и анализ завершены за умеренное время.")
368
 
369
  # Create download section
370
- create_download_section(excel_output, pdf_data)
371
 
372
  return df
373
 
 
39
  else:
40
  st.error("Ошибка при создании Excel файла")
41
 
42
+
 
 
 
 
 
 
 
 
 
 
43
 
44
 
45
  def display_sentiment_results(row, sentiment, impact=None, reasoning=None):
 
69
  st.write("---")
70
 
71
 
 
 
 
 
 
 
 
 
 
 
72
 
73
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
74
 
75
  # Initialize sentiment analyzers
76
  finbert = pipeline("sentiment-analysis", model="ProsusAI/finbert")
 
287
 
288
 
289
  # Generate all output files
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 протокола...")
297
+ #pdf_data = generate_pdf_report(output_capture.texts)
298
 
299
  # Save PDF to disk
300
+ #if pdf_data:
301
+ # with open("result.pdf", "wb") as f:
302
+ # f.write(pdf_data)
303
+ # st.success("PDF протокол сохранен как 'result.pdf'")
304
 
305
  # Show success message
306
+ #st.success(f"✅ Обработка и анализ завершены за умеренное время.")
307
 
308
  # Create download section
309
+ create_download_section(excel_output,"")
310
 
311
  return df
312