Nechama commited on
Commit
9c3e1a4
1 Parent(s): 730412f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -6
app.py CHANGED
@@ -1,15 +1,25 @@
1
  import gradio as gr
2
- import pytesseract
 
 
3
 
 
 
 
4
 
5
- #pytesseract.pytesseract.tesseract_cmd = r'/usr/bin/tesseract'
 
6
 
7
- def process_recipe(i,j):
8
- text = pytesseract.image_to_string(Image.open(image))
9
- return text
 
 
 
 
10
 
11
  iface = gr.Interface(
12
- fn=process_recipe,
13
  inputs=[
14
  gr.components.Image(type="filepath", label="Recipe Image"),
15
  gr.components.Radio(choices=["Double","Triple", "Half", "Third"], label="Action")
 
1
  import gradio as gr
2
+ from PIL import Image
3
+ from transformers import pipeline, AutoModelForVision2Seq, AutoProcessor
4
+ import torch
5
 
6
+ # Load the OpenGVLab/InternVL-Chat-V1-5 model and processor
7
+ from transformers import AutoModel
8
+ model = AutoModel.from_pretrained("OpenGVLab/InternVL-Chat-V1-5", trust_remote_code=True)
9
 
10
+ # Load the Llama3 model for text processing
11
+ #llama_model = pipeline("text2text-generation", model="llama3")
12
 
13
+ def process_image(image):
14
+ # Process the image to extract the recipe using OpenGVLab
15
+ inputs = processor(images=image, return_tensors="pt")
16
+ generated_ids = model.generate(**inputs)
17
+ extracted_text = processor.batch_decode(generated_ids, skip_special_tokens=True)[0]
18
+
19
+ return extracted_text
20
 
21
  iface = gr.Interface(
22
+ fn=process_image,
23
  inputs=[
24
  gr.components.Image(type="filepath", label="Recipe Image"),
25
  gr.components.Radio(choices=["Double","Triple", "Half", "Third"], label="Action")