Spaces:
Runtime error
Runtime error
Update pages/ImageToText.py
Browse files- pages/ImageToText.py +10 -1
pages/ImageToText.py
CHANGED
@@ -14,7 +14,15 @@ vitgpt_model.to(device)
|
|
14 |
def generate_caption(processor, model, image, tokenizer=None):
|
15 |
|
16 |
inputs = processor(images=image, return_tensors="pt").to(device)
|
17 |
-
generated_ids = model.generate(pixel_values=inputs.pixel_values,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
|
19 |
if tokenizer is not None:
|
20 |
generated_caption = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
|
@@ -29,6 +37,7 @@ def generate_captions(image):
|
|
29 |
uploaded_file = st.file_uploader("Upload your image")
|
30 |
if uploaded_file is not None:
|
31 |
image = Image.open(uploaded_file)
|
|
|
32 |
generated_caption = generate_caption(vitgpt_processor, vitgpt_model, image, vitgpt_tokenizer)
|
33 |
st.write(generated_caption)
|
34 |
|
|
|
14 |
def generate_caption(processor, model, image, tokenizer=None):
|
15 |
|
16 |
inputs = processor(images=image, return_tensors="pt").to(device)
|
17 |
+
generated_ids = model.generate(pixel_values=inputs.pixel_values,
|
18 |
+
max_length=100,
|
19 |
+
num_beams=5,
|
20 |
+
do_sample=True,
|
21 |
+
temperature=1.,
|
22 |
+
top_k=50,
|
23 |
+
top_p=0.6,
|
24 |
+
no_repeat_ngram_size=3,
|
25 |
+
num_return_sequences=3)
|
26 |
|
27 |
if tokenizer is not None:
|
28 |
generated_caption = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
|
|
|
37 |
uploaded_file = st.file_uploader("Upload your image")
|
38 |
if uploaded_file is not None:
|
39 |
image = Image.open(uploaded_file)
|
40 |
+
st.image(image)
|
41 |
generated_caption = generate_caption(vitgpt_processor, vitgpt_model, image, vitgpt_tokenizer)
|
42 |
st.write(generated_caption)
|
43 |
|