Spaces:
Sleeping
Sleeping
Initial commit
Browse files- app.py +31 -0
- requirements.txt +4 -0
app.py
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import numpy as np
|
3 |
+
from PIL import Image
|
4 |
+
from transformers import AutoProcessor, AutoModelForPreTraining
|
5 |
+
import os
|
6 |
+
|
7 |
+
# PaliGemma settings
|
8 |
+
#access_token = os.getenv('HF_TOKEN')
|
9 |
+
processor = AutoProcessor.from_pretrained("google/paligemma-3b-pt-896")
|
10 |
+
model = AutoModelForPreTraining.from_pretrained("google/paligemma-3b-pt-896")
|
11 |
+
|
12 |
+
def response_request(image,prompt):
|
13 |
+
inputs = processor(prompt, image, return_tensors="pt")
|
14 |
+
output = model.generate(**inputs, max_new_tokens=100, do_sample=False)
|
15 |
+
response = processor.decode(output[0], skip_special_tokens=True)[len(prompt):]
|
16 |
+
return response
|
17 |
+
|
18 |
+
# Interface
|
19 |
+
iface = gr.Interface(
|
20 |
+
fn=response_request,
|
21 |
+
inputs=[
|
22 |
+
gr.Image(type="pil", label="Upload Image"),
|
23 |
+
gr.Textbox(label="Prompt")
|
24 |
+
],
|
25 |
+
outputs=[
|
26 |
+
gr.Textbox(label="Response")
|
27 |
+
],
|
28 |
+
title="PaliGemma (google/paligemma-3b-pt-896)"
|
29 |
+
)
|
30 |
+
|
31 |
+
iface.launch()
|
requirements.txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
gradio
|
2 |
+
numpy
|
3 |
+
pillow
|
4 |
+
transformers
|