Update app.py
Browse files
app.py
CHANGED
|
@@ -87,13 +87,6 @@ def categorize_frames(text):
|
|
| 87 |
|
| 88 |
return frames
|
| 89 |
|
| 90 |
-
# Function to generate and download the output as docx
|
| 91 |
-
import os
|
| 92 |
-
|
| 93 |
-
# Function to generate and download the output as docx
|
| 94 |
-
import os
|
| 95 |
-
from docx import Document
|
| 96 |
-
|
| 97 |
# Function to generate and download the output as docx
|
| 98 |
def generate_docx(output):
|
| 99 |
try:
|
|
@@ -110,16 +103,11 @@ def generate_docx(output):
|
|
| 110 |
for frame in output['Frames']:
|
| 111 |
doc.add_paragraph(frame)
|
| 112 |
|
| 113 |
-
# Save the document
|
| 114 |
-
file_path =
|
| 115 |
doc.save(file_path)
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
if os.path.exists(file_path):
|
| 119 |
-
return file_path
|
| 120 |
-
else:
|
| 121 |
-
raise Exception("File saving failed")
|
| 122 |
-
|
| 123 |
except Exception as e:
|
| 124 |
st.write(f"Error generating DOCX file: {e}")
|
| 125 |
return None
|
|
@@ -173,7 +161,7 @@ if input_text:
|
|
| 173 |
# Add download button for the generated docx
|
| 174 |
download_button = st.download_button(
|
| 175 |
label="Download Analysis as DOCX",
|
| 176 |
-
data=
|
| 177 |
file_name="activism_message_analysis.docx",
|
| 178 |
mime="application/vnd.openxmlformats-officedocument.wordprocessingml.document"
|
| 179 |
)
|
|
|
|
| 87 |
|
| 88 |
return frames
|
| 89 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 90 |
# Function to generate and download the output as docx
|
| 91 |
def generate_docx(output):
|
| 92 |
try:
|
|
|
|
| 103 |
for frame in output['Frames']:
|
| 104 |
doc.add_paragraph(frame)
|
| 105 |
|
| 106 |
+
# Save the document
|
| 107 |
+
file_path = "/mnt/data/activism_message_analysis.docx"
|
| 108 |
doc.save(file_path)
|
| 109 |
+
|
| 110 |
+
return file_path
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 111 |
except Exception as e:
|
| 112 |
st.write(f"Error generating DOCX file: {e}")
|
| 113 |
return None
|
|
|
|
| 161 |
# Add download button for the generated docx
|
| 162 |
download_button = st.download_button(
|
| 163 |
label="Download Analysis as DOCX",
|
| 164 |
+
data=generate_docx(output),
|
| 165 |
file_name="activism_message_analysis.docx",
|
| 166 |
mime="application/vnd.openxmlformats-officedocument.wordprocessingml.document"
|
| 167 |
)
|