ahm14 commited on
Commit
248922c
·
verified ·
1 Parent(s): bba1b37

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -3
app.py CHANGED
@@ -200,14 +200,40 @@ def create_docx_from_data(extracted_data):
200
  ordered_keys = [
201
  "Post Number", "Date of Post", "Media Type", "Number of Pictures",
202
  "Number of Videos", "Number of Audios", "Likes", "Comments", "Tagged Audience",
203
- "Full Caption", "Language", "Tone", "Hashtags", "Frames"
204
  ]
205
  for key in ordered_keys:
206
  value = data.get(key, "N/A")
207
  if key in ["Tone", "Hashtags"]:
208
  value = ", ".join(value) if isinstance(value, list) else value
209
- # For Frames, simply add the table text as is.
210
- doc.add_paragraph(f"**{key}:** {value}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
211
  doc.add_paragraph("\n")
212
  return doc
213
 
 
200
  ordered_keys = [
201
  "Post Number", "Date of Post", "Media Type", "Number of Pictures",
202
  "Number of Videos", "Number of Audios", "Likes", "Comments", "Tagged Audience",
203
+ "Full Caption", "Language", "Tone", "Hashtags"
204
  ]
205
  for key in ordered_keys:
206
  value = data.get(key, "N/A")
207
  if key in ["Tone", "Hashtags"]:
208
  value = ", ".join(value) if isinstance(value, list) else value
209
+ para = doc.add_paragraph()
210
+ run = para.add_run(f"**{key}:** {value}")
211
+ run.font.size = Pt(11)
212
+ # Instead of adding the Frames as plain text, add a proper table if FramesMapping is present.
213
+ if "FramesMapping" in data:
214
+ doc.add_paragraph("Frames:")
215
+ mapping = data["FramesMapping"]
216
+ # Create a table with header row and one row per frame
217
+ table = doc.add_table(rows=1, cols=5)
218
+ table.style = "Light List Accent 1"
219
+ hdr_cells = table.rows[0].cells
220
+ hdr_cells[0].text = "Frame"
221
+ hdr_cells[1].text = "Major Focus"
222
+ hdr_cells[2].text = "Significant Focus"
223
+ hdr_cells[3].text = "Minor Mention"
224
+ hdr_cells[4].text = "Not Applicable"
225
+ tick = "✓"
226
+ for frame, category in mapping.items():
227
+ row_cells = table.add_row().cells
228
+ row_cells[0].text = frame
229
+ row_cells[1].text = tick if category == "Major Focus" else ""
230
+ row_cells[2].text = tick if category == "Significant Focus" else ""
231
+ row_cells[3].text = tick if category == "Minor Mention" else ""
232
+ row_cells[4].text = tick if category == "Not Applicable" else ""
233
+ else:
234
+ # Fallback: if no FramesMapping, simply add the plain text value for "Frames"
235
+ value = data.get("Frames", "N/A")
236
+ doc.add_paragraph(f"**Frames:** {value}")
237
  doc.add_paragraph("\n")
238
  return doc
239