Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -71,4 +71,30 @@ def ocr_and_extract(image, text_query):
|
|
| 71 |
# Generate the output with Qwen2-VL
|
| 72 |
generated_ids = qwen_model.generate(**inputs, max_new_tokens=50)
|
| 73 |
output_text = processor.batch_decode(
|
| 74 |
-
generated_ids, skip_special_tokens=True,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
# Generate the output with Qwen2-VL
|
| 72 |
generated_ids = qwen_model.generate(**inputs, max_new_tokens=50)
|
| 73 |
output_text = processor.batch_decode(
|
| 74 |
+
generated_ids, skip_special_tokens=True, clean_up_tokenization_spaces=False
|
| 75 |
+
)
|
| 76 |
+
|
| 77 |
+
# Clean up the temporary file
|
| 78 |
+
os.remove(temp_image_path)
|
| 79 |
+
|
| 80 |
+
return output_text[0]
|
| 81 |
+
|
| 82 |
+
except Exception as e:
|
| 83 |
+
error_message = str(e)
|
| 84 |
+
traceback.print_exc()
|
| 85 |
+
return f"Error: {error_message}"
|
| 86 |
+
|
| 87 |
+
# Gradio interface for image input
|
| 88 |
+
iface = gr.Interface(
|
| 89 |
+
fn=ocr_and_extract,
|
| 90 |
+
inputs=[
|
| 91 |
+
gr.Image(type="pil"),
|
| 92 |
+
gr.Textbox(label="Enter your query (optional)"),
|
| 93 |
+
],
|
| 94 |
+
outputs="text",
|
| 95 |
+
title="Image OCR with Byaldi + Qwen2-VL",
|
| 96 |
+
description="Upload an image (JPEG/PNG) containing Hindi and English text for OCR.",
|
| 97 |
+
)
|
| 98 |
+
|
| 99 |
+
# Launch the Gradio app
|
| 100 |
+
iface.launch()
|