Spaces:
Sleeping
Sleeping
| import streamlit as st | |
| from streamlit_drawable_canvas import st_canvas | |
| from huggingface_hub import HfFileSystem | |
| from flax.serialization import msgpack_restore, from_state_dict | |
| fs = HfFileSystem() | |
| with fs.open("PrakhAI/HelloWorld/checkpoint.msgpack", "rb") as f: | |
| state = msgpack_restore(f.read()) | |
| print(type(state)) | |
| print(state) | |
| print([(k, type(v)) for (k, v) in state.items()]) | |
| # print(state['params']) | |
| # print(state['opt_state']) | |
| # logits = state.apply_fn({'params': state.params}, batch['image']) | |
| # print(logits) | |
| # x = st.slider('Select a value') | |
| # st.write(x, 'squared is', x * x) | |
| # Specify canvas parameters in application | |
| drawing_mode = st.sidebar.selectbox( | |
| "Drawing tool:", | |
| ("freedraw", "line", "rect", "circle", "transform", "polygon", "point"), | |
| ) | |
| stroke_width = st.sidebar.slider("Stroke width: ", 1, 25, 3) | |
| if drawing_mode == "point": | |
| point_display_radius = st.sidebar.slider("Point display radius: ", 1, 25, 3) | |
| realtime_update = st.sidebar.checkbox("Update in realtime", True) | |
| # Create a canvas component | |
| canvas_result = st_canvas( | |
| fill_color="rgba(0, 0, 0, 0)", # Fixed fill color with some opacity | |
| stroke_width=stroke_width, | |
| stroke_color="rgba(255, 255, 255, 0)", | |
| background_color="rgba(0, 0, 0, 0)", | |
| background_image=None, | |
| update_streamlit=realtime_update, | |
| height=150, | |
| drawing_mode=drawing_mode, | |
| point_display_radius=point_display_radius if drawing_mode == "point" else 0, | |
| display_toolbar=st.sidebar.checkbox("Display toolbar", True), | |
| key="full_app", | |
| ) | |
| # Do something interesting with the image data and paths | |
| if canvas_result.image_data is not None: | |
| st.image(canvas_result.image_data) | |