Spaces:
Running
Running
Commit ·
1fd794f
1
Parent(s): 4ff6c1a
progress more (3.1+)
Browse files
app.py
CHANGED
|
@@ -19,6 +19,27 @@ from io import StringIO
|
|
| 19 |
import contextlib
|
| 20 |
|
| 21 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
# Initialize sentiment analyzers
|
| 24 |
finbert = pipeline("sentiment-analysis", model="ProsusAI/finbert")
|
|
@@ -388,7 +409,7 @@ def main():
|
|
| 388 |
if st.session_state.processed_df is not None:
|
| 389 |
save_to_pdf(output) # Save the captured output to PDF
|
| 390 |
|
| 391 |
-
|
| 392 |
st.download_button(
|
| 393 |
label="Скачать результат анализа",
|
| 394 |
data=output,
|
|
|
|
| 19 |
import contextlib
|
| 20 |
|
| 21 |
|
| 22 |
+
@contextlib.contextmanager
|
| 23 |
+
def capture_streamlit_output():
|
| 24 |
+
# Create StringIO object to capture output
|
| 25 |
+
output = StringIO()
|
| 26 |
+
with contextlib.redirect_stdout(output):
|
| 27 |
+
yield output
|
| 28 |
+
|
| 29 |
+
def save_to_pdf(output_text):
|
| 30 |
+
doc = SimpleDocTemplate("result.pdf", pagesize=letter)
|
| 31 |
+
styles = getSampleStyleSheet()
|
| 32 |
+
story = []
|
| 33 |
+
|
| 34 |
+
# Split the captured output into lines
|
| 35 |
+
lines = output_text.getvalue().split('\n')
|
| 36 |
+
for line in lines:
|
| 37 |
+
if line.strip(): # Skip empty lines
|
| 38 |
+
p = Paragraph(line, styles['Normal'])
|
| 39 |
+
story.append(p)
|
| 40 |
+
story.append(Spacer(1, 12)) # Add space between paragraphs
|
| 41 |
+
|
| 42 |
+
doc.build(story)
|
| 43 |
|
| 44 |
# Initialize sentiment analyzers
|
| 45 |
finbert = pipeline("sentiment-analysis", model="ProsusAI/finbert")
|
|
|
|
| 409 |
if st.session_state.processed_df is not None:
|
| 410 |
save_to_pdf(output) # Save the captured output to PDF
|
| 411 |
|
| 412 |
+
|
| 413 |
st.download_button(
|
| 414 |
label="Скачать результат анализа",
|
| 415 |
data=output,
|