Spaces:
Runtime error
Runtime error
requirements.txt
Browse filestransformers
torch
gradio
accelerate
pillow
app.py
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import AutoProcessor, AutoModelForVision2Seq
|
| 3 |
+
from PIL import Image
|
| 4 |
+
|
| 5 |
+
# Load model and processor
|
| 6 |
+
processor = AutoProcessor.from_pretrained("Qwen/Qwen2.5-VL-7B-Instruct")
|
| 7 |
+
model = AutoModelForVision2Seq.from_pretrained("Qwen/Qwen2.5-VL-7B-Instruct", device_map="auto")
|
| 8 |
+
|
| 9 |
+
# Prompt specifically designed for CD spines
|
| 10 |
+
prompt = "What is the album title and artist on this CD spine?"
|
| 11 |
+
|
| 12 |
+
# Inference function
|
| 13 |
+
def extract_text(image: Image.Image):
|
| 14 |
+
inputs = processor(prompt=prompt, images=image, return_tensors="pt").to(model.device)
|
| 15 |
+
generated_ids = model.generate(**inputs, max_new_tokens=128)
|
| 16 |
+
generated_text = processor.batch_decode(generated_ids, skip_special_tokens=True)[0]
|
| 17 |
+
return {"text": generated_text}
|
| 18 |
+
|
| 19 |
+
# Gradio interface
|
| 20 |
+
iface = gr.Interface(
|
| 21 |
+
fn=extract_text,
|
| 22 |
+
inputs="image",
|
| 23 |
+
outputs="json",
|
| 24 |
+
title="Qwen2.5-VL: CD Spine Reader",
|
| 25 |
+
description="Upload an image of a CD spine to get the album title and artist using Qwen2.5-VL-7B-Instruct."
|
| 26 |
+
)
|
| 27 |
+
|
| 28 |
+
iface.launch()
|