Spaces:
Runtime error
Runtime error
import gradio as gr | |
from transformers import AutoProcessor, AutoModelForVision2Seq | |
from PIL import Image | |
import torch | |
model_id = "Qwen/Qwen-VL" | |
processor = AutoProcessor.from_pretrained(model_id, trust_remote_code=True) | |
model = AutoModelForVision2Seq.from_pretrained(model_id, torch_dtype=torch.float16, device_map="auto", trust_remote_code=True) | |
def answer_question(image, question): | |
inputs = processor(images=image, text=question, return_tensors="pt").to("cuda") | |
generated_ids = model.generate(**inputs, max_new_tokens=50) | |
generated_text = processor.batch_decode(generated_ids, skip_special_tokens=True)[0] | |
return generated_text | |
iface = gr.Interface(fn=answer_question, inputs=["image", "text"], outputs="text", title="Qwen-VL Demo") | |
iface.launch() | |