Update app.py
Browse files
app.py
CHANGED
@@ -1,15 +1,25 @@
|
|
1 |
import gradio as gr
|
2 |
-
import
|
|
|
|
|
3 |
|
|
|
|
|
|
|
4 |
|
5 |
-
#
|
|
|
6 |
|
7 |
-
def
|
8 |
-
|
9 |
-
|
|
|
|
|
|
|
|
|
10 |
|
11 |
iface = gr.Interface(
|
12 |
-
fn=
|
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")
|