Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -57,6 +57,11 @@ def process_image(input_image):
|
|
57 |
# Step 4: Crop the image using the bounding box
|
58 |
cropped_image = enhanced_image.crop((xmin, ymin, xmax, ymax))
|
59 |
|
|
|
|
|
|
|
|
|
|
|
60 |
# Select the corresponding OCR prompt based on the YOLO label
|
61 |
if label.lower() == "front":
|
62 |
doc_prompt = front
|
@@ -93,12 +98,14 @@ def process_image(input_image):
|
|
93 |
)
|
94 |
inputs = {k: v.to(device) for k, v in inputs.items()}
|
95 |
|
|
|
96 |
output = ocr_model.generate(
|
97 |
**inputs,
|
98 |
-
temperature=0.8,
|
99 |
-
max_new_tokens=50
|
100 |
num_return_sequences=1,
|
101 |
-
do_sample=
|
|
|
102 |
)
|
103 |
prompt_length = inputs["input_ids"].shape[1]
|
104 |
new_tokens = output[:, prompt_length:]
|
@@ -124,4 +131,5 @@ iface = gr.Interface(
|
|
124 |
),
|
125 |
)
|
126 |
|
127 |
-
|
|
|
|
57 |
# Step 4: Crop the image using the bounding box
|
58 |
cropped_image = enhanced_image.crop((xmin, ymin, xmax, ymax))
|
59 |
|
60 |
+
# OPTIMIZATION: Resize the image to reduce processing time
|
61 |
+
# Calculate aspect ratio to maintain proportions
|
62 |
+
max_size = (800, 800) # Reduced from original size
|
63 |
+
cropped_image.thumbnail(max_size, Image.LANCZOS)
|
64 |
+
|
65 |
# Select the corresponding OCR prompt based on the YOLO label
|
66 |
if label.lower() == "front":
|
67 |
doc_prompt = front
|
|
|
98 |
)
|
99 |
inputs = {k: v.to(device) for k, v in inputs.items()}
|
100 |
|
101 |
+
# OPTIMIZATION: Modified generation parameters for faster processing
|
102 |
output = ocr_model.generate(
|
103 |
**inputs,
|
104 |
+
temperature=0.2, # Reduced from 0.8 to 0.2 for faster, more deterministic output
|
105 |
+
max_new_tokens=40, # Slightly reduced from 50
|
106 |
num_return_sequences=1,
|
107 |
+
do_sample=False, # Changed to deterministic for speed
|
108 |
+
early_stopping=True # Add early stopping to prevent unnecessary generation
|
109 |
)
|
110 |
prompt_length = inputs["input_ids"].shape[1]
|
111 |
new_tokens = output[:, prompt_length:]
|
|
|
131 |
),
|
132 |
)
|
133 |
|
134 |
+
# Enable queue for better handling of processing time
|
135 |
+
iface.launch(share=True)
|