Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -7,8 +7,8 @@ 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(
|
11 |
-
image = Image.open(
|
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)
|
@@ -17,7 +17,7 @@ def recognize_text(image):
|
|
17 |
# Gradio Interface
|
18 |
interface = gr.Interface(
|
19 |
fn=recognize_text,
|
20 |
-
inputs=gr.Image(type="
|
21 |
outputs=gr.Textbox(label="Recognized Text"),
|
22 |
title="OCR Model Demo",
|
23 |
description="Upload an image containing text to test the OCR model.",
|
|
|
7 |
model = VisionEncoderDecoderModel.from_pretrained("Pisethan/sangapac_ocr")
|
8 |
|
9 |
# Define the prediction function
|
10 |
+
def recognize_text(image_path):
|
11 |
+
image = Image.open(image_path).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)
|
|
|
17 |
# Gradio Interface
|
18 |
interface = gr.Interface(
|
19 |
fn=recognize_text,
|
20 |
+
inputs=gr.Image(type="filepath", label="Upload an Image"),
|
21 |
outputs=gr.Textbox(label="Recognized Text"),
|
22 |
title="OCR Model Demo",
|
23 |
description="Upload an image containing text to test the OCR model.",
|