Spaces:
Sleeping
Sleeping
doshan1250
commited on
Commit
•
1c49de7
1
Parent(s):
9eee83a
init push
Browse files
app.py
ADDED
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import torch
|
3 |
+
from PIL import Image
|
4 |
+
|
5 |
+
from donut import DonutModel
|
6 |
+
|
7 |
+
def demo_process(input_img):
|
8 |
+
global pretrained_model, task_prompt, task_name
|
9 |
+
# input_img = Image.fromarray(input_img)
|
10 |
+
output = pretrained_model.inference(image=input_img, prompt=task_prompt)["predictions"][0]
|
11 |
+
return output
|
12 |
+
task_name = "preparedFinetuneData_Bird"
|
13 |
+
# task_name = "cord-v2"
|
14 |
+
task_prompt = f"<s_{task_name}>"
|
15 |
+
|
16 |
+
image = Image.open("inv87.jpg")
|
17 |
+
image.save("inv87.jpg")
|
18 |
+
image = Image.open("inv17.jpg")
|
19 |
+
image.save("inv17.jpg")
|
20 |
+
|
21 |
+
PATH = 'epochs30_base_on_donut_base/'
|
22 |
+
pretrained_model = DonutModel.from_pretrained("doshan1250/p9OcrAiV2Bird")
|
23 |
+
pretrained_model.eval()
|
24 |
+
|
25 |
+
demo = gr.Interface(
|
26 |
+
fn=demo_process,
|
27 |
+
inputs= gr.Image(type="pil"),
|
28 |
+
outputs="json",
|
29 |
+
title=f"Goodarc p9 for `{task_name}` task, epochs30",
|
30 |
+
description="""Goodarc p9 v2 訓練.
|
31 |
+
""",
|
32 |
+
examples=[["inv87.jpg"], ["inv17.jpg"]],
|
33 |
+
cache_examples=False,
|
34 |
+
)
|
35 |
+
|
36 |
+
demo.launch()
|
inv17.jpg
ADDED
inv87.jpg
ADDED
requirements.txt
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
torch
|
2 |
+
donut-python
|
3 |
+
gradio
|
4 |
+
transformers==4.25.1
|
5 |
+
timm==0.5.4
|
6 |
+
pytorch-lightning==1.6.4
|