Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
|
3 |
+
from transformers import pipeline
|
4 |
+
from PIL import Image
|
5 |
+
|
6 |
+
model = "pacman2223/test-mod"
|
7 |
+
|
8 |
+
image = Image.open("./sample_cv.png")
|
9 |
+
image.save("cv.png")
|
10 |
+
image = Image.open("./sample_hack.png")
|
11 |
+
image.save("hack.png")
|
12 |
+
|
13 |
+
def demo_process(img, question):
|
14 |
+
|
15 |
+
qa_pipeline = pipeline("document-question-answering", model=model)
|
16 |
+
qa_pipeline(img, question)
|
17 |
+
|
18 |
+
return qa_pipeline["answer"]
|
19 |
+
|
20 |
+
|
21 |
+
demo = gr.Interface(
|
22 |
+
fn=demo_process,
|
23 |
+
inputs=["image", "text"],
|
24 |
+
outputs="json",
|
25 |
+
title=f"BIP demonstration for `layoutlmv2` task",
|
26 |
+
description="""This model is trained with 1200 receipt images of Docqva dataset. <br>""",
|
27 |
+
examples=[["cv.png"], ["hack.png"]],
|
28 |
+
cache_examples=False,
|
29 |
+
)
|
30 |
+
|
31 |
+
demo.launch()
|