Spaces:
Runtime error
Runtime error
import gradio as gr | |
from PIL import Image | |
from transformers import TrOCRProcessor, VisionEncoderDecoderModel | |
# Load the model and processor | |
processor = TrOCRProcessor.from_pretrained("kkatiz/thai-trocr-thaigov-v2") | |
model = VisionEncoderDecoderModel.from_pretrained("kkatiz/thai-trocr-thaigov-v2") | |
# Define the prediction function | |
def predict(image): | |
image = image.convert("RGB") | |
pixel_values = processor(image, return_tensors="pt").pixel_values | |
generated_ids = model.generate(pixel_values) | |
generated_text = processor.batch_decode(generated_ids, skip_special_tokens=True)[0] | |
return generated_text | |
# Define the Gradio interface | |
iface = gr.Interface( | |
fn=predict, | |
inputs=gr.Image(type="pil"), | |
outputs="text", | |
title="Thai Image-to-Text Prediction", | |
description="Upload an image, and the model will predict the text in the image.", | |
) | |
# Launch the app | |
if __name__ == "__main__": | |
iface.launch() |