Spaces:
Paused
Paused
file path
Browse files
app.py
CHANGED
@@ -1,11 +1,10 @@
|
|
1 |
-
import
|
2 |
import gradio as gr
|
3 |
import numpy as np
|
4 |
-
from transformers import Qwen2VLForConditionalGeneration,
|
5 |
from qwen_vl_utils import process_vision_info
|
6 |
import torch
|
7 |
from ast import literal_eval
|
8 |
-
from PIL import Image
|
9 |
|
10 |
# Load the model on the available device(s)
|
11 |
model = Qwen2VLForConditionalGeneration.from_pretrained(
|
@@ -42,17 +41,14 @@ tax_deductions = '''Extract the following information in the given format:
|
|
42 |
}
|
43 |
'''
|
44 |
|
45 |
-
def demo(
|
46 |
-
# Convert image to bytes or suitable format if needed
|
47 |
-
image_name = image # If you're directly using the image
|
48 |
-
|
49 |
messages = [
|
50 |
{
|
51 |
"role": "user",
|
52 |
"content": [
|
53 |
{
|
54 |
"type": "image",
|
55 |
-
"image":
|
56 |
},
|
57 |
{"type": "text", "text": prompt},
|
58 |
],
|
@@ -91,9 +87,12 @@ def demo(image, prompt):
|
|
91 |
return json
|
92 |
|
93 |
def process_document(image):
|
94 |
-
#
|
95 |
-
|
96 |
-
|
|
|
|
|
|
|
97 |
json_op = {
|
98 |
"tax_deductions": one,
|
99 |
"other_benifits": two
|
|
|
1 |
+
import os
|
2 |
import gradio as gr
|
3 |
import numpy as np
|
4 |
+
from transformers import Qwen2VLForConditionalGeneration, AutoProcessor
|
5 |
from qwen_vl_utils import process_vision_info
|
6 |
import torch
|
7 |
from ast import literal_eval
|
|
|
8 |
|
9 |
# Load the model on the available device(s)
|
10 |
model = Qwen2VLForConditionalGeneration.from_pretrained(
|
|
|
41 |
}
|
42 |
'''
|
43 |
|
44 |
+
def demo(image_path, prompt):
|
|
|
|
|
|
|
45 |
messages = [
|
46 |
{
|
47 |
"role": "user",
|
48 |
"content": [
|
49 |
{
|
50 |
"type": "image",
|
51 |
+
"image": image_path, # Use the file path here
|
52 |
},
|
53 |
{"type": "text", "text": prompt},
|
54 |
],
|
|
|
87 |
return json
|
88 |
|
89 |
def process_document(image):
|
90 |
+
# Save the uploaded image temporarily and get its path
|
91 |
+
image_path = image.name # Gradio provides an interface to access the file name
|
92 |
+
|
93 |
+
# Process the image with your model
|
94 |
+
one = demo(image_path, other_benifits)
|
95 |
+
two = demo(image_path, tax_deductions)
|
96 |
json_op = {
|
97 |
"tax_deductions": one,
|
98 |
"other_benifits": two
|