Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -9,11 +9,27 @@ from transformers import BlipProcessor, BlipForConditionalGeneration
|
|
9 |
model = BlipForConditionalGeneration.from_pretrained('jaimin/Imagecap')
|
10 |
processor = BlipProcessor.from_pretrained('jaimin/Imagecap')
|
11 |
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
model = BlipForConditionalGeneration.from_pretrained('jaimin/Imagecap')
|
10 |
processor = BlipProcessor.from_pretrained('jaimin/Imagecap')
|
11 |
|
12 |
+
|
13 |
+
|
14 |
+
def predict(image,max_length=64, num_beams=4):
|
15 |
+
image = image.convert('RGB')
|
16 |
+
image = feature_extractor(image, return_tensors="pt").pixel_values.to(device)
|
17 |
+
#clean_text = lambda x: x.replace('<|endoftext|>','').split('\n')[0]
|
18 |
+
caption_ids = model.generate(image, max_length = max_length)[0]
|
19 |
+
caption_text = tokenizer.decode(caption_ids)
|
20 |
+
return processor.decode(caption_ids[0], skip_special_tokens=True)
|
21 |
+
|
22 |
+
|
23 |
+
|
24 |
+
input = gr.inputs.Image(label="Upload your Image", type = 'pil', optional=True)
|
25 |
+
output = gr.outputs.Textbox(label="Captions")
|
26 |
+
|
27 |
+
title = "ImageCap"
|
28 |
+
|
29 |
+
interface = gr.Interface(
|
30 |
+
fn=predict,
|
31 |
+
inputs = input,
|
32 |
+
outputs=output,
|
33 |
+
title=title,
|
34 |
+
)
|
35 |
+
interface.launch(debug=True)
|