Ari commited on
Commit
f6ccaae
1 Parent(s): 1f99276

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -15
app.py CHANGED
@@ -77,24 +77,34 @@ def pdf_to_text(text, PDF, min_length=20):
77
 
78
  # Function to process the preloaded document
79
  def process_sample_document(min_length=20):
80
- # Replace this with the path to your preloaded legal document (PDF or DOCX)
81
- sample_document_path = "Marbury v. Madison.pdf" # Replace with your file's path
82
 
83
- # Use the same processing function to summarize the preloaded document
84
- return pdf_to_text("", sample_document_path, min_length)
 
85
 
86
  # Gradio interface
87
- iface = gr.Interface(
88
- fn=pdf_to_text,
89
- inputs=[gr.Textbox(label="Input Text"), gr.File(label="Upload PDF or DOCX"), gr.Slider(minimum=10, maximum=100, step=10, value=20, label="Summary Minimum Length")],
90
- outputs=[gr.Audio(label="Generated Audio"), gr.Textbox(label="Generated Summary"), gr.File(label="Summary PDF")],
91
- title="Legal Document Summarizer",
92
- description="Upload a legal document in PDF or DOCX format to generate a summary.",
93
- )
94
-
95
- # Add a button for the sample document
96
- iface.add_component(gr.Button("Process Sample Legal Document", elem_id="process_sample_document", interactive=True))
97
- iface.set_event_listener("process_sample_document", process_sample_document)
 
 
 
 
 
 
 
 
 
98
 
99
  if __name__ == "__main__":
100
  iface.launch()
 
77
 
78
  # Function to process the preloaded document
79
  def process_sample_document(min_length=20):
80
+ # Replace this with the path to your preloaded legal document (PDF)
81
+ sample_document_path = "Marbury v. Madison.pdf"
82
 
83
+ # Simulate file-like object for Gradio
84
+ with open(sample_document_path, "rb") as f:
85
+ return pdf_to_text("", f, min_length)
86
 
87
  # Gradio interface
88
+ with gr.Blocks() as iface:
89
+ # Create a button to process the sample document
90
+ with gr.Row():
91
+ process_sample_button = gr.Button("Process Sample Legal Document")
92
+
93
+ # Create the regular input interface
94
+ text_input = gr.Textbox(label="Input Text")
95
+ file_input = gr.File(label="Upload PDF or DOCX")
96
+ slider = gr.Slider(minimum=10, maximum=100, step=10, value=20, label="Summary Minimum Length")
97
+
98
+ # Outputs
99
+ audio_output = gr.Audio(label="Generated Audio")
100
+ summary_output = gr.Textbox(label="Generated Summary")
101
+ pdf_output = gr.File(label="Summary PDF")
102
+
103
+ # Define the action for the button click to process the preloaded document
104
+ process_sample_button.click(fn=process_sample_document, inputs=slider, outputs=[audio_output, summary_output, pdf_output])
105
+
106
+ # Define the action for the regular file processing
107
+ file_input.change(fn=pdf_to_text, inputs=[text_input, file_input, slider], outputs=[audio_output, summary_output, pdf_output])
108
 
109
  if __name__ == "__main__":
110
  iface.launch()