Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -7,12 +7,22 @@ from PIL import Image
|
|
| 7 |
from transformers import AutoProcessor, AutoModelForTokenClassification
|
| 8 |
|
| 9 |
#function to load gemini pro vision model and get response
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
|
| 17 |
#function to provide image
|
| 18 |
def input_image_setup(uploaded_file):
|
|
|
|
| 7 |
from transformers import AutoProcessor, AutoModelForTokenClassification
|
| 8 |
|
| 9 |
#function to load gemini pro vision model and get response
|
| 10 |
+
from transformers import AutoTokenizer, AutoModelForTokenClassification
|
| 11 |
+
|
| 12 |
+
def get_model_response(input_text, image, prompt):
|
| 13 |
+
# Load the pre-trained model and tokenizer
|
| 14 |
+
model_name = "monuirctc/invoice-extraction"
|
| 15 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 16 |
+
model = AutoModelForTokenClassification.from_pretrained(model_name)
|
| 17 |
+
|
| 18 |
+
# Tokenize inputs
|
| 19 |
+
inputs = tokenizer(input_text, image, prompt, return_tensors="pt", max_length=512, truncation=True)
|
| 20 |
+
|
| 21 |
+
# Generate response from the model
|
| 22 |
+
outputs = model(**inputs)
|
| 23 |
+
response = tokenizer.decode(outputs.logits.argmax(dim=-1))
|
| 24 |
+
|
| 25 |
+
return response
|
| 26 |
|
| 27 |
#function to provide image
|
| 28 |
def input_image_setup(uploaded_file):
|