eagle0504 commited on
Commit
5077d50
·
verified ·
1 Parent(s): 10d3738

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -49
app.py CHANGED
@@ -1,51 +1,30 @@
1
  import streamlit as st
2
- from PIL import Image, ImageDraw
3
- import numpy as np
4
 
5
- # Function to check if a click is within a clickable area
6
- def check_click(click_x, click_y, clickable_areas):
7
- for area in clickable_areas:
8
- x, y, w, h = area["coords"]
9
- if x <= click_x <= x + w and y <= click_y <= y + h:
10
- return area["label"]
11
- return None
12
-
13
- # Function to handle the form
14
- def show_form(area_label):
15
- with st.form(f"form_{area_label}"):
16
- st.text_input(f"Enter text for {area_label}:")
17
- submitted = st.form_submit_button("Submit")
18
- if submitted:
19
- st.write(f"Form for {area_label} submitted!")
20
-
21
- # Load the image
22
- image = Image.open("test.png")
23
-
24
- # Define clickable areas (x, y, width, height)
25
- clickable_areas = [
26
- {"label": "Area 1", "coords": (100, 100, 50, 50)}, # Example coordinates
27
- {"label": "Area 2", "coords": (200, 200, 50, 50)},
28
- {"label": "Area 3", "coords": (300, 300, 50, 50)}
29
- ]
30
-
31
- # Draw * signs on the image to indicate clickable areas
32
- draw = ImageDraw.Draw(image)
33
- for area in clickable_areas:
34
- x, y = area["coords"][:2]
35
- draw.text((x, y), "*", fill="red")
36
-
37
- # Display the image and get mouse click coordinates
38
- st.image(image, caption="Uploaded Image with Clickable Areas", use_container_width=True)
39
-
40
- # Simulate a click using Streamlit's interactive input
41
- click_x = st.number_input("Click X coordinate:", min_value=0, max_value=image.width, value=0)
42
- click_y = st.number_input("Click Y coordinate:", min_value=0, max_value=image.height, value=0)
43
-
44
- # Check if the click is inside any defined area
45
- clicked_area = check_click(click_x, click_y, clickable_areas)
46
-
47
- if clicked_area:
48
- st.write(f"You clicked on: {clicked_area}")
49
- show_form(clicked_area)
50
- else:
51
- st.write("Click on a valid area to trigger an action.")
 
1
  import streamlit as st
 
 
2
 
3
+ if st.button("Click me"):
4
+ st.write("Clicked")
5
+
6
+ st.markdown(
7
+ """
8
+ <style>
9
+ button {
10
+ background: none!important;
11
+ border: none;
12
+ padding: 0!important;
13
+ color: black !important;
14
+ text-decoration: none;
15
+ cursor: pointer;
16
+ border: none !important;
17
+ }
18
+ button:hover {
19
+ text-decoration: none;
20
+ color: black !important;
21
+ }
22
+ button:focus {
23
+ outline: none !important;
24
+ box-shadow: none !important;
25
+ color: black !important;
26
+ }
27
+ </style>
28
+ """,
29
+ unsafe_allow_html=True,
30
+ )