Daviiin commited on
Commit
ce97a5f
ยท
verified ยท
1 Parent(s): 2792b85

feat: desenvolve app em streamlit

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +68 -38
src/streamlit_app.py CHANGED
@@ -1,40 +1,70 @@
1
- import altair as alt
2
- import numpy as np
3
- import pandas as pd
4
  import streamlit as st
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
 
6
- """
7
- # Welcome to Streamlit!
8
-
9
- Edit `/streamlit_app.py` to customize this app to your heart's desire :heart:.
10
- If you have any questions, checkout our [documentation](https://docs.streamlit.io) and [community
11
- forums](https://discuss.streamlit.io).
12
-
13
- In the meantime, below is an example of what you can do with just a few lines of code:
14
- """
15
-
16
- num_points = st.slider("Number of points in spiral", 1, 10000, 1100)
17
- num_turns = st.slider("Number of turns in spiral", 1, 300, 31)
18
-
19
- indices = np.linspace(0, 1, num_points)
20
- theta = 2 * np.pi * num_turns * indices
21
- radius = indices
22
-
23
- x = radius * np.cos(theta)
24
- y = radius * np.sin(theta)
25
-
26
- df = pd.DataFrame({
27
- "x": x,
28
- "y": y,
29
- "idx": indices,
30
- "rand": np.random.randn(num_points),
31
- })
32
-
33
- st.altair_chart(alt.Chart(df, height=700, width=700)
34
- .mark_point(filled=True)
35
- .encode(
36
- x=alt.X("x", axis=None),
37
- y=alt.Y("y", axis=None),
38
- color=alt.Color("idx", legend=None, scale=alt.Scale()),
39
- size=alt.Size("rand", legend=None, scale=alt.Scale(range=[1, 150])),
40
- ))
 
1
+
 
 
2
  import streamlit as st
3
+ import json
4
+ import pandas as pd
5
+ import numpy as np
6
+
7
+ st.set_page_config(page_title="PetSet", layout="centered")
8
+
9
+ st.markdown("<h1 style='text-align: center;'>๐Ÿพ PetSet โ€“ Your Dataset Pet</h1>", unsafe_allow_html=True)
10
+ st.markdown("<p style='text-align: center; font-size: 18px;'>Upload a LeRobot .json dataset and start caring for your pet!</p>", unsafe_allow_html=True)
11
+
12
+ uploaded_file = st.file_uploader("๐Ÿ“‚ Upload your LeRobotDataset (.json)", type=["json"])
13
+
14
+ if uploaded_file:
15
+ data = json.load(uploaded_file)
16
+ episodes = data.get("episodes", [])
17
+
18
+ if not episodes:
19
+ st.error("No episodes found in this file.")
20
+ else:
21
+ df = pd.DataFrame(episodes)
22
+ st.success(f"{len(episodes)} episodes loaded successfully!")
23
+
24
+ # Calcular atributos do pet
25
+ success_rate = df["success"].mean()
26
+ duration_std = df["duration"].std()
27
+ health = 100 - df['success'].value_counts().get(False, 0) * 10
28
+ energy = success_rate * 100
29
+ attention = max(0, 100 - duration_std * 10)
30
+
31
+ col1, col2, col3 = st.columns(3)
32
+ with col1:
33
+ st.metric("โค๏ธ Health", f"{int(health)}%")
34
+ with col2:
35
+ st.metric("โšก Energy", f"{int(energy)}%")
36
+ with col3:
37
+ st.metric("๐Ÿง  Attention", f"{int(attention)}%")
38
+
39
+ st.markdown("---")
40
+ st.image("https://media.giphy.com/media/v1.Y2lkPTc5MGI3NjExZ2EyZWkyd2ZzMmFmd3FuNm1jY2Fjdm42a2p6dDh4cGc1dzNsb25uMSZlcD12MV9naWZzX3NlYXJjaCZjdD1n/VbnUQpnihPSIgIXuZv/giphy.gif", width=200, caption="Your Pet")
41
+
42
+ st.markdown("### ๐Ÿ›  What would you like to do?")
43
+ col_a, col_b, col_c = st.columns(3)
44
+ with col_a:
45
+ feed = st.button("๐ŸŽ Feed Data")
46
+ with col_b:
47
+ heal = st.button("๐Ÿฉบ Heal Pet")
48
+ with col_c:
49
+ check = st.button("๐Ÿงช Check Quality")
50
+
51
+ if heal:
52
+ original_len = len(data["episodes"])
53
+ data["episodes"] = [ep for ep in episodes if ep.get("success", True)]
54
+ removed = original_len - len(data["episodes"])
55
+ st.success(f"Removed {removed} failed episodes.")
56
+
57
+ if check:
58
+ problems = df['success'].value_counts().get(False, 0)
59
+ st.markdown(f"<div style='padding: 15px; background-color: #fff3cd; border-radius: 10px;'><strong>โš ๏ธ Found {problems} corrupted episodes!</strong></div>", unsafe_allow_html=True)
60
+
61
+ st.markdown("### ๐Ÿ“ฆ Dataset Preview")
62
+ st.dataframe(df[["id", "success", "duration", "avg_accel"]])
63
+
64
+ st.markdown("---")
65
+ if st.button("๐Ÿ’พ Download Cleaned Dataset"):
66
+ cleaned_json = json.dumps(data, indent=2)
67
+ st.download_button("Download JSON", cleaned_json, file_name="cleaned_dataset.json")
68
 
69
+ else:
70
+ st.info("๐Ÿ‘† Upload a dataset file to begin.")