PrakhAI's picture
Update app.py
e5bec26
raw
history blame
2.11 kB
import streamlit as st
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)
stroke_color = st.sidebar.color_picker("Stroke color hex: ")
bg_color = st.sidebar.color_picker("Background color hex: ", "#eee")
bg_image = st.sidebar.file_uploader("Background image:", type=["png", "jpg"])
realtime_update = st.sidebar.checkbox("Update in realtime", True)
# Create a canvas component
canvas_result = st_canvas(
fill_color="rgba(255, 165, 0, 0.3)", # Fixed fill color with some opacity
stroke_width=stroke_width,
stroke_color=stroke_color,
background_color=bg_color,
background_image=Image.open(bg_image) if bg_image else 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)
if canvas_result.json_data is not None:
objects = pd.json_normalize(canvas_result.json_data["objects"])
for col in objects.select_dtypes(include=["object"]).columns:
objects[col] = objects[col].astype("str")
st.dataframe(objects)