gauri-sharan commited on
Commit
db3dd58
·
verified ·
1 Parent(s): 4791a38

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -7
app.py CHANGED
@@ -22,12 +22,9 @@ qwen_model = Qwen2VLForConditionalGeneration.from_pretrained(
22
  # Processor for Qwen2-VL
23
  processor = AutoProcessor.from_pretrained("Qwen/Qwen2-VL-7B-Instruct", trust_remote_code=True)
24
 
25
- # Global variable to store extracted text
26
- extracted_text = ""
27
-
28
  @spaces.GPU(duration=120) # Increased GPU duration to 120 seconds
29
  def ocr_and_extract(image):
30
- global extracted_text
31
  try:
32
  # Save the uploaded image temporarily
33
  temp_image_path = "temp_image.jpg"
@@ -88,7 +85,7 @@ def ocr_and_extract(image):
88
  traceback.print_exc()
89
  return f"Error: {error_message}"
90
 
91
- def search_keywords(keywords):
92
  if not extracted_text:
93
  return "No text extracted yet. Please upload an image."
94
 
@@ -105,7 +102,7 @@ with gr.Blocks() as iface:
105
  # Image upload and text extraction section
106
  with gr.Column():
107
  img_input = gr.Image(type="pil", label="Upload an Image")
108
- extracted_output = gr.HTML(label="Extracted Text") # Removed 'interactive' argument
109
 
110
  # Functionality to trigger the OCR and extraction
111
  img_button = gr.Button("Extract Text")
@@ -118,6 +115,6 @@ with gr.Blocks() as iface:
118
 
119
  # Functionality to search within the extracted text
120
  search_button = gr.Button("Search")
121
- search_button.click(fn=search_keywords, inputs=search_input, outputs=search_output)
122
 
123
  iface.launch()
 
22
  # Processor for Qwen2-VL
23
  processor = AutoProcessor.from_pretrained("Qwen/Qwen2-VL-7B-Instruct", trust_remote_code=True)
24
 
25
+ # Function for OCR and text extraction
 
 
26
  @spaces.GPU(duration=120) # Increased GPU duration to 120 seconds
27
  def ocr_and_extract(image):
 
28
  try:
29
  # Save the uploaded image temporarily
30
  temp_image_path = "temp_image.jpg"
 
85
  traceback.print_exc()
86
  return f"Error: {error_message}"
87
 
88
+ def search_keywords(extracted_text, keywords):
89
  if not extracted_text:
90
  return "No text extracted yet. Please upload an image."
91
 
 
102
  # Image upload and text extraction section
103
  with gr.Column():
104
  img_input = gr.Image(type="pil", label="Upload an Image")
105
+ extracted_output = gr.Textbox(label="Extracted Text", interactive=False) # Use Textbox to store text
106
 
107
  # Functionality to trigger the OCR and extraction
108
  img_button = gr.Button("Extract Text")
 
115
 
116
  # Functionality to search within the extracted text
117
  search_button = gr.Button("Search")
118
+ search_button.click(fn=search_keywords, inputs=[extracted_output, search_input], outputs=search_output)
119
 
120
  iface.launch()