Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,23 +1,27 @@
|
|
1 |
import gradio as gr
|
2 |
-
from
|
3 |
from PIL import Image
|
4 |
|
5 |
-
# Load
|
6 |
-
|
|
|
7 |
|
8 |
-
#
|
9 |
-
def
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
|
|
14 |
|
15 |
-
#
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
|
|
22 |
|
23 |
-
|
|
|
|
1 |
import gradio as gr
|
2 |
+
from transformers import TrOCRProcessor, VisionEncoderDecoderModel
|
3 |
from PIL import Image
|
4 |
|
5 |
+
# Load model and processor
|
6 |
+
processor = TrOCRProcessor.from_pretrained("Pisethan/sangapac_ocr")
|
7 |
+
model = VisionEncoderDecoderModel.from_pretrained("Pisethan/sangapac_ocr")
|
8 |
|
9 |
+
# Define the prediction function
|
10 |
+
def recognize_text(image):
|
11 |
+
image = Image.open(image).convert("RGB")
|
12 |
+
inputs = processor(images=image, return_tensors="pt").pixel_values
|
13 |
+
outputs = model.generate(inputs)
|
14 |
+
predicted_text = processor.tokenizer.decode(outputs[0], skip_special_tokens=True)
|
15 |
+
return predicted_text
|
16 |
|
17 |
+
# Gradio Interface
|
18 |
+
interface = gr.Interface(
|
19 |
+
fn=recognize_text,
|
20 |
+
inputs=gr.inputs.Image(type="file", label="Upload an Image"),
|
21 |
+
outputs=gr.outputs.Textbox(label="Recognized Text"),
|
22 |
+
title="OCR Model Demo",
|
23 |
+
description="Upload an image containing text to test the OCR model.",
|
24 |
+
)
|
25 |
|
26 |
+
# Launch the app
|
27 |
+
interface.launch()
|