Spaces:
Build error
Build error
new approach ,new lib
Browse files
app.py
CHANGED
@@ -1,38 +1,43 @@
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
-
from
|
3 |
|
4 |
-
#
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
draw.line(drawing["points"], fill="black", width=2)
|
16 |
|
17 |
-
|
18 |
-
def main():
|
19 |
-
st.title("Canvas Drawing Tool")
|
20 |
-
st.sidebar.title("Options")
|
21 |
|
22 |
-
|
23 |
-
draw_on_canvas()
|
24 |
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
29 |
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
main()
|
|
|
1 |
+
import pandas as pd
|
2 |
+
from PIL import Image
|
3 |
import streamlit as st
|
4 |
+
from streamlit_drawable_canvas import st_canvas
|
5 |
|
6 |
+
# Specify canvas parameters in application
|
7 |
+
drawing_mode = st.sidebar.selectbox(
|
8 |
+
"Drawing tool:", ("point", "freedraw", "line", "rect", "circle", "transform")
|
9 |
+
)
|
10 |
|
11 |
+
stroke_width = st.sidebar.slider("Stroke width: ", 1, 25, 3)
|
12 |
+
if drawing_mode == 'point':
|
13 |
+
point_display_radius = st.sidebar.slider("Point display radius: ", 1, 25, 3)
|
14 |
+
stroke_color = st.sidebar.color_picker("Stroke color hex: ")
|
15 |
+
bg_color = st.sidebar.color_picker("Background color hex: ", "#eee")
|
16 |
+
bg_image = st.sidebar.file_uploader("Background image:", type=["png", "jpg"])
|
|
|
17 |
|
18 |
+
realtime_update = st.sidebar.checkbox("Update in realtime", True)
|
|
|
|
|
|
|
19 |
|
20 |
+
|
|
|
21 |
|
22 |
+
# Create a canvas component
|
23 |
+
canvas_result = st_canvas(
|
24 |
+
fill_color="rgba(255, 165, 0, 0.3)", # Fixed fill color with some opacity
|
25 |
+
stroke_width=stroke_width,
|
26 |
+
stroke_color=stroke_color,
|
27 |
+
background_color=bg_color,
|
28 |
+
background_image=Image.open(bg_image) if bg_image else None,
|
29 |
+
update_streamlit=realtime_update,
|
30 |
+
height=150,
|
31 |
+
drawing_mode=drawing_mode,
|
32 |
+
point_display_radius=point_display_radius if drawing_mode == 'point' else 0,
|
33 |
+
key="canvas",
|
34 |
+
)
|
35 |
|
36 |
+
# Do something interesting with the image data and paths
|
37 |
+
if canvas_result.image_data is not None:
|
38 |
+
st.image(canvas_result.image_data)
|
39 |
+
if canvas_result.json_data is not None:
|
40 |
+
objects = pd.json_normalize(canvas_result.json_data["objects"]) # need to convert obj to str because PyArrow
|
41 |
+
for col in objects.select_dtypes(include=['object']).columns:
|
42 |
+
objects[col] = objects[col].astype("str")
|
43 |
+
st.dataframe(objects)
|
|