ahm14 commited on
Commit
5a10e8d
·
verified ·
1 Parent(s): 2c42a2f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -17
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 in the temporary directory accessible in Streamlit
114
- file_path = os.path.join("/tmp", "activism_message_analysis.docx")
115
  doc.save(file_path)
116
-
117
- # Check if the file exists and is valid
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=open(generate_docx(output), 'rb').read(), # Open file in binary mode
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
  )