Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import AutoProcessor, PaliGemmaForConditionalGeneration, BitsAndBytesConfig
|
3 |
+
from peft import PeftModel
|
4 |
+
import spaces
|
5 |
+
import torch
|
6 |
+
from huggingface_hub.hf_api import HfFolder
|
7 |
+
import os
|
8 |
+
token = os.getenv('token')
|
9 |
+
HfFolder.save_token(token)
|
10 |
+
device = "cuda"
|
11 |
+
model = PaliGemmaForConditionalGeneration.from_pretrained("google/paligemma-3b-mix-224")
|
12 |
+
processor = AutoProcessor.from_pretrained("google/paligemma-3b-mix-224")
|
13 |
+
|
14 |
+
@spaces.GPU(duration=120)
|
15 |
+
def greet(image, prompt):
|
16 |
+
|
17 |
+
# quantization_config = BitsAndBytesConfig(
|
18 |
+
# load_in_4bit=True, bnb_4bit_quant_type="nf4", bnb_4bit_compute_dtype=torch.float16
|
19 |
+
# )
|
20 |
+
|
21 |
+
|
22 |
+
# model = PaliGemmaForConditionalGeneration.from_pretrained("/folders", torch_dtype=torch.float16, quantization_config=quantization_config).to(device)
|
23 |
+
|
24 |
+
|
25 |
+
# # model = PeftModel(base_model, "/folders").to(device)
|
26 |
+
inputs = processor(prompt, raw_image, return_tensors="pt")
|
27 |
+
output = model.generate(**inputs, max_new_tokens=20)
|
28 |
+
return output
|
29 |
+
|
30 |
+
demo = gr.Interface(fn=greet, inputs=[gr.Image(label="Upload image", sources=['upload', 'webcam'], type="pil"), gr.Text()], outputs="text")
|
31 |
+
demo.launch()
|