MANIKANDAN A
commited on
Commit
·
f8843b8
1
Parent(s):
083d065
Update app.py
Browse files
app.py
CHANGED
@@ -100,7 +100,7 @@ def login_section():
|
|
100 |
|
101 |
|
102 |
|
103 |
-
def predict():
|
104 |
captions = []
|
105 |
pred_caption = generate_caption('tmp.jpg', caption_model)
|
106 |
|
@@ -118,41 +118,6 @@ def predict():
|
|
118 |
for c in captions:
|
119 |
cap_col.markdown(f'<div class="cap-line" style="color: black; background-color: light grey; padding: 5px; margin-bottom: 5px; font-family: \'Palatino Linotype\', \'Book Antiqua\', Palatino, serif;">{c}</div>', unsafe_allow_html=True)
|
120 |
cap_col.markdown('</div>', unsafe_allow_html=True)
|
121 |
-
|
122 |
-
st.markdown('<h1 style="text-align:center; font-family:Arial; width:fit-content; font-size:3em; color:black; text-shadow: 2px 2px 4px #000000;">IMAGE CAPTION GENERATOR</h1>', unsafe_allow_html=True)
|
123 |
-
col1, col2 = st.columns(2)
|
124 |
-
|
125 |
-
# Image URL input
|
126 |
-
img_url = st.text_input(label='Enter Image URL')
|
127 |
-
|
128 |
-
# Image upload input
|
129 |
-
img_upload = st.file_uploader(label='Upload Image', type=['jpg', 'png', 'jpeg'])
|
130 |
-
|
131 |
-
# Language selection dropdown
|
132 |
-
target_language = st.selectbox('Select Target Language', ['en', 'ta', 'hi', 'es', 'fr', 'zh-cn'], index=0)
|
133 |
-
|
134 |
-
# Process image and generate captions
|
135 |
-
if img_url:
|
136 |
-
img = Image.open(requests.get(img_url, stream=True).raw)
|
137 |
-
img = img.convert('RGB')
|
138 |
-
col1.image(img, caption="Input Image", use_column_width=True)
|
139 |
-
img.save('tmp.jpg')
|
140 |
-
predict(col2)
|
141 |
-
|
142 |
-
st.markdown('<center style="opacity: 70%">OR</center>', unsafe_allow_html=True)
|
143 |
-
|
144 |
-
elif img_upload:
|
145 |
-
img = img_upload.read()
|
146 |
-
img = Image.open(io.BytesIO(img))
|
147 |
-
img = img.convert('RGB')
|
148 |
-
col1.image(img, caption="Input Image", use_column_width=True)
|
149 |
-
img.save('tmp.jpg')
|
150 |
-
predict(col2)
|
151 |
-
|
152 |
-
# Remove temporary image file
|
153 |
-
if img_url or img_upload:
|
154 |
-
os.remove('tmp.jpg')
|
155 |
-
|
156 |
|
157 |
|
158 |
def main():
|
@@ -171,7 +136,40 @@ def main():
|
|
171 |
elif selected_tab == "Login":
|
172 |
login_section()
|
173 |
elif selected_tab == "Generate Caption":
|
174 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
175 |
else:
|
176 |
st.write("Please login to access this feature.")
|
177 |
|
|
|
100 |
|
101 |
|
102 |
|
103 |
+
def predict(cap_col):
|
104 |
captions = []
|
105 |
pred_caption = generate_caption('tmp.jpg', caption_model)
|
106 |
|
|
|
118 |
for c in captions:
|
119 |
cap_col.markdown(f'<div class="cap-line" style="color: black; background-color: light grey; padding: 5px; margin-bottom: 5px; font-family: \'Palatino Linotype\', \'Book Antiqua\', Palatino, serif;">{c}</div>', unsafe_allow_html=True)
|
120 |
cap_col.markdown('</div>', unsafe_allow_html=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
121 |
|
122 |
|
123 |
def main():
|
|
|
136 |
elif selected_tab == "Login":
|
137 |
login_section()
|
138 |
elif selected_tab == "Generate Caption":
|
139 |
+
st.markdown('<h1 style="text-align:center; font-family:Arial; width:fit-content; font-size:3em; color:black; text-shadow: 2px 2px 4px #000000;">IMAGE CAPTION GENERATOR</h1>', unsafe_allow_html=True)
|
140 |
+
col1, col2 = st.columns(2)
|
141 |
+
|
142 |
+
# Image URL input
|
143 |
+
img_url = st.text_input(label='Enter Image URL')
|
144 |
+
|
145 |
+
# Image upload input
|
146 |
+
img_upload = st.file_uploader(label='Upload Image', type=['jpg', 'png', 'jpeg'])
|
147 |
+
|
148 |
+
# Language selection dropdown
|
149 |
+
target_language = st.selectbox('Select Target Language', ['en', 'ta', 'hi', 'es', 'fr', 'zh-cn'], index=0)
|
150 |
+
|
151 |
+
# Process image and generate captions
|
152 |
+
if img_url:
|
153 |
+
img = Image.open(requests.get(img_url, stream=True).raw)
|
154 |
+
img = img.convert('RGB')
|
155 |
+
col1.image(img, caption="Input Image", use_column_width=True)
|
156 |
+
img.save('tmp.jpg')
|
157 |
+
predict(col2)
|
158 |
+
|
159 |
+
st.markdown('<center style="opacity: 70%">OR</center>', unsafe_allow_html=True)
|
160 |
+
|
161 |
+
elif img_upload:
|
162 |
+
img = img_upload.read()
|
163 |
+
img = Image.open(io.BytesIO(img))
|
164 |
+
img = img.convert('RGB')
|
165 |
+
col1.image(img, caption="Input Image", use_column_width=True)
|
166 |
+
img.save('tmp.jpg')
|
167 |
+
predict(col2)
|
168 |
+
|
169 |
+
# Remove temporary image file
|
170 |
+
if img_url or img_upload:
|
171 |
+
os.remove('tmp.jpg')
|
172 |
+
|
173 |
else:
|
174 |
st.write("Please login to access this feature.")
|
175 |
|