triphuong57 commited on
Commit
a5458c0
β€’
1 Parent(s): 4c9d89f

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -0
app.py ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import AutoProcessor, PaliGemmaForConditionalGeneration
3
+ from peft import PeftModel
4
+ import spaces
5
+
6
+ @spaces.GPU
7
+ def greet(image, prompt):
8
+ base_model = PaliGemmaForConditionalGeneration.from_pretrained("google/paligemma-3b-mix-224")
9
+ processor = AutoProcessor.from_pretrained("google/paligemma-3b-mix-224")
10
+ model = PeftModel(base_model, "/folders")
11
+ inputs = processor(prompt, raw_image, return_tensors="pt")
12
+ output = model.generate(**inputs, max_new_tokens=20)
13
+ return output
14
+
15
+ demo = gr.Interface(fn=greet, inputs=[gr.Image(label="Upload image", sources=['upload', 'webcam'], type="pil"), gr.Text()], outputs="text")
16
+ demo.launch()