Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import pandas as pd
|
3 |
+
from PIL import Image
|
4 |
+
from streamlit_drawable_canvas import st_canvas
|
5 |
+
from helper import load_background_image, display_canvas_data
|
6 |
+
|
7 |
+
# Specify canvas parameters in application
|
8 |
+
drawing_mode = st.sidebar.selectbox(
|
9 |
+
"Drawing tool:", ("point", "freedraw", "line", "rect", "circle", "transform")
|
10 |
+
)
|
11 |
+
|
12 |
+
stroke_width = st.sidebar.slider("Stroke width: ", 1, 25, 3)
|
13 |
+
if drawing_mode == 'point':
|
14 |
+
point_display_radius = st.sidebar.slider("Point display radius: ", 1, 25, 3)
|
15 |
+
stroke_color = st.sidebar.color_picker("Stroke color hex: ")
|
16 |
+
bg_color = st.sidebar.color_picker("Background color hex: ", "#eee")
|
17 |
+
bg_image = st.sidebar.file_uploader("Background image:", type=["png", "jpg"])
|
18 |
+
|
19 |
+
realtime_update = st.sidebar.checkbox("Update in realtime", True)
|
20 |
+
|
21 |
+
# Load background image if provided
|
22 |
+
background_image = load_background_image(bg_image)
|
23 |
+
|
24 |
+
# Create a canvas component
|
25 |
+
canvas_result = st_canvas(
|
26 |
+
fill_color="rgba(255, 165, 0, 0.3)", # Fixed fill color with some opacity
|
27 |
+
stroke_width=stroke_width,
|
28 |
+
stroke_color=stroke_color,
|
29 |
+
background_color=bg_color,
|
30 |
+
background_image=background_image,
|
31 |
+
update_streamlit=realtime_update,
|
32 |
+
height=150,
|
33 |
+
drawing_mode=drawing_mode,
|
34 |
+
point_display_radius=point_display_radius if drawing_mode == 'point' else 0,
|
35 |
+
key="canvas",
|
36 |
+
)
|
37 |
+
|
38 |
+
# Process the canvas data and display it
|
39 |
+
display_canvas_data(canvas_result)
|