MANIKANDAN A
commited on
Commit
·
c579034
1
Parent(s):
3691b02
Update app.py
Browse files
app.py
CHANGED
@@ -1,4 +1,6 @@
|
|
1 |
import sqlite3
|
|
|
|
|
2 |
import streamlit as st
|
3 |
from PIL import Image
|
4 |
import tensorflow as tf
|
@@ -93,6 +95,23 @@ def login_section():
|
|
93 |
except sqlite3.OperationalError as e:
|
94 |
st.error(f"An error occurred while trying to log in: {e}")
|
95 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
96 |
def main():
|
97 |
# Create the database table if it doesn't exist
|
98 |
create_table()
|
@@ -130,12 +149,8 @@ def main():
|
|
130 |
|
131 |
img = img.convert('RGB')
|
132 |
col1.image(img, caption="Input Image", use_column_width=True)
|
133 |
-
|
134 |
-
|
135 |
-
img_tensor = tf.image.resize(img_tensor, (224, 224))
|
136 |
-
|
137 |
-
caption_model = get_caption_model()
|
138 |
-
generated_caption = generate_caption(img, caption_model)
|
139 |
|
140 |
if generated_caption:
|
141 |
col2.markdown('<div style="margin-top: 15px; padding: 10px; background-color: #e6f7ff; border-radius: 5px;">' + generated_caption + '</div>', unsafe_allow_html=True)
|
|
|
1 |
import sqlite3
|
2 |
+
import io
|
3 |
+
import os
|
4 |
import streamlit as st
|
5 |
from PIL import Image
|
6 |
import tensorflow as tf
|
|
|
95 |
except sqlite3.OperationalError as e:
|
96 |
st.error(f"An error occurred while trying to log in: {e}")
|
97 |
|
98 |
+
def predict(cap_col):
|
99 |
+
captions = []
|
100 |
+
pred_caption = generate_caption('tmp.jpg', caption_model)
|
101 |
+
|
102 |
+
cap_col.markdown('#### Predicted Captions:')
|
103 |
+
captions.append(pred_caption)
|
104 |
+
|
105 |
+
for _ in range(4):
|
106 |
+
pred_caption = generate_caption('tmp.jpg', caption_model, add_noise=True)
|
107 |
+
if pred_caption not in captions:
|
108 |
+
captions.append(pred_caption_caption)
|
109 |
+
|
110 |
+
cap_col.markdown('<div class="caption-container">', unsafe_allow_html=True)
|
111 |
+
for c in captions:
|
112 |
+
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)
|
113 |
+
cap_col.markdown('</div>', unsafe_allow_html=True)
|
114 |
+
|
115 |
def main():
|
116 |
# Create the database table if it doesn't exist
|
117 |
create_table()
|
|
|
149 |
|
150 |
img = img.convert('RGB')
|
151 |
col1.image(img, caption="Input Image", use_column_width=True)
|
152 |
+
img.save('tmp.jpg')
|
153 |
+
predict(col2)
|
|
|
|
|
|
|
|
|
154 |
|
155 |
if generated_caption:
|
156 |
col2.markdown('<div style="margin-top: 15px; padding: 10px; background-color: #e6f7ff; border-radius: 5px;">' + generated_caption + '</div>', unsafe_allow_html=True)
|