ahm14 commited on
Commit
749417d
·
verified ·
1 Parent(s): 40be765

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -12
app.py CHANGED
@@ -138,7 +138,6 @@ def extract_captions_from_docx(docx_file):
138
  def extract_metadata_from_excel(excel_file):
139
  try:
140
  df = pd.read_excel(excel_file)
141
- # Ensure the required columns are present
142
  required_columns = ["Date", "Media Type", "Number of Pictures", "Number of Videos", "Number of Audios", "Likes", "Comments", "Tagged Audience"]
143
  if not all(col in df.columns for col in required_columns):
144
  st.error("Excel file is missing required columns.")
@@ -236,23 +235,32 @@ if uploaded_excel:
236
  if uploaded_excel:
237
  output_data = merge_metadata_with_generated_data(output_data, excel_metadata)
238
 
 
 
 
 
 
 
 
 
 
 
 
 
 
239
  # Display results in collapsible sections for better UI
240
- if output_data:
241
- for post_number, data in output_data.items():
242
  with st.expander(post_number):
243
  for key, value in data.items():
244
  st.write(f"**{key}:** {value}")
245
 
246
  # Create DOCX file for download
247
- if output_data:
248
- doc = create_docx_from_data(output_data)
249
  docx_io = io.BytesIO()
250
  doc.save(docx_io)
251
  docx_io.seek(0)
252
-
253
- st.download_button(
254
- label="Download Extracted Data as DOCX",
255
- data=docx_io,
256
- file_name="extracted_data.docx",
257
- mime="application/vnd.openxmlformats-officedocument.wordprocessingml.document"
258
- )
 
138
  def extract_metadata_from_excel(excel_file):
139
  try:
140
  df = pd.read_excel(excel_file)
 
141
  required_columns = ["Date", "Media Type", "Number of Pictures", "Number of Videos", "Number of Audios", "Likes", "Comments", "Tagged Audience"]
142
  if not all(col in df.columns for col in required_columns):
143
  st.error("Excel file is missing required columns.")
 
235
  if uploaded_excel:
236
  output_data = merge_metadata_with_generated_data(output_data, excel_metadata)
237
 
238
+ # Filtering or sorting options
239
+ tone_filter = st.multiselect("Filter by Tone", options=["Emotional", "Harsh", "Somber", "Motivational", "Informative", "Positive", "Angry", "Fearful", "Sarcastic", "Hopeful"])
240
+ frame_filter = st.multiselect("Filter by Frame", options=["Human Rights & Justice", "Political & State Accountability", "Gender & Patriarchy", "Religious Freedom & Persecution", "Grassroots Mobilization", "Environmental Crisis & Activism", "Anti-Extremism & Anti-Violence", "Social Inequality & Economic Disparities", "Activism & Advocacy", "Systemic Oppression", "Intersectionality", "Call to Action", "Empowerment & Resistance", "Climate Justice", "Human Rights Advocacy"])
241
+
242
+ # Filtered output
243
+ filtered_data = output_data
244
+
245
+ # Apply filters
246
+ if tone_filter:
247
+ filtered_data = {key: value for key, value in filtered_data.items() if any(tone in tone_filter for tone in value["Tone"])}
248
+ if frame_filter:
249
+ filtered_data = {key: value for key, value in filtered_data.items() if any(frame in frame_filter for frame in value["Frames"])}
250
+
251
  # Display results in collapsible sections for better UI
252
+ if filtered_data:
253
+ for post_number, data in filtered_data.items():
254
  with st.expander(post_number):
255
  for key, value in data.items():
256
  st.write(f"**{key}:** {value}")
257
 
258
  # Create DOCX file for download
259
+ if filtered_data:
260
+ doc = create_docx_from_data(filtered_data)
261
  docx_io = io.BytesIO()
262
  doc.save(docx_io)
263
  docx_io.seek(0)
264
+ st.download_button(label="Download Analysis as DOCX", data=docx_io, file_name="analysis.docx")
265
+ else:
266
+ st.warning("No data available after applying filters.")