pratikshahp commited on
Commit
db7493a
·
verified ·
1 Parent(s): 95a0fec

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -6
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
- def get_model_response(input,image,prompt): #input: how LLM model behave like, #image: To extract info, prompt: ask something
11
- #load a model
12
- processor = AutoProcessor.from_pretrained("monuirctc/invoice-extraction")
13
- model = AutoModelForTokenClassification.from_pretrained("monuirctc/invoice-extraction")
14
- response=model.generate_content([input,image[0],prompt]) #get response from model
15
- return response.text
 
 
 
 
 
 
 
 
 
 
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):