Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,21 +1,13 @@
|
|
1 |
import streamlit as st
|
2 |
from PIL import Image
|
3 |
-
from transformers import GPT2TokenizerFast, ViTImageProcessor, VisionEncoderDecoderModel,RobertaTokenizerFast
|
4 |
-
|
5 |
-
|
6 |
-
import requests
|
7 |
-
from PIL import Image
|
8 |
-
|
9 |
-
from transformers import GPT2TokenizerFast, ViTImageProcessor, VisionEncoderDecoderModel
|
10 |
-
|
11 |
-
|
12 |
|
13 |
#import torch
|
14 |
#from transformers import BlipProcessor, BlipForConditionalGeneration
|
15 |
|
16 |
def set_page_config():
|
17 |
st.set_page_config(
|
18 |
-
page_title='Caption an Image',
|
19 |
page_icon=':camera:',
|
20 |
layout='wide',
|
21 |
)
|
@@ -31,8 +23,7 @@ def initialize_model():
|
|
31 |
def upload_image():
|
32 |
return st.sidebar.file_uploader("Upload an image (we aren't storing anything)", type=["jpg", "jpeg", "png"])
|
33 |
|
34 |
-
def
|
35 |
-
|
36 |
image = image.resize((max_width, height))
|
37 |
if image.mode == "L":
|
38 |
image = image.convert("RGB")
|
@@ -53,28 +44,27 @@ def main():
|
|
53 |
|
54 |
if uploaded_image is not None:
|
55 |
image = Image.open(uploaded_image)
|
56 |
-
image =
|
57 |
-
|
58 |
st.image(image, caption='Your image')
|
59 |
|
60 |
with st.sidebar:
|
61 |
st.divider()
|
62 |
if st.sidebar.button('Generate Caption'):
|
63 |
with st.spinner('Generating caption...'):
|
64 |
-
|
65 |
-
|
66 |
-
caption=
|
|
|
67 |
st.header("Caption:")
|
68 |
st.markdown(f'**{caption}**')
|
69 |
|
70 |
|
71 |
-
|
72 |
if __name__ == '__main__':
|
73 |
main()
|
74 |
|
75 |
|
76 |
st.markdown("""
|
77 |
---
|
78 |
-
You are looking at
|
79 |
-
|
80 |
|
|
|
1 |
import streamlit as st
|
2 |
from PIL import Image
|
3 |
+
from transformers import GPT2TokenizerFast, ViTImageProcessor, VisionEncoderDecoderModel,RobertaTokenizerFast, VisionEncoderDecoderModel
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
|
5 |
#import torch
|
6 |
#from transformers import BlipProcessor, BlipForConditionalGeneration
|
7 |
|
8 |
def set_page_config():
|
9 |
st.set_page_config(
|
10 |
+
page_title='Caption an Cartoon Image',
|
11 |
page_icon=':camera:',
|
12 |
layout='wide',
|
13 |
)
|
|
|
23 |
def upload_image():
|
24 |
return st.sidebar.file_uploader("Upload an image (we aren't storing anything)", type=["jpg", "jpeg", "png"])
|
25 |
|
26 |
+
def image_preprocess(image):
|
|
|
27 |
image = image.resize((max_width, height))
|
28 |
if image.mode == "L":
|
29 |
image = image.convert("RGB")
|
|
|
44 |
|
45 |
if uploaded_image is not None:
|
46 |
image = Image.open(uploaded_image)
|
47 |
+
image = image_preprocess(image)
|
48 |
+
|
49 |
st.image(image, caption='Your image')
|
50 |
|
51 |
with st.sidebar:
|
52 |
st.divider()
|
53 |
if st.sidebar.button('Generate Caption'):
|
54 |
with st.spinner('Generating caption...'):
|
55 |
+
image_processor, model,tokenizer, device = initialize_model()
|
56 |
+
|
57 |
+
caption = generate_caption(image_processor, model, device, image)
|
58 |
+
#caption="im here man"
|
59 |
st.header("Caption:")
|
60 |
st.markdown(f'**{caption}**')
|
61 |
|
62 |
|
|
|
63 |
if __name__ == '__main__':
|
64 |
main()
|
65 |
|
66 |
|
67 |
st.markdown("""
|
68 |
---
|
69 |
+
You are looking at partial finetuned model , please JUDGE ME!!! """)
|
|
|
70 |
|