Spaces:
Runtime error
Runtime error
Commit
·
28c3712
1
Parent(s):
18517c6
new file: app.py
Browse filesnew file: requirements.txt
- app.py +28 -0
- requirements.txt +4 -0
app.py
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from transformers import AutoProcessor, PaliGemmaForConditionalGeneration
|
| 2 |
+
from PIL import Image
|
| 3 |
+
import torch
|
| 4 |
+
import gradio as gr
|
| 5 |
+
|
| 6 |
+
# Load model and processor
|
| 7 |
+
processor = AutoProcessor.from_pretrained("google/paligemma-3b")
|
| 8 |
+
model = PaliGemmaForConditionalGeneration.from_pretrained(
|
| 9 |
+
"google/paligemma-3b",
|
| 10 |
+
torch_dtype=torch.float16,
|
| 11 |
+
device_map="auto"
|
| 12 |
+
)
|
| 13 |
+
|
| 14 |
+
def ecommerce_assistant(image, question):
|
| 15 |
+
prompt = f"Question: {question}\nAnswer:"
|
| 16 |
+
inputs = processor(text=prompt, images=image, return_tensors="pt").to("cuda", torch.float16)
|
| 17 |
+
outputs = model.generate(**inputs, max_new_tokens=50)
|
| 18 |
+
return processor.batch_decode(outputs, skip_special_tokens=True)[0]
|
| 19 |
+
|
| 20 |
+
demo = gr.Interface(
|
| 21 |
+
fn=ecommerce_assistant,
|
| 22 |
+
inputs=["image", "text"],
|
| 23 |
+
outputs="text",
|
| 24 |
+
title="🛍️ E-commerce Visual Assistant",
|
| 25 |
+
description="Upload a product photo and ask questions like 'What brand is this?' or 'Can I buy it online?'"
|
| 26 |
+
)
|
| 27 |
+
|
| 28 |
+
demo.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
transformers
|
| 2 |
+
torch
|
| 3 |
+
gradio
|
| 4 |
+
Pillow
|