Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -10,10 +10,64 @@ except ImportError as e:
|
|
| 10 |
st.error("Please make sure all required libraries are installed.")
|
| 11 |
st.stop()
|
| 12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
def main():
|
| 14 |
-
|
|
|
|
|
|
|
| 15 |
|
|
|
|
| 16 |
uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
|
|
|
|
| 17 |
|
| 18 |
if uploaded_file is not None:
|
| 19 |
try:
|
|
@@ -24,8 +78,10 @@ def main():
|
|
| 24 |
with st.spinner('Generating caption...'):
|
| 25 |
try:
|
| 26 |
caption = generate_caption(image)
|
| 27 |
-
st.
|
| 28 |
-
st.
|
|
|
|
|
|
|
| 29 |
except Exception as e:
|
| 30 |
st.error(f"An error occurred while generating the caption: {str(e)}")
|
| 31 |
st.error("Detailed error traceback:")
|
|
|
|
| 10 |
st.error("Please make sure all required libraries are installed.")
|
| 11 |
st.stop()
|
| 12 |
|
| 13 |
+
def set_custom_style():
|
| 14 |
+
st.markdown("""
|
| 15 |
+
<style>
|
| 16 |
+
.stApp {
|
| 17 |
+
max-width: 800px;
|
| 18 |
+
margin: 0 auto;
|
| 19 |
+
background-color: #f0f2f6;
|
| 20 |
+
padding: 2rem;
|
| 21 |
+
border-radius: 10px;
|
| 22 |
+
}
|
| 23 |
+
.title {
|
| 24 |
+
color: #1e3a8a;
|
| 25 |
+
font-size: 2.5rem;
|
| 26 |
+
font-weight: bold;
|
| 27 |
+
margin-bottom: 2rem;
|
| 28 |
+
text-align: center;
|
| 29 |
+
}
|
| 30 |
+
.upload-section {
|
| 31 |
+
background-color: white;
|
| 32 |
+
padding: 2rem;
|
| 33 |
+
border-radius: 10px;
|
| 34 |
+
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
|
| 35 |
+
}
|
| 36 |
+
.caption-section {
|
| 37 |
+
background-color: white;
|
| 38 |
+
padding: 2rem;
|
| 39 |
+
border-radius: 10px;
|
| 40 |
+
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
|
| 41 |
+
margin-top: 2rem;
|
| 42 |
+
}
|
| 43 |
+
.caption-text {
|
| 44 |
+
font-size: 1.2rem;
|
| 45 |
+
font-style: italic;
|
| 46 |
+
color: #4a5568;
|
| 47 |
+
}
|
| 48 |
+
.stButton>button {
|
| 49 |
+
background-color: #3b82f6;
|
| 50 |
+
color: white;
|
| 51 |
+
font-weight: bold;
|
| 52 |
+
padding: 0.5rem 2rem;
|
| 53 |
+
border-radius: 5px;
|
| 54 |
+
border: none;
|
| 55 |
+
transition: background-color 0.3s ease;
|
| 56 |
+
}
|
| 57 |
+
.stButton>button:hover {
|
| 58 |
+
background-color: #2563eb;
|
| 59 |
+
}
|
| 60 |
+
</style>
|
| 61 |
+
""", unsafe_allow_html=True)
|
| 62 |
+
|
| 63 |
def main():
|
| 64 |
+
set_custom_style()
|
| 65 |
+
|
| 66 |
+
st.markdown('<h1 class="title">Image Captioning App</h1>', unsafe_allow_html=True)
|
| 67 |
|
| 68 |
+
st.markdown('<div class="upload-section">', unsafe_allow_html=True)
|
| 69 |
uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
|
| 70 |
+
st.markdown('</div>', unsafe_allow_html=True)
|
| 71 |
|
| 72 |
if uploaded_file is not None:
|
| 73 |
try:
|
|
|
|
| 78 |
with st.spinner('Generating caption...'):
|
| 79 |
try:
|
| 80 |
caption = generate_caption(image)
|
| 81 |
+
st.markdown('<div class="caption-section">', unsafe_allow_html=True)
|
| 82 |
+
st.markdown("### Generated Caption:")
|
| 83 |
+
st.markdown(f'<p class="caption-text">{caption}</p>', unsafe_allow_html=True)
|
| 84 |
+
st.markdown('</div>', unsafe_allow_html=True)
|
| 85 |
except Exception as e:
|
| 86 |
st.error(f"An error occurred while generating the caption: {str(e)}")
|
| 87 |
st.error("Detailed error traceback:")
|