Spaces:
Runtime error
Runtime error
Add application files
Browse files- app.py +27 -0
- requirements.txt +3 -0
app.py
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import BlipProcessor, BlipForConditionalGeneration
|
3 |
+
|
4 |
+
model_id = "dblasko/blip-dalle3-img2prompt"
|
5 |
+
model = BlipForConditionalGeneration.from_pretrained(model_id)
|
6 |
+
processor = BlipProcessor.from_pretrained(model_id)
|
7 |
+
|
8 |
+
|
9 |
+
def gen_caption(image):
|
10 |
+
inputs = processor(images=image, return_tensors="pt")
|
11 |
+
pixel_values = inputs.pixel_values
|
12 |
+
|
13 |
+
generated_ids = model.generate(pixel_values=pixel_values, max_length=70)
|
14 |
+
generated_caption = processor.batch_decode(generated_ids, skip_special_tokens=True)[
|
15 |
+
0
|
16 |
+
]
|
17 |
+
|
18 |
+
return generated_caption
|
19 |
+
|
20 |
+
|
21 |
+
# Create a gradio interface with an image input and a textbox output
|
22 |
+
demo = gr.Interface(
|
23 |
+
fn=gen_caption,
|
24 |
+
inputs=gr.Image(shape=(224, 224)),
|
25 |
+
outputs=gr.Textbox(label="Generated caption"),
|
26 |
+
)
|
27 |
+
demo.launch()
|
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
gradio
|
2 |
+
torch
|
3 |
+
transformers
|