Commit
·
b0e280f
1
Parent(s):
04d88b1
feat: add choose image feature
Browse files- Dockerfile +1 -0
- app.py +44 -11
Dockerfile
CHANGED
@@ -19,5 +19,6 @@ RUN mkdir app
|
|
19 |
WORKDIR $HOME/app
|
20 |
COPY . $HOME/app
|
21 |
|
|
|
22 |
EXPOSE 8501
|
23 |
CMD streamlit run app.py
|
|
|
19 |
WORKDIR $HOME/app
|
20 |
COPY . $HOME/app
|
21 |
|
22 |
+
RUN echo "hello world"
|
23 |
EXPOSE 8501
|
24 |
CMD streamlit run app.py
|
app.py
CHANGED
@@ -1,13 +1,16 @@
|
|
1 |
import streamlit as st
|
2 |
import streamlit.components.v1 as components
|
3 |
from PIL import Image
|
|
|
4 |
|
5 |
from predict import generate_text
|
6 |
-
from model import
|
|
|
|
|
7 |
|
8 |
|
9 |
# Configure Streamlit page
|
10 |
-
st.set_page_config(page_title="Caption Machine", page_icon="
|
11 |
|
12 |
# Set Session
|
13 |
|
@@ -42,24 +45,54 @@ st.markdown(
|
|
42 |
"This app generates Image Caption using OpenAI's [GPT-2](https://openai.com/research/better-language-models) and [CLIP](https://openai.com/research/clip) model."
|
43 |
)
|
44 |
|
45 |
-
# st.subheader("Model Architecture")
|
46 |
|
47 |
-
# image = Image.open('model.png')
|
48 |
|
49 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
50 |
|
51 |
upload_file = st.file_uploader("Upload an image:", type=['png','jpg','jpeg'])
|
52 |
|
|
|
53 |
|
54 |
# Checking the Format of the page
|
55 |
-
if upload_file
|
56 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
57 |
st.image(img)
|
58 |
-
st.write("Image Uploaded Successfully")
|
59 |
|
60 |
# gpt_model, tokenizer = load_gpt_model()
|
61 |
-
|
62 |
-
|
63 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
64 |
|
65 |
|
|
|
1 |
import streamlit as st
|
2 |
import streamlit.components.v1 as components
|
3 |
from PIL import Image
|
4 |
+
import requests
|
5 |
|
6 |
from predict import generate_text
|
7 |
+
from model import load_model
|
8 |
+
|
9 |
+
from streamlit_image_select import image_select
|
10 |
|
11 |
|
12 |
# Configure Streamlit page
|
13 |
+
st.set_page_config(page_title="Caption Machine", page_icon="📸")
|
14 |
|
15 |
# Set Session
|
16 |
|
|
|
45 |
"This app generates Image Caption using OpenAI's [GPT-2](https://openai.com/research/better-language-models) and [CLIP](https://openai.com/research/clip) model."
|
46 |
)
|
47 |
|
|
|
48 |
|
|
|
49 |
|
50 |
+
# Select image or upload image
|
51 |
+
select_file = image_select(
|
52 |
+
label="Select a photo:",
|
53 |
+
images=[
|
54 |
+
"https://farm5.staticflickr.com/4084/5093294428_2f50d54acb_z.jpg",
|
55 |
+
"https://farm8.staticflickr.com/7044/6855243647_cd204d079c_z.jpg",
|
56 |
+
"http://farm4.staticflickr.com/3016/2650267987_f478c8d682_z.jpg",
|
57 |
+
"https://farm8.staticflickr.com/7249/6913786280_c145ecc433_z.jpg",
|
58 |
+
],
|
59 |
+
# captions=["A cat", "Another cat", "Oh look, a cat!", "Guess what, a cat..."],
|
60 |
+
)
|
61 |
+
|
62 |
+
|
63 |
|
64 |
upload_file = st.file_uploader("Upload an image:", type=['png','jpg','jpeg'])
|
65 |
|
66 |
+
st.divider()
|
67 |
|
68 |
# Checking the Format of the page
|
69 |
+
if upload_file or select_file:
|
70 |
+
|
71 |
+
img = None
|
72 |
+
|
73 |
+
if upload_file:
|
74 |
+
img = Image.open(upload_file)
|
75 |
+
|
76 |
+
elif select_file:
|
77 |
+
st.text(select_file)
|
78 |
+
img = Image.open(requests.get(select_file, stream=True).raw)
|
79 |
+
|
80 |
+
|
81 |
st.image(img)
|
82 |
+
# st.write("Image Uploaded Successfully")
|
83 |
|
84 |
# gpt_model, tokenizer = load_gpt_model()
|
85 |
+
with st.spinner('Generating caption...'):
|
86 |
+
caption = generate_text(st.session_state['model'], img, st.session_state['tokenizer'], st.session_state['image_transform'])
|
87 |
+
|
88 |
+
st.success(f"Result: {caption}")
|
89 |
+
|
90 |
+
|
91 |
+
# Model information
|
92 |
+
with st.expander("See model architecture"):
|
93 |
+
st.write("")
|
94 |
+
|
95 |
+
model_img = Image.open('./model.png')
|
96 |
+
st.image(model_img, width=500)
|
97 |
|
98 |
|