Update app.py
Browse files
app.py
CHANGED
@@ -1,94 +1,104 @@
|
|
1 |
import streamlit as st
|
2 |
from PIL import Image
|
3 |
|
4 |
-
# Custom CSS
|
5 |
st.markdown("""
|
6 |
<style>
|
7 |
-
|
8 |
-
background-color: #
|
9 |
-
|
10 |
-
border-radius: 10px;
|
11 |
-
box-shadow: 2px 2px 10px rgba(0, 0, 0, 0.1);
|
12 |
-
}
|
13 |
-
.sidebar .sidebar-content {
|
14 |
-
background-color: #2c3e50;
|
15 |
-
color: white;
|
16 |
}
|
17 |
-
.
|
18 |
-
color: #
|
|
|
|
|
|
|
19 |
}
|
20 |
.title {
|
21 |
-
color: #
|
22 |
-
font-
|
23 |
-
font-weight:
|
24 |
-
font-size: 36px;
|
25 |
text-align: center;
|
26 |
-
margin-bottom:
|
27 |
}
|
28 |
-
.upload-
|
29 |
-
background-color: #
|
30 |
-
|
31 |
-
border-radius:
|
32 |
-
|
33 |
text-align: center;
|
34 |
-
|
|
|
|
|
|
|
35 |
}
|
36 |
-
.
|
37 |
-
background-color: #
|
38 |
color: white;
|
39 |
border-radius: 5px;
|
40 |
padding: 10px;
|
41 |
font-weight: bold;
|
42 |
-
text-align: center;
|
43 |
cursor: pointer;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
}
|
45 |
</style>
|
46 |
""", unsafe_allow_html=True)
|
47 |
|
48 |
-
# Main UI
|
49 |
st.markdown('<div class="main">', unsafe_allow_html=True)
|
50 |
st.markdown('<div class="title">Florence-2 Image Captioning Demo</div>', unsafe_allow_html=True)
|
51 |
|
52 |
-
#
|
53 |
-
st.sidebar.markdown("## Model Configuration")
|
54 |
-
model_option = st.sidebar.selectbox(
|
55 |
-
"Select Model",
|
56 |
-
("microsoft/Florence-2-large-ft", "microsoft/Florence-2-large", "microsoft/Florence-2-base-ft", "microsoft/Florence-2-base")
|
57 |
-
)
|
58 |
-
|
59 |
-
# Task prompt selection
|
60 |
task_prompt = st.text_input("Task Prompt", value="Describe the image in detail:")
|
61 |
|
62 |
-
#
|
63 |
-
|
|
|
|
|
64 |
|
65 |
-
#
|
66 |
-
|
67 |
|
68 |
-
#
|
69 |
if uploaded_image is not None:
|
70 |
image = Image.open(uploaded_image)
|
71 |
st.image(image, caption="Uploaded Image", use_column_width=True)
|
72 |
-
|
73 |
-
#
|
74 |
-
st.
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
#
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
# Display bounding boxes if available
|
86 |
if "bboxes" in result:
|
87 |
st.markdown("### Detected Objects")
|
88 |
fig = plot_bbox(image, result)
|
89 |
st.pyplot(fig)
|
90 |
-
|
91 |
-
# Display polygons if available
|
92 |
if "polygons" in result:
|
93 |
st.markdown("### Image with Polygons")
|
94 |
processed_image = draw_polygons(image.copy(), result)
|
|
|
1 |
import streamlit as st
|
2 |
from PIL import Image
|
3 |
|
4 |
+
# Custom CSS for enhanced styling
|
5 |
st.markdown("""
|
6 |
<style>
|
7 |
+
body {
|
8 |
+
background-color: #f7f9fc;
|
9 |
+
font-family: 'Arial', sans-serif;
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
}
|
11 |
+
.main {
|
12 |
+
background-color: #ffffff;
|
13 |
+
padding: 30px;
|
14 |
+
border-radius: 15px;
|
15 |
+
box-shadow: 0px 0px 15px rgba(0, 0, 0, 0.1);
|
16 |
}
|
17 |
.title {
|
18 |
+
color: #2c3e50;
|
19 |
+
font-size: 40px;
|
20 |
+
font-weight: 700;
|
|
|
21 |
text-align: center;
|
22 |
+
margin-bottom: 40px;
|
23 |
}
|
24 |
+
.upload-area {
|
25 |
+
background-color: #e8f4f8;
|
26 |
+
padding: 20px;
|
27 |
+
border-radius: 10px;
|
28 |
+
border: 2px dashed #1abc9c;
|
29 |
text-align: center;
|
30 |
+
margin-bottom: 20px;
|
31 |
+
}
|
32 |
+
.upload-area:hover {
|
33 |
+
background-color: #d1ecf1;
|
34 |
}
|
35 |
+
.generate-button {
|
36 |
+
background-color: #1abc9c;
|
37 |
color: white;
|
38 |
border-radius: 5px;
|
39 |
padding: 10px;
|
40 |
font-weight: bold;
|
|
|
41 |
cursor: pointer;
|
42 |
+
text-align: center;
|
43 |
+
margin-top: 20px;
|
44 |
+
}
|
45 |
+
.generate-button:hover {
|
46 |
+
background-color: #16a085;
|
47 |
+
}
|
48 |
+
.result-section {
|
49 |
+
margin-top: 40px;
|
50 |
+
}
|
51 |
+
.result-title {
|
52 |
+
color: #34495e;
|
53 |
+
font-size: 24px;
|
54 |
+
font-weight: 600;
|
55 |
+
margin-bottom: 20px;
|
56 |
+
}
|
57 |
+
.success {
|
58 |
+
background-color: #dff0d8;
|
59 |
+
color: #3c763d;
|
60 |
+
padding: 15px;
|
61 |
+
border-radius: 5px;
|
62 |
}
|
63 |
</style>
|
64 |
""", unsafe_allow_html=True)
|
65 |
|
66 |
+
# Main UI container
|
67 |
st.markdown('<div class="main">', unsafe_allow_html=True)
|
68 |
st.markdown('<div class="title">Florence-2 Image Captioning Demo</div>', unsafe_allow_html=True)
|
69 |
|
70 |
+
# Task prompt input
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
71 |
task_prompt = st.text_input("Task Prompt", value="Describe the image in detail:")
|
72 |
|
73 |
+
# Image upload area
|
74 |
+
st.markdown('<div class="upload-area">', unsafe_allow_html=True)
|
75 |
+
uploaded_image = st.file_uploader("Upload your image here", type=["jpg", "jpeg", "png"])
|
76 |
+
st.markdown('</div>', unsafe_allow_html=True)
|
77 |
|
78 |
+
# Additional text input (optional)
|
79 |
+
text_input = st.text_area("Additional Text Input (Optional)", height=150)
|
80 |
|
81 |
+
# Display the uploaded image and process it if available
|
82 |
if uploaded_image is not None:
|
83 |
image = Image.open(uploaded_image)
|
84 |
st.image(image, caption="Uploaded Image", use_column_width=True)
|
85 |
+
|
86 |
+
# Generate Caption button
|
87 |
+
if st.button("Generate Caption", key="generate"):
|
88 |
+
# Assuming `run_example` function is defined
|
89 |
+
result = run_example(task_prompt, image, text_input)
|
90 |
+
|
91 |
+
# Display the generated caption
|
92 |
+
st.markdown('<div class="result-section">', unsafe_allow_html=True)
|
93 |
+
st.markdown('<div class="result-title">Generated Caption</div>', unsafe_allow_html=True)
|
94 |
+
st.markdown(f'<div class="success">{result["text"]}</div>', unsafe_allow_html=True)
|
95 |
+
|
96 |
+
# Display bounding boxes or polygons if available
|
|
|
|
|
97 |
if "bboxes" in result:
|
98 |
st.markdown("### Detected Objects")
|
99 |
fig = plot_bbox(image, result)
|
100 |
st.pyplot(fig)
|
101 |
+
|
|
|
102 |
if "polygons" in result:
|
103 |
st.markdown("### Image with Polygons")
|
104 |
processed_image = draw_polygons(image.copy(), result)
|