pranshh commited on
Commit
9936c85
1 Parent(s): 89c493b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -1
app.py CHANGED
@@ -22,6 +22,7 @@ def load_model():
22
  return Qwen2VLForConditionalGeneration.from_pretrained(
23
  "Qwen/Qwen2-VL-2B-Instruct",
24
  torch_dtype=torch.float32, # Use float32 for CPU
 
25
  )
26
 
27
  # Load the model
@@ -76,6 +77,9 @@ def ocr_image(image, query="Extract text from the image", keyword=""):
76
 
77
  # Gradio interface
78
  def process_image(image, keyword=""):
 
 
 
79
  return ocr_image(image, keyword=keyword)
80
 
81
  # Update the Gradio interface:
@@ -90,4 +94,4 @@ interface = gr.Interface(
90
  )
91
 
92
  # Launch Gradio interface in Colab
93
- interface.launch()
 
22
  return Qwen2VLForConditionalGeneration.from_pretrained(
23
  "Qwen/Qwen2-VL-2B-Instruct",
24
  torch_dtype=torch.float32, # Use float32 for CPU
25
+ low_cpu_mem_usage=True
26
  )
27
 
28
  # Load the model
 
77
 
78
  # Gradio interface
79
  def process_image(image, keyword=""):
80
+ max_size = 1024
81
+ if max(image.size) > max_size:
82
+ image.thumbnail((max_size, max_size))
83
  return ocr_image(image, keyword=keyword)
84
 
85
  # Update the Gradio interface:
 
94
  )
95
 
96
  # Launch Gradio interface in Colab
97
+ interface.launch(server_timeout=300)