Spaces:
Runtime error
Runtime error
Commit
Β·
b6a0b2f
1
Parent(s):
1efb16b
Initial Qwen-VL demo
Browse files- app.py +18 -0
- requirements.txt +5 -0
app.py
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import AutoProcessor, AutoModelForVision2Seq
|
| 3 |
+
from PIL import Image
|
| 4 |
+
import torch
|
| 5 |
+
|
| 6 |
+
model_id = "Qwen/Qwen-VL"
|
| 7 |
+
processor = AutoProcessor.from_pretrained(model_id)
|
| 8 |
+
model = AutoModelForVision2Seq.from_pretrained(model_id, torch_dtype=torch.float16, device_map="auto")
|
| 9 |
+
|
| 10 |
+
def answer_question(image, question):
|
| 11 |
+
inputs = processor(images=image, text=question, return_tensors="pt").to("cuda")
|
| 12 |
+
generated_ids = model.generate(**inputs, max_new_tokens=50)
|
| 13 |
+
generated_text = processor.batch_decode(generated_ids, skip_special_tokens=True)[0]
|
| 14 |
+
return generated_text
|
| 15 |
+
|
| 16 |
+
iface = gr.Interface(fn=answer_question, inputs=["image", "text"], outputs="text", title="Qwen-VL Demo")
|
| 17 |
+
iface.launch()
|
| 18 |
+
|
requirements.txt
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
transformers
|
| 2 |
+
torch
|
| 3 |
+
gradio
|
| 4 |
+
accelerate
|
| 5 |
+
|