Spaces:
Runtime error
Runtime error
Commit
·
ea98132
1
Parent(s):
aeceb12
Suggestion to simplify
Browse files
app.py
CHANGED
@@ -14,39 +14,35 @@ processor = AutoProcessor.from_pretrained(config.base_model_name_or_path)
|
|
14 |
model = model.to(device)
|
15 |
model.eval()
|
16 |
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
|
|
|
|
22 |
prompts = [[image, prompt]]
|
23 |
inputs = processor(prompts[0], return_tensors="pt").to(device)
|
24 |
generated_ids = model.generate(**inputs, max_length=max_length)
|
25 |
generated_text = processor.batch_decode(generated_ids, skip_special_tokens=True)[0]
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
|
30 |
title = "Midjourney-like Image Captioning with IDEFICS"
|
31 |
description = "Gradio Demo for generating *Midjourney* like captions (describe functionality) with **IDEFICS**"
|
32 |
|
33 |
examples = [
|
34 |
-
["
|
35 |
-
["
|
36 |
-
["
|
37 |
-
["
|
38 |
-
["
|
39 |
-
|
40 |
]
|
41 |
io = gr.Interface(fn=predict,
|
42 |
inputs=[
|
43 |
-
gr.
|
44 |
-
gr.Textbox(label="image URL", placeholder="Insert the URL of the image to be described"),
|
45 |
-
gr.Image(label="or upload an image", type="pil"),
|
46 |
-
gr.Slider(label="Max tokens", value=64, max=128, min=16, step=8)
|
47 |
],
|
48 |
outputs=[
|
49 |
-
gr.Image(type='pil', label="Image"),
|
50 |
gr.Textbox(label="IDEFICS Description")
|
51 |
],
|
52 |
title=title, description=description, examples=examples,
|
|
|
14 |
model = model.to(device)
|
15 |
model.eval()
|
16 |
|
17 |
+
#Pre-determined best prompt for this fine-tune
|
18 |
+
prompt="Describe the following image:"
|
19 |
+
|
20 |
+
#Max generated tokens for your prompt
|
21 |
+
max_length=64
|
22 |
+
|
23 |
+
def predict(image):
|
24 |
prompts = [[image, prompt]]
|
25 |
inputs = processor(prompts[0], return_tensors="pt").to(device)
|
26 |
generated_ids = model.generate(**inputs, max_length=max_length)
|
27 |
generated_text = processor.batch_decode(generated_ids, skip_special_tokens=True)[0]
|
28 |
+
generated_text = generated_text.replace(prompt,"")
|
29 |
+
return generated_text
|
|
|
30 |
|
31 |
title = "Midjourney-like Image Captioning with IDEFICS"
|
32 |
description = "Gradio Demo for generating *Midjourney* like captions (describe functionality) with **IDEFICS**"
|
33 |
|
34 |
examples = [
|
35 |
+
["1_sTXgMwDUW0pk-1yK4iHYFw.png"],
|
36 |
+
["0_6as5rHi0sgG4W2Tq.png"],
|
37 |
+
["zoomout_2-1440x807.jpg"],
|
38 |
+
["inZdRVn7eafZNvaVre2iW1a538.png"],
|
39 |
+
["cute-photos-of-cats-in-grass-1593184777.jpg"]
|
|
|
40 |
]
|
41 |
io = gr.Interface(fn=predict,
|
42 |
inputs=[
|
43 |
+
gr.Image(label="Upload an image", type="pil"),
|
|
|
|
|
|
|
44 |
],
|
45 |
outputs=[
|
|
|
46 |
gr.Textbox(label="IDEFICS Description")
|
47 |
],
|
48 |
title=title, description=description, examples=examples,
|