anky2002 commited on
Commit
61f3df8
Β·
verified Β·
1 Parent(s): 894d051

Upload app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +67 -2
app.py CHANGED
@@ -617,9 +617,31 @@ def build_app():
617
  with gr.Tab("βš–οΈ Court Brief"):
618
  court_md = gr.Markdown(label="Court Brief (FRE 702)")
619
 
620
- # Wire up the analysis
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
621
  analyze_btn.click(
622
- fn=analyze_image,
623
  inputs=[image_input],
624
  outputs=[
625
  verdict_html,
@@ -635,9 +657,52 @@ def build_app():
635
  benford_plot,
636
  metadata_table,
637
  agent_details_md,
 
 
 
638
  ],
639
  )
640
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
641
  # Footer
642
  gr.HTML("""
643
  <div style="text-align:center; padding:20px; color:#aaa; font-size:0.8em; border-top:1px solid #eee; margin-top:20px;">
 
617
  with gr.Tab("βš–οΈ Court Brief"):
618
  court_md = gr.Markdown(label="Court Brief (FRE 702)")
619
 
620
+ with gr.Tab("πŸ“₯ Export"):
621
+ gr.Markdown("""### Export Forensic Report
622
+ Export the complete analysis in your preferred format. Reports are professionally formatted using **Qwen2.5-72B-Instruct** when available.
623
+ """)
624
+ with gr.Row():
625
+ export_pdf_btn = gr.Button("πŸ“„ Export PDF", variant="primary")
626
+ export_docx_btn = gr.Button("πŸ“ Export DOCX", variant="primary")
627
+ export_txt_btn = gr.Button("πŸ“ƒ Export TXT", variant="secondary")
628
+ export_md_btn = gr.Button("πŸ“‹ Export Markdown", variant="secondary")
629
+ export_file = gr.File(label="Download Report", visible=True)
630
+ export_status = gr.Markdown("")
631
+
632
+ # ── Hidden state to store report data for exports ────────────
633
+ report_state = gr.State("")
634
+ court_state = gr.State("")
635
+ tree_state = gr.State("")
636
+
637
+ # Wire up the analysis β€” also store report data in state
638
+ def analyze_and_store(img):
639
+ results = analyze_image(img)
640
+ # results[4] = report_md, results[5] = tree_md, results[6] = court_md
641
+ return list(results) + [results[4], results[6], results[5]]
642
+
643
  analyze_btn.click(
644
+ fn=analyze_and_store,
645
  inputs=[image_input],
646
  outputs=[
647
  verdict_html,
 
657
  benford_plot,
658
  metadata_table,
659
  agent_details_md,
660
+ report_state,
661
+ court_state,
662
+ tree_state,
663
  ],
664
  )
665
 
666
+ # ── Export handlers ───────────────────────────────────────────
667
+ from export import export_pdf, export_docx, export_txt, export_md
668
+
669
+ def do_export_pdf(report, court, tree):
670
+ if not report: return None, "⚠️ Run analysis first"
671
+ try:
672
+ path = export_pdf(report, court, tree)
673
+ return path, "βœ… PDF exported successfully"
674
+ except Exception as e:
675
+ return None, f"❌ Export failed: {e}"
676
+
677
+ def do_export_docx(report, court, tree):
678
+ if not report: return None, "⚠️ Run analysis first"
679
+ try:
680
+ path = export_docx(report, court, tree)
681
+ return path, "βœ… DOCX exported successfully"
682
+ except Exception as e:
683
+ return None, f"❌ Export failed: {e}"
684
+
685
+ def do_export_txt(report, court, tree):
686
+ if not report: return None, "⚠️ Run analysis first"
687
+ try:
688
+ path = export_txt(report, court, tree)
689
+ return path, "βœ… TXT exported successfully"
690
+ except Exception as e:
691
+ return None, f"❌ Export failed: {e}"
692
+
693
+ def do_export_md(report, court, tree):
694
+ if not report: return None, "⚠️ Run analysis first"
695
+ try:
696
+ path = export_md(report, court, tree)
697
+ return path, "βœ… Markdown exported successfully"
698
+ except Exception as e:
699
+ return None, f"❌ Export failed: {e}"
700
+
701
+ export_pdf_btn.click(fn=do_export_pdf, inputs=[report_state, court_state, tree_state], outputs=[export_file, export_status])
702
+ export_docx_btn.click(fn=do_export_docx, inputs=[report_state, court_state, tree_state], outputs=[export_file, export_status])
703
+ export_txt_btn.click(fn=do_export_txt, inputs=[report_state, court_state, tree_state], outputs=[export_file, export_status])
704
+ export_md_btn.click(fn=do_export_md, inputs=[report_state, court_state, tree_state], outputs=[export_file, export_status])
705
+
706
  # Footer
707
  gr.HTML("""
708
  <div style="text-align:center; padding:20px; color:#aaa; font-size:0.8em; border-top:1px solid #eee; margin-top:20px;">