Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -9,11 +9,15 @@ model = VisionEncoderDecoderModel.from_pretrained("microsoft/trocr-large-handwri
|
|
9 |
|
10 |
@spaces.GPU
|
11 |
def recognize_text(image):
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
|
|
|
|
|
|
|
|
17 |
|
18 |
# Gradio UI
|
19 |
note = gr.Interface(
|
@@ -24,4 +28,4 @@ note = gr.Interface(
|
|
24 |
description="Upload an image of handwritten text, and the AI will convert it to digital text."
|
25 |
)
|
26 |
|
27 |
-
note.launch()
|
|
|
9 |
|
10 |
@spaces.GPU
|
11 |
def recognize_text(image):
|
12 |
+
try:
|
13 |
+
image = image.convert("RGB")
|
14 |
+
pixel_values = processor(images=image, return_tensors="pt").pixel_values
|
15 |
+
generated_ids = model.generate(pixel_values)
|
16 |
+
text = processor.batch_decode(generated_ids, skip_special_tokens=True)[0]
|
17 |
+
|
18 |
+
return text
|
19 |
+
except Exception as e:
|
20 |
+
return f"Error: {str(e)}"
|
21 |
|
22 |
# Gradio UI
|
23 |
note = gr.Interface(
|
|
|
28 |
description="Upload an image of handwritten text, and the AI will convert it to digital text."
|
29 |
)
|
30 |
|
31 |
+
note.launch()
|