Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import BlipProcessor, BlipForConditionalGeneration
|
3 |
+
from huggingface_hub import login
|
4 |
+
from PIL import Image
|
5 |
+
|
6 |
+
# Step 1: Authenticate with Hugging Face using your token
|
7 |
+
login(token="") # Paste your token here
|
8 |
+
|
9 |
+
# Step 2: Load the processor and the private model
|
10 |
+
model_name = "anushettypsl/paligemma_vqav2" # Replace with actual model link
|
11 |
+
processor = BlipProcessor.from_pretrained(model_name)
|
12 |
+
model = BlipForConditionalGeneration.from_pretrained(model_name)
|
13 |
+
|
14 |
+
# Step 3: Define the prediction function
|
15 |
+
def predict(image):
|
16 |
+
inputs = processor(image, return_tensors="pt")
|
17 |
+
outputs = model.generate(**inputs)
|
18 |
+
generated_text = processor.decode(outputs[0], skip_special_tokens=True)
|
19 |
+
return generated_text
|
20 |
+
|
21 |
+
# Step 4: Create the Gradio interface
|
22 |
+
interface = gr.Interface(
|
23 |
+
fn=predict,
|
24 |
+
inputs=gr.Image(type="pil"), # Image input
|
25 |
+
outputs="text", # Text output
|
26 |
+
title="Image-to-Text Model"
|
27 |
+
)
|
28 |
+
|
29 |
+
# Step 5: Launch the app
|
30 |
+
interface.launch()
|