Update app.py
Browse files
app.py
CHANGED
@@ -6,12 +6,12 @@ from transformers import BlipProcessor, BlipForConditionalGeneration
|
|
6 |
processor = BlipProcessor.from_pretrained("Salesforce/blip-image-captioning-large")
|
7 |
model = BlipForConditionalGeneration.from_pretrained("Salesforce/blip-image-captioning-large")
|
8 |
|
9 |
-
def caption(img):
|
10 |
raw_image = Image.open(img).convert('RGB')
|
11 |
|
12 |
inputs = processor(raw_image, return_tensors="pt")
|
13 |
|
14 |
-
out = model.generate(**inputs, min_length=
|
15 |
return processor.decode(out[0], skip_special_tokens=True)
|
16 |
|
17 |
def greet(img):
|
@@ -20,7 +20,7 @@ def greet(img):
|
|
20 |
iface = gr.Interface(fn=greet,
|
21 |
title='Blip Image Captioning Large',
|
22 |
description="[Salesforce/blip-image-captioning-large](https://huggingface.co/Salesforce/blip-image-captioning-large)",
|
23 |
-
inputs=gr.Image(type='filepath', label='Image'),
|
24 |
outputs=gr.Textbox(label='Caption'),
|
25 |
theme = gr.themes.Base(primary_hue="teal",secondary_hue="teal",neutral_hue="slate"),)
|
26 |
iface.launch()
|
|
|
6 |
processor = BlipProcessor.from_pretrained("Salesforce/blip-image-captioning-large")
|
7 |
model = BlipForConditionalGeneration.from_pretrained("Salesforce/blip-image-captioning-large")
|
8 |
|
9 |
+
def caption(img, min, max):
|
10 |
raw_image = Image.open(img).convert('RGB')
|
11 |
|
12 |
inputs = processor(raw_image, return_tensors="pt")
|
13 |
|
14 |
+
out = model.generate(**inputs, min_length=min, max_length=max)
|
15 |
return processor.decode(out[0], skip_special_tokens=True)
|
16 |
|
17 |
def greet(img):
|
|
|
20 |
iface = gr.Interface(fn=greet,
|
21 |
title='Blip Image Captioning Large',
|
22 |
description="[Salesforce/blip-image-captioning-large](https://huggingface.co/Salesforce/blip-image-captioning-large)",
|
23 |
+
inputs=[gr.Image(type='filepath', label='Image'), gr.Slider(label='Minimum Length', minimum=1, maximum=1000, value=30), gr.Slider(label='Maximum Length', minimum=1, maximum=1000, value=100)],
|
24 |
outputs=gr.Textbox(label='Caption'),
|
25 |
theme = gr.themes.Base(primary_hue="teal",secondary_hue="teal",neutral_hue="slate"),)
|
26 |
iface.launch()
|