Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,48 +1,49 @@
|
|
1 |
-
|
2 |
-
#
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
# logging.set_verbosity_error()
|
7 |
|
8 |
-
|
9 |
-
# processor = AutoProcessor.from_pretrained("Salesforce/blip-image-captioning-base")
|
10 |
|
11 |
-
|
12 |
-
|
13 |
-
# out = model.generate(**inputs)
|
14 |
-
# caption = processor.decode(out[0], skip_special_tokens=True)
|
15 |
-
# return caption
|
16 |
|
|
|
|
|
|
|
|
|
|
|
17 |
|
18 |
|
|
|
|
|
19 |
# gr.Interface(caption_image, gr.inputs.Image(), "text").launch()
|
20 |
-
#
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
-
import streamlit as st
|
26 |
-
# from PIL import Image
|
27 |
-
from transformers.utils import logging
|
28 |
-
from transformers import BlipForConditionalGeneration, AutoProcessor
|
29 |
-
import torch
|
30 |
|
31 |
-
logging.set_verbosity_error()
|
32 |
|
33 |
-
model = BlipForConditionalGeneration.from_pretrained("Salesforce/blip-image-captioning-base")
|
34 |
-
processor = AutoProcessor.from_pretrained("Salesforce/blip-image-captioning-base")
|
35 |
|
36 |
-
st.title("Image Captioning")
|
37 |
|
38 |
-
uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
|
39 |
|
40 |
-
if uploaded_file is not None:
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
|
|
1 |
+
import gradio as gr
|
2 |
+
# from PIL import Image
|
3 |
+
from transformers.utils import logging
|
4 |
+
from transformers import BlipForConditionalGeneration, AutoProcessor
|
|
|
|
|
5 |
|
6 |
+
logging.set_verbosity_error()
|
|
|
7 |
|
8 |
+
model = BlipForConditionalGeneration.from_pretrained("Salesforce/blip-image-captioning-base")
|
9 |
+
processor = AutoProcessor.from_pretrained("Salesforce/blip-image-captioning-base")
|
|
|
|
|
|
|
10 |
|
11 |
+
def caption_image(image):
|
12 |
+
inputs = processor(image, return_tensors="pt")
|
13 |
+
out = model.generate(**inputs)
|
14 |
+
caption = processor.decode(out[0], skip_special_tokens=True)
|
15 |
+
return caption
|
16 |
|
17 |
|
18 |
+
iface = gr.Interface(fn=caption_image, inputs=["image"], outputs="textbox")
|
19 |
+
iface.launch()
|
20 |
# gr.Interface(caption_image, gr.inputs.Image(), "text").launch()
|
21 |
+
# gr.Interface(caption_image, image_input, caption_output).launch()
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
+
# import streamlit as st
|
27 |
+
# # from PIL import Image
|
28 |
+
# from transformers.utils import logging
|
29 |
+
# from transformers import BlipForConditionalGeneration, AutoProcessor
|
30 |
+
# import torch
|
31 |
|
32 |
+
# logging.set_verbosity_error()
|
33 |
|
34 |
+
# model = BlipForConditionalGeneration.from_pretrained("Salesforce/blip-image-captioning-base")
|
35 |
+
# processor = AutoProcessor.from_pretrained("Salesforce/blip-image-captioning-base")
|
36 |
|
37 |
+
# st.title("Image Captioning")
|
38 |
|
39 |
+
# uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
|
40 |
|
41 |
+
# if uploaded_file is not None:
|
42 |
+
# image = Image.open(uploaded_file)
|
43 |
+
# st.image(image, caption="Uploaded Image", use_column_width=True)
|
44 |
+
# st.write("")
|
45 |
+
# st.write("Generating caption...")
|
46 |
+
# inputs = processor(image, return_tensors="pt")
|
47 |
+
# out = model.generate(**inputs)
|
48 |
+
# caption = processor.decode(out[0], skip_special_tokens=True)
|
49 |
+
# st.write("Caption:", caption)
|