DarwinAnim8or commited on
Commit
6c0f47c
1 Parent(s): a9490fc

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -0
app.py ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ def generate_caption(image):
9
+ inputs = processor(images=image, return_tensors="pt")
10
+ pixel_values = inputs.pixel_values
11
+
12
+ generated_ids = model.generate(pixel_values=pixel_values, max_length=50)
13
+ generated_caption = processor.batch_decode(generated_ids, skip_special_tokens=True)[0]
14
+
15
+ return generated_caption
16
+
17
+ # Create a gradio interface with an image input and a textbox output
18
+ demo = gr.Interface(fn=generate_caption, inputs=gr.Image(shape=(224, 224)), outputs=gr.Textbox(label="Generated caption"))
19
+ demo.launch()