Spaces:
Sleeping
Sleeping
added code
Browse files
app.py
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import BlipProcessor, BlipForConditionalGeneration
|
3 |
+
from PIL import Image
|
4 |
+
import torch
|
5 |
+
|
6 |
+
# Example with BLIP (replace with your fine-tuned model)
|
7 |
+
processor = BlipProcessor.from_pretrained("Salesforce/blip-image-captioning-large")
|
8 |
+
model = BlipForConditionalGeneration.from_pretrained("Salesforce/blip-image-captioning-large")
|
9 |
+
|
10 |
+
def caption_image(image):
|
11 |
+
if image is None:
|
12 |
+
return "No image provided"
|
13 |
+
inputs = processor(images=image, return_tensors="pt")
|
14 |
+
with torch.no_grad():
|
15 |
+
out = model.generate(**inputs)
|
16 |
+
caption = processor.decode(out[0], skip_special_tokens=True)
|
17 |
+
return caption
|
18 |
+
|
19 |
+
demo = gr.Interface(
|
20 |
+
fn=caption_image,
|
21 |
+
inputs=gr.Image(type="pil"),
|
22 |
+
outputs="text",
|
23 |
+
title="Custom UI Action Description"
|
24 |
+
)
|
25 |
+
|
26 |
+
if __name__ == "__main__":
|
27 |
+
demo.launch()
|