Iqra Ali
Create app.py
2f61d8a
raw
history blame
1.31 kB
import gradio as gr
import torch
from PIL import Image
#from donut import DonutModel
def demo_process(input_img):
global pretrained_model, task_prompt, task_name
# input_img = Image.fromarray(input_img)
output = pretrained_model.inference(image=input_img, prompt=task_prompt)["predictions"][0]
return output
task_prompt = f"<s_cord-v2>"
image = Image.open("/content/SKMBT_75122072616550_Page_37_Image_0001.png")
image.save("cord_sample_receipt1.png")
image = Image.open("/content/SKMBT_75122072616550_Page_50_Image_0001.png")
image.save("cord_sample_receipt2.png")
#pretrained_model = DonutModel.from_pretrained("naver-clova-ix/donut-base-finetuned-cord-v2")
#pretrained_model.encoder.to(torch.bfloat16)
model = torch.load("/content/drive/MyDrive/fast_job/DONUT_model/donut/model.pt")
# Move model to GPU
device = "cuda" if torch.cuda.is_available() else "cpu"
model.to(device)
demo = gr.Interface(
fn=demo_process,
inputs= gr.inputs.Image(type="pil"),
outputs="json",
title=f"Donut 🍩 demonstration for `Medical Prescription Dataset` task",
description="""This model is trained with 200 medical prescription handwritten document images. <br>""",
examples=[["cord_sample_receipt1.png"], ["cord_sample_receipt2.png"]],
cache_examples=False,
)
demo.launch()