Update app.py
Browse files
app.py
CHANGED
@@ -1,43 +1,48 @@
|
|
1 |
import streamlit as st
|
|
|
|
|
|
|
|
|
2 |
|
3 |
# Load the image
|
4 |
image_path = "test.png"
|
5 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
|
7 |
-
#
|
8 |
-
st.
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
display: block;
|
17 |
-
}}
|
18 |
-
.button {{
|
19 |
-
position: absolute;
|
20 |
-
top: 50%; /* Adjust to place the button */
|
21 |
-
left: 50%; /* Adjust to place the button */
|
22 |
-
transform: translate(-50%, -50%);
|
23 |
-
background: none!important;
|
24 |
-
border: none;
|
25 |
-
color: black;
|
26 |
-
text-decoration: none;
|
27 |
-
cursor: pointer;
|
28 |
-
font-size: 20px;
|
29 |
-
padding: 10px 20px;
|
30 |
-
}}
|
31 |
-
.button:hover {{
|
32 |
-
text-decoration: none;
|
33 |
-
color: black;
|
34 |
-
background: rgba(255, 255, 255, 0.5);
|
35 |
-
}}
|
36 |
-
</style>
|
37 |
-
<div class="image-container">
|
38 |
-
<img class="image" src="{image_url}" alt="Image with clickable button">
|
39 |
-
<button class="button" onclick="window.alert('Button clicked!');">Click Me</button>
|
40 |
-
</div>
|
41 |
-
""",
|
42 |
-
unsafe_allow_html=True,
|
43 |
-
)
|
|
|
1 |
import streamlit as st
|
2 |
+
from PIL import Image
|
3 |
+
|
4 |
+
# Title of the Streamlit App
|
5 |
+
st.title("Interactive Image App")
|
6 |
|
7 |
# Load the image
|
8 |
image_path = "test.png"
|
9 |
+
image = Image.open(image_path)
|
10 |
+
|
11 |
+
# Display the image
|
12 |
+
st.image(image, caption="Interactive Image", use_column_width=True)
|
13 |
+
|
14 |
+
# Create a clickable area
|
15 |
+
st.markdown("""
|
16 |
+
<style>
|
17 |
+
.clickable {
|
18 |
+
position: absolute;
|
19 |
+
top: 20%; /* Adjust position to where text should appear on the image */
|
20 |
+
left: 50%; /* Adjust position to where text should appear on the image */
|
21 |
+
transform: translate(-50%, -50%);
|
22 |
+
color: white;
|
23 |
+
font-size: 24px;
|
24 |
+
font-weight: bold;
|
25 |
+
background: rgba(0, 0, 0, 0.5);
|
26 |
+
padding: 10px 20px;
|
27 |
+
border-radius: 5px;
|
28 |
+
cursor: pointer;
|
29 |
+
z-index: 2;
|
30 |
+
}
|
31 |
+
</style>
|
32 |
+
<div class="clickable" onClick="window.open('#form', '_self')">
|
33 |
+
Click me
|
34 |
+
</div>
|
35 |
+
""", unsafe_allow_html=True)
|
36 |
+
|
37 |
+
# Anchor for form
|
38 |
+
st.markdown('<a name="form"></a>', unsafe_allow_html=True)
|
39 |
|
40 |
+
# If clicked, show a form
|
41 |
+
if st.button("Click me"):
|
42 |
+
with st.form("form", clear_on_submit=True):
|
43 |
+
st.write("Fill out this form:")
|
44 |
+
name = st.text_input("Name")
|
45 |
+
email = st.text_input("Email")
|
46 |
+
submitted = st.form_submit_button("Submit")
|
47 |
+
if submitted:
|
48 |
+
st.success(f"Form submitted! Name: {name}, Email: {email}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|