Andrei Shadrikov commited on
Commit
23c0f1b
·
1 Parent(s): 1482457
Files changed (1) hide show
  1. app.py +8 -7
app.py CHANGED
@@ -67,10 +67,11 @@ def process_pdf(pdf_file, cur_files):
67
 
68
  # Function to process image and text query
69
  def process_image_and_text(doc, text_query):
70
- images = convert_from_path(doc)
71
- outputs = []
72
- for img in images:
73
- outputs += p(img, question)
 
74
  return sorted(outputs, key=lambda x: x["score"], reverse=True)[0]['answer']
75
 
76
  text_interface = gr.Interface(
@@ -92,11 +93,11 @@ pdf_interface = gr.Interface(
92
  image_interface = gr.Interface(
93
  fn=process_image_and_text,
94
  inputs=[
95
- gr.Image(label="Upload Image"),
96
  gr.Textbox(label="Text Query")
97
  ],
98
- outputs="text",
99
- title="Image Text Search",
100
  description="Searches for text in the uploaded image based on the provided query."
101
  )
102
 
 
67
 
68
  # Function to process image and text query
69
  def process_image_and_text(doc, text_query):
70
+ with tempfile.TemporaryDirectory() as path:
71
+ images = convert_from_path(doc, output_folder=path)
72
+ outputs = []
73
+ for img in images:
74
+ outputs += p(img, question)
75
  return sorted(outputs, key=lambda x: x["score"], reverse=True)[0]['answer']
76
 
77
  text_interface = gr.Interface(
 
93
  image_interface = gr.Interface(
94
  fn=process_image_and_text,
95
  inputs=[
96
+ gr.PDF(label="Upload PDF"),
97
  gr.Textbox(label="Text Query")
98
  ],
99
+ outputs=gr.Textbox(label="Possible Answers"),
100
+ title="Ask Your PDF",
101
  description="Searches for text in the uploaded image based on the provided query."
102
  )
103