PrakhAI commited on
Commit
e5bec26
·
1 Parent(s): 7c7a530

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -1
app.py CHANGED
@@ -17,4 +17,42 @@ print([(k, type(v)) for (k, v) in state.items()])
17
  # print(logits)
18
 
19
  # x = st.slider('Select a value')
20
- # st.write(x, 'squared is', x * x)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
  # print(logits)
18
 
19
  # x = st.slider('Select a value')
20
+ # st.write(x, 'squared is', x * x)
21
+
22
+ # Specify canvas parameters in application
23
+ drawing_mode = st.sidebar.selectbox(
24
+ "Drawing tool:",
25
+ ("freedraw", "line", "rect", "circle", "transform", "polygon", "point"),
26
+ )
27
+ stroke_width = st.sidebar.slider("Stroke width: ", 1, 25, 3)
28
+ if drawing_mode == "point":
29
+ point_display_radius = st.sidebar.slider("Point display radius: ", 1, 25, 3)
30
+ stroke_color = st.sidebar.color_picker("Stroke color hex: ")
31
+ bg_color = st.sidebar.color_picker("Background color hex: ", "#eee")
32
+ bg_image = st.sidebar.file_uploader("Background image:", type=["png", "jpg"])
33
+ realtime_update = st.sidebar.checkbox("Update in realtime", True)
34
+
35
+ # Create a canvas component
36
+ canvas_result = st_canvas(
37
+ fill_color="rgba(255, 165, 0, 0.3)", # Fixed fill color with some opacity
38
+ stroke_width=stroke_width,
39
+ stroke_color=stroke_color,
40
+ background_color=bg_color,
41
+ background_image=Image.open(bg_image) if bg_image else None,
42
+ update_streamlit=realtime_update,
43
+ height=150,
44
+ drawing_mode=drawing_mode,
45
+ point_display_radius=point_display_radius if drawing_mode == "point" else 0,
46
+ display_toolbar=st.sidebar.checkbox("Display toolbar", True),
47
+ key="full_app",
48
+ )
49
+
50
+ # Do something interesting with the image data and paths
51
+ if canvas_result.image_data is not None:
52
+ st.image(canvas_result.image_data)
53
+ if canvas_result.json_data is not None:
54
+ objects = pd.json_normalize(canvas_result.json_data["objects"])
55
+ for col in objects.select_dtypes(include=["object"]).columns:
56
+ objects[col] = objects[col].astype("str")
57
+ st.dataframe(objects)
58
+