Spaces:
Build error
Build error
File size: 1,082 Bytes
41b1911 25b37ff fa725d5 25b37ff fa725d5 f204998 fa725d5 a3c69ef fa725d5 4ab173c fa725d5 f204998 fa725d5 f204998 25b37ff fa725d5 f204998 fa725d5 f204998 41b1911 fa725d5 f204998 fa725d5 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
import gradio as gr
import torch
from PIL import Image
from transformers import AutoModel, AutoTokenizer
# Load the model and tokenizer from the local path
model = AutoModel.from_pretrained('minicpm/models', trust_remote_code=True)
tokenizer = AutoTokenizer.from_pretrained('minicpm/models', trust_remote_code=True)
# Set the model to evaluation mode
model.eval()
def predict(image, question):
# Preprocess the image
image = image.convert('RGB')
# Create the message list
msgs = [{'role': 'user', 'content': question}]
# Generate a response
res = model.chat(
image=image,
msgs=msgs,
tokenizer=tokenizer,
sampling=True,
temperature=0.1
)
return res
# Create the Gradio interface
iface = gr.Interface(
fn=predict,
inputs=[
gr.inputs.Image(type="pil", label="Upload an Image"),
gr.inputs.Textbox(label="Ask a Question")
],
outputs="text",
title="Image Question Answering",
description="Upload an image and ask a question about it."
)
# Launch the app
iface.launch()
|