Commit
·
ee363c7
1
Parent(s):
53edb88
Updated with OCR model and Gradio integration
Browse files
app.py
CHANGED
@@ -1,20 +1,24 @@
|
|
1 |
import gradio as gr
|
2 |
-
from transformers import
|
3 |
|
4 |
-
# Load
|
5 |
-
|
|
|
|
|
6 |
|
7 |
-
def
|
8 |
-
|
9 |
-
|
|
|
|
|
|
|
10 |
|
11 |
-
# Gradio interface
|
12 |
demo = gr.Interface(
|
13 |
-
fn=
|
14 |
-
inputs=gr.Image(type="pil"),
|
15 |
-
outputs="text",
|
16 |
-
title="
|
17 |
-
description="Upload an image of an invoice to extract text."
|
18 |
)
|
19 |
|
20 |
if __name__ == "__main__":
|
|
|
1 |
import gradio as gr
|
2 |
+
from transformers import AutoTokenizer, AutoModelForVision2Seq
|
3 |
|
4 |
+
# Load the tokenizer and model
|
5 |
+
model_name = "OpenGVLab/InternVL2-1B"
|
6 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
7 |
+
model = AutoModelForVision2Seq.from_pretrained(model_name)
|
8 |
|
9 |
+
def analyze_image_text(image, text):
|
10 |
+
# Tokenize the input
|
11 |
+
inputs = tokenizer(text, return_tensors="pt")
|
12 |
+
# Use the model to get outputs
|
13 |
+
outputs = model.generate(**inputs)
|
14 |
+
return tokenizer.decode(outputs[0])
|
15 |
|
16 |
+
# Gradio interface
|
17 |
demo = gr.Interface(
|
18 |
+
fn=analyze_image_text,
|
19 |
+
inputs=[gr.Image(type="pil"), gr.Textbox()],
|
20 |
+
outputs="text",
|
21 |
+
title="InternVL2-1B Image-Text Model"
|
|
|
22 |
)
|
23 |
|
24 |
if __name__ == "__main__":
|