Spaces:
Runtime error
Runtime error
seanbenhur
commited on
Commit
·
969520d
1
Parent(s):
7bbc0b3
Update app.py
Browse files
app.py
CHANGED
@@ -18,9 +18,7 @@ def predict(image,max_length=64, num_beams=4):
|
|
18 |
image = image.convert('RGB')
|
19 |
image = feature_extractor(image, return_tensors="pt").pixel_values.to(device)
|
20 |
clean_text = lambda x: x.replace('<|endoftext|>','').split('\n')[0]
|
21 |
-
caption_ids = model.generate(
|
22 |
-
print("*"*20)
|
23 |
-
print(caption_ids)
|
24 |
caption_text = clean_text(tokenizer.decode(caption_ids))
|
25 |
return caption_text
|
26 |
|
@@ -32,12 +30,14 @@ output = gr.outputs.Textbox(type="auto",label="Captions")
|
|
32 |
|
33 |
article = "This HuggingFace Space presents a demo for Image captioning in Hindi built with VIT Encoder and GPT2 Decoder"
|
34 |
title = "Hindi Image Captioning System"
|
|
|
|
|
35 |
interface = gr.Interface(
|
36 |
fn=predict,
|
37 |
inputs = input,
|
38 |
theme="grass",
|
39 |
outputs=output,
|
40 |
-
|
41 |
title=title,
|
42 |
description=article,
|
43 |
)
|
|
|
18 |
image = image.convert('RGB')
|
19 |
image = feature_extractor(image, return_tensors="pt").pixel_values.to(device)
|
20 |
clean_text = lambda x: x.replace('<|endoftext|>','').split('\n')[0]
|
21 |
+
caption_ids = model.generate(image, max_length = max_length)[0]
|
|
|
|
|
22 |
caption_text = clean_text(tokenizer.decode(caption_ids))
|
23 |
return caption_text
|
24 |
|
|
|
30 |
|
31 |
article = "This HuggingFace Space presents a demo for Image captioning in Hindi built with VIT Encoder and GPT2 Decoder"
|
32 |
title = "Hindi Image Captioning System"
|
33 |
+
examples = [f"./example_{i}.jpg" for i in range(1,5)]
|
34 |
+
|
35 |
interface = gr.Interface(
|
36 |
fn=predict,
|
37 |
inputs = input,
|
38 |
theme="grass",
|
39 |
outputs=output,
|
40 |
+
examples = examples,
|
41 |
title=title,
|
42 |
description=article,
|
43 |
)
|