Update app.py
Browse files
app.py
CHANGED
@@ -207,11 +207,11 @@ def save_text_to_pdf(text, output_path):
|
|
207 |
doc.save(output_path)
|
208 |
print(f"Text saved to PDF at {output_path}.")
|
209 |
# Function to handle user queries
|
210 |
-
def handle_query(query, is_read_pdf, instructions):
|
211 |
print("Handling user query...")
|
212 |
max_chars_per_chunk = 1000 # Adjust this value as needed to control chunk size
|
213 |
-
if is_read_pdf:
|
214 |
-
pdf_text = read_pdf(
|
215 |
text_chunks = [pdf_text[i:i+max_chars_per_chunk] for i in range(0, len(pdf_text), max_chars_per_chunk)]
|
216 |
else:
|
217 |
search_results = google_search(query)
|
@@ -231,13 +231,14 @@ def handle_query(query, is_read_pdf, instructions):
|
|
231 |
def run_app():
|
232 |
with gr.Blocks() as demo:
|
233 |
gr.Markdown("# Web and PDF Summarizer")
|
234 |
-
query = gr.Textbox(label="Enter your query
|
|
|
235 |
is_read_pdf = gr.Checkbox(label="Read PDF", value=False)
|
236 |
instructions = gr.Textbox(label="Enter instructions", placeholder="Enter instructions here")
|
237 |
output = gr.Textbox(label="Summary")
|
238 |
clear_cache_btn = gr.Button("Clear Cache")
|
239 |
clear_cache_btn.click(fn=clear_cache, outputs=output)
|
240 |
generate_btn = gr.Button("Generate Summary")
|
241 |
-
generate_btn.click(fn=handle_query, inputs=[query, is_read_pdf, instructions], outputs=output)
|
242 |
demo.launch()
|
243 |
run_app()
|
|
|
207 |
doc.save(output_path)
|
208 |
print(f"Text saved to PDF at {output_path}.")
|
209 |
# Function to handle user queries
|
210 |
+
def handle_query(query, is_read_pdf, instructions, pdf_file=None):
|
211 |
print("Handling user query...")
|
212 |
max_chars_per_chunk = 1000 # Adjust this value as needed to control chunk size
|
213 |
+
if is_read_pdf and pdf_file:
|
214 |
+
pdf_text = read_pdf(pdf_file)
|
215 |
text_chunks = [pdf_text[i:i+max_chars_per_chunk] for i in range(0, len(pdf_text), max_chars_per_chunk)]
|
216 |
else:
|
217 |
search_results = google_search(query)
|
|
|
231 |
def run_app():
|
232 |
with gr.Blocks() as demo:
|
233 |
gr.Markdown("# Web and PDF Summarizer")
|
234 |
+
query = gr.Textbox(label="Enter your query", placeholder="Enter query here")
|
235 |
+
pdf_file = gr.File(label="Upload PDF", file_types=[".pdf"])
|
236 |
is_read_pdf = gr.Checkbox(label="Read PDF", value=False)
|
237 |
instructions = gr.Textbox(label="Enter instructions", placeholder="Enter instructions here")
|
238 |
output = gr.Textbox(label="Summary")
|
239 |
clear_cache_btn = gr.Button("Clear Cache")
|
240 |
clear_cache_btn.click(fn=clear_cache, outputs=output)
|
241 |
generate_btn = gr.Button("Generate Summary")
|
242 |
+
generate_btn.click(fn=handle_query, inputs=[query, is_read_pdf, instructions, pdf_file], outputs=output)
|
243 |
demo.launch()
|
244 |
run_app()
|