new_app / app.py
Nechama's picture
Update app.py
9c3e1a4 verified
import gradio as gr
from PIL import Image
from transformers import pipeline, AutoModelForVision2Seq, AutoProcessor
import torch
# Load the OpenGVLab/InternVL-Chat-V1-5 model and processor
from transformers import AutoModel
model = AutoModel.from_pretrained("OpenGVLab/InternVL-Chat-V1-5", trust_remote_code=True)
# Load the Llama3 model for text processing
#llama_model = pipeline("text2text-generation", model="llama3")
def process_image(image):
# Process the image to extract the recipe using OpenGVLab
inputs = processor(images=image, return_tensors="pt")
generated_ids = model.generate(**inputs)
extracted_text = processor.batch_decode(generated_ids, skip_special_tokens=True)[0]
return extracted_text
iface = gr.Interface(
fn=process_image,
inputs=[
gr.components.Image(type="filepath", label="Recipe Image"),
gr.components.Radio(choices=["Double","Triple", "Half", "Third"], label="Action")
],
outputs="text",
title="Recipe Modifier",
description="Upload an image of a recipe and choose how to modify the measurements.",
)
if __name__ == "__main__":
iface.launch()