|
import gradio as gr |
|
from PIL import Image |
|
from transformers import pipeline, AutoModelForVision2Seq, AutoProcessor |
|
import torch |
|
|
|
|
|
from transformers import AutoModel |
|
model = AutoModel.from_pretrained("OpenGVLab/InternVL-Chat-V1-5", trust_remote_code=True) |
|
|
|
|
|
|
|
|
|
def process_image(image): |
|
|
|
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() |
|
|