Spaces:
Paused
Paused
one more
Browse files
app.py
CHANGED
|
@@ -1,10 +1,12 @@
|
|
| 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(
|
|
@@ -37,7 +39,7 @@ tax_deductions = '''Extract the following information in the given format:
|
|
| 37 |
'ee medicare tax:': {'Amount':'', 'Year-To_Date':""}},
|
| 38 |
'california:': {
|
| 39 |
'withholding tax:': {'Amount':'', 'Year-To_Date':""},
|
| 40 |
-
'ee disability tax:': {'Amount':'', 'Year-
|
| 41 |
}
|
| 42 |
'''
|
| 43 |
|
|
@@ -87,8 +89,11 @@ def demo(image_path, prompt):
|
|
| 87 |
return json
|
| 88 |
|
| 89 |
def process_document(image):
|
| 90 |
-
# Save the uploaded image
|
| 91 |
-
|
|
|
|
|
|
|
|
|
|
| 92 |
|
| 93 |
# Process the image with your model
|
| 94 |
one = demo(image_path, other_benifits)
|
|
@@ -97,6 +102,10 @@ def process_document(image):
|
|
| 97 |
"tax_deductions": one,
|
| 98 |
"other_benifits": two
|
| 99 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 100 |
return json_op
|
| 101 |
|
| 102 |
# Create Gradio interface
|
|
|
|
| 1 |
import os
|
| 2 |
+
import tempfile
|
| 3 |
import gradio as gr
|
| 4 |
import numpy as np
|
| 5 |
from transformers import Qwen2VLForConditionalGeneration, AutoProcessor
|
| 6 |
from qwen_vl_utils import process_vision_info
|
| 7 |
import torch
|
| 8 |
from ast import literal_eval
|
| 9 |
+
from PIL import Image
|
| 10 |
|
| 11 |
# Load the model on the available device(s)
|
| 12 |
model = Qwen2VLForConditionalGeneration.from_pretrained(
|
|
|
|
| 39 |
'ee medicare tax:': {'Amount':'', 'Year-To_Date':""}},
|
| 40 |
'california:': {
|
| 41 |
'withholding tax:': {'Amount':'', 'Year-To_Date':""},
|
| 42 |
+
'ee disability tax:': {'Amount':'', 'Year-To-Date':""}}},
|
| 43 |
}
|
| 44 |
'''
|
| 45 |
|
|
|
|
| 89 |
return json
|
| 90 |
|
| 91 |
def process_document(image):
|
| 92 |
+
# Save the uploaded image to a temporary file
|
| 93 |
+
with tempfile.NamedTemporaryFile(delete=False, suffix=".jpg") as tmp_file:
|
| 94 |
+
image = Image.fromarray(image) # Convert NumPy array to PIL Image
|
| 95 |
+
image.save(tmp_file.name) # Save the image to the temporary file
|
| 96 |
+
image_path = tmp_file.name # Get the path of the saved file
|
| 97 |
|
| 98 |
# Process the image with your model
|
| 99 |
one = demo(image_path, other_benifits)
|
|
|
|
| 102 |
"tax_deductions": one,
|
| 103 |
"other_benifits": two
|
| 104 |
}
|
| 105 |
+
|
| 106 |
+
# Optionally, you can delete the temporary file after use
|
| 107 |
+
os.remove(image_path)
|
| 108 |
+
|
| 109 |
return json_op
|
| 110 |
|
| 111 |
# Create Gradio interface
|