Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -12,6 +12,11 @@ This application predicts the stability/robustness of a robotic grasp based on s
|
|
| 12 |
You can either upload a CSV file with sensor features or input values manually.
|
| 13 |
""")
|
| 14 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
# Load the saved model (make sure the model file 'model.pkl' is in the same directory)
|
| 16 |
@st.cache_resource
|
| 17 |
def load_model():
|
|
@@ -25,7 +30,7 @@ st.sidebar.header("Input Options")
|
|
| 25 |
input_method = st.sidebar.radio("Choose input method:", ("CSV Upload", "Manual Input"))
|
| 26 |
|
| 27 |
# Define the list of features expected by the model.
|
| 28 |
-
#
|
| 29 |
FEATURES = [
|
| 30 |
"H1_F1J2_pos", "H1_F1J2_vel", "H1_F1J2_eff",
|
| 31 |
"H1_F1J3_pos", "H1_F1J3_vel", "H1_F1J3_eff",
|
|
@@ -65,69 +70,139 @@ if input_method == "CSV Upload":
|
|
| 65 |
st.dataframe(input_df)
|
| 66 |
except Exception as e:
|
| 67 |
st.error(f"Error processing file: {e}")
|
|
|
|
| 68 |
# Option 2: Manual Input
|
| 69 |
else:
|
| 70 |
st.header("Manual Input")
|
| 71 |
st.markdown("Enter the sensor values for prediction:")
|
| 72 |
|
| 73 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
input_data = {}
|
| 75 |
|
| 76 |
with st.expander("F1 Joint Sensors"):
|
| 77 |
st.write("Sensors for Finger 1:")
|
| 78 |
-
input_data["H1_F1J2_pos"] = st.number_input("H1_F1J2_pos",
|
| 79 |
-
|
| 80 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 81 |
|
| 82 |
st.write("Sensors for Finger 3:")
|
| 83 |
-
input_data["H1_F1J3_pos"] = st.number_input("H1_F1J3_pos",
|
| 84 |
-
|
| 85 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 86 |
|
| 87 |
st.write("Sensors for Finger 1 (alternate):")
|
| 88 |
-
input_data["H1_F1J1_pos"] = st.number_input("H1_F1J1_pos",
|
| 89 |
-
|
| 90 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 91 |
|
| 92 |
with st.expander("F3 Joint Sensors"):
|
| 93 |
-
input_data["H1_F3J1_pos"] = st.number_input("H1_F3J1_pos",
|
| 94 |
-
|
| 95 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 96 |
|
| 97 |
-
input_data["H1_F3J2_pos"] = st.number_input("H1_F3J2_pos",
|
| 98 |
-
|
| 99 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 100 |
|
| 101 |
-
input_data["H1_F3J3_pos"] = st.number_input("H1_F3J3_pos",
|
| 102 |
-
|
| 103 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 104 |
|
| 105 |
with st.expander("F2 Joint Sensors"):
|
| 106 |
-
input_data["H1_F2J1_pos"] = st.number_input("H1_F2J1_pos",
|
| 107 |
-
|
| 108 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 109 |
|
| 110 |
-
input_data["H1_F2J3_pos"] = st.number_input("H1_F2J3_pos",
|
| 111 |
-
|
| 112 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 113 |
|
| 114 |
-
input_data["H1_F2J2_pos"] = st.number_input("H1_F2J2_pos",
|
| 115 |
-
|
| 116 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 117 |
|
| 118 |
-
#
|
| 119 |
if st.button("Predict"):
|
| 120 |
input_df = pd.DataFrame([input_data])
|
| 121 |
prediction = model.predict(input_df)
|
| 122 |
st.success(f"The predicted grasp robustness is: {prediction[0]:.3f}")
|
| 123 |
|
| 124 |
-
# Create a gauge chart
|
| 125 |
-
#
|
| 126 |
fig_gauge = go.Figure(go.Indicator(
|
| 127 |
mode = "gauge+number",
|
| 128 |
value = prediction[0],
|
| 129 |
title = {'text': "Grasp Robustness"},
|
| 130 |
-
gauge = {'axis': {'range': [
|
| 131 |
'bar': {'color': "darkblue"},
|
| 132 |
'steps' : [
|
| 133 |
{'range': [0, 30], 'color': "red"},
|
|
@@ -137,7 +212,7 @@ else:
|
|
| 137 |
))
|
| 138 |
st.plotly_chart(fig_gauge, use_container_width=True)
|
| 139 |
|
| 140 |
-
# If the model supports feature importances
|
| 141 |
try:
|
| 142 |
feature_importances = model.named_steps['model'].feature_importances_
|
| 143 |
imp_df = pd.DataFrame({
|
|
|
|
| 12 |
You can either upload a CSV file with sensor features or input values manually.
|
| 13 |
""")
|
| 14 |
|
| 15 |
+
# Display robotics images at the top
|
| 16 |
+
# (Ensure that you have internet access for these images, or replace with local image files)
|
| 17 |
+
st.image("https://upload.wikimedia.org/wikipedia/commons/thumb/3/34/Robotic_arm_by_Robust_automation_in_Australia.jpg/640px-Robotic_arm_by_Robust_automation_in_Australia.jpg", caption="Robotic Arm", use_column_width=True)
|
| 18 |
+
st.image("https://upload.wikimedia.org/wikipedia/commons/9/95/Robotic_arm.jpg", caption="Advanced Robotics", use_column_width=True)
|
| 19 |
+
|
| 20 |
# Load the saved model (make sure the model file 'model.pkl' is in the same directory)
|
| 21 |
@st.cache_resource
|
| 22 |
def load_model():
|
|
|
|
| 30 |
input_method = st.sidebar.radio("Choose input method:", ("CSV Upload", "Manual Input"))
|
| 31 |
|
| 32 |
# Define the list of features expected by the model.
|
| 33 |
+
# Update these names to match your dataset after cleaning.
|
| 34 |
FEATURES = [
|
| 35 |
"H1_F1J2_pos", "H1_F1J2_vel", "H1_F1J2_eff",
|
| 36 |
"H1_F1J3_pos", "H1_F1J3_vel", "H1_F1J3_eff",
|
|
|
|
| 70 |
st.dataframe(input_df)
|
| 71 |
except Exception as e:
|
| 72 |
st.error(f"Error processing file: {e}")
|
| 73 |
+
|
| 74 |
# Option 2: Manual Input
|
| 75 |
else:
|
| 76 |
st.header("Manual Input")
|
| 77 |
st.markdown("Enter the sensor values for prediction:")
|
| 78 |
|
| 79 |
+
# Radio button for input type selection inside manual input
|
| 80 |
+
input_type = st.radio("Select input mode:", ("Custom Input", "API Default Values"))
|
| 81 |
+
|
| 82 |
+
# Define default API values (adjust these as needed)
|
| 83 |
+
default_values = {
|
| 84 |
+
"H1_F1J2_pos": 0.5, "H1_F1J2_vel": 0.0, "H1_F1J2_eff": 0.1,
|
| 85 |
+
"H1_F1J3_pos": 0.5, "H1_F1J3_vel": 0.0, "H1_F1J3_eff": 0.1,
|
| 86 |
+
"H1_F1J1_pos": 0.5, "H1_F1J1_vel": 0.0, "H1_F1J1_eff": 0.1,
|
| 87 |
+
"H1_F3J1_pos": 1.0, "H1_F3J1_vel": 0.0, "H1_F3J1_eff": 0.2,
|
| 88 |
+
"H1_F3J2_pos": 1.0, "H1_F3J2_vel": 0.0, "H1_F3J2_eff": 0.2,
|
| 89 |
+
"H1_F3J3_pos": 1.0, "H1_F3J3_vel": 0.0, "H1_F3J3_eff": 0.2,
|
| 90 |
+
"H1_F2J1_pos": 0.7, "H1_F2J1_vel": 0.0, "H1_F2J1_eff": 0.15,
|
| 91 |
+
"H1_F2J3_pos": 0.7, "H1_F2J3_vel": 0.0, "H1_F2J3_eff": 0.15,
|
| 92 |
+
"H1_F2J2_pos": 0.7, "H1_F2J2_vel": 0.0, "H1_F2J2_eff": 0.15,
|
| 93 |
+
}
|
| 94 |
+
|
| 95 |
input_data = {}
|
| 96 |
|
| 97 |
with st.expander("F1 Joint Sensors"):
|
| 98 |
st.write("Sensors for Finger 1:")
|
| 99 |
+
input_data["H1_F1J2_pos"] = st.number_input("H1_F1J2_pos",
|
| 100 |
+
value=default_values["H1_F1J2_pos"] if input_type=="API Default Values" else 0.0,
|
| 101 |
+
format="%.5f")
|
| 102 |
+
input_data["H1_F1J2_vel"] = st.number_input("H1_F1J2_vel",
|
| 103 |
+
value=default_values["H1_F1J2_vel"] if input_type=="API Default Values" else 0.0,
|
| 104 |
+
format="%.5f")
|
| 105 |
+
input_data["H1_F1J2_eff"] = st.number_input("H1_F1J2_eff",
|
| 106 |
+
value=default_values["H1_F1J2_eff"] if input_type=="API Default Values" else 0.0,
|
| 107 |
+
format="%.5f")
|
| 108 |
|
| 109 |
st.write("Sensors for Finger 3:")
|
| 110 |
+
input_data["H1_F1J3_pos"] = st.number_input("H1_F1J3_pos",
|
| 111 |
+
value=default_values["H1_F1J3_pos"] if input_type=="API Default Values" else 0.0,
|
| 112 |
+
format="%.5f")
|
| 113 |
+
input_data["H1_F1J3_vel"] = st.number_input("H1_F1J3_vel",
|
| 114 |
+
value=default_values["H1_F1J3_vel"] if input_type=="API Default Values" else 0.0,
|
| 115 |
+
format="%.5f")
|
| 116 |
+
input_data["H1_F1J3_eff"] = st.number_input("H1_F1J3_eff",
|
| 117 |
+
value=default_values["H1_F1J3_eff"] if input_type=="API Default Values" else 0.0,
|
| 118 |
+
format="%.5f")
|
| 119 |
|
| 120 |
st.write("Sensors for Finger 1 (alternate):")
|
| 121 |
+
input_data["H1_F1J1_pos"] = st.number_input("H1_F1J1_pos",
|
| 122 |
+
value=default_values["H1_F1J1_pos"] if input_type=="API Default Values" else 0.0,
|
| 123 |
+
format="%.5f")
|
| 124 |
+
input_data["H1_F1J1_vel"] = st.number_input("H1_F1J1_vel",
|
| 125 |
+
value=default_values["H1_F1J1_vel"] if input_type=="API Default Values" else 0.0,
|
| 126 |
+
format="%.5f")
|
| 127 |
+
input_data["H1_F1J1_eff"] = st.number_input("H1_F1J1_eff",
|
| 128 |
+
value=default_values["H1_F1J1_eff"] if input_type=="API Default Values" else 0.0,
|
| 129 |
+
format="%.5f")
|
| 130 |
|
| 131 |
with st.expander("F3 Joint Sensors"):
|
| 132 |
+
input_data["H1_F3J1_pos"] = st.number_input("H1_F3J1_pos",
|
| 133 |
+
value=default_values["H1_F3J1_pos"] if input_type=="API Default Values" else 0.0,
|
| 134 |
+
format="%.5f")
|
| 135 |
+
input_data["H1_F3J1_vel"] = st.number_input("H1_F3J1_vel",
|
| 136 |
+
value=default_values["H1_F3J1_vel"] if input_type=="API Default Values" else 0.0,
|
| 137 |
+
format="%.5f")
|
| 138 |
+
input_data["H1_F3J1_eff"] = st.number_input("H1_F3J1_eff",
|
| 139 |
+
value=default_values["H1_F3J1_eff"] if input_type=="API Default Values" else 0.0,
|
| 140 |
+
format="%.5f")
|
| 141 |
|
| 142 |
+
input_data["H1_F3J2_pos"] = st.number_input("H1_F3J2_pos",
|
| 143 |
+
value=default_values["H1_F3J2_pos"] if input_type=="API Default Values" else 0.0,
|
| 144 |
+
format="%.5f")
|
| 145 |
+
input_data["H1_F3J2_vel"] = st.number_input("H1_F3J2_vel",
|
| 146 |
+
value=default_values["H1_F3J2_vel"] if input_type=="API Default Values" else 0.0,
|
| 147 |
+
format="%.5f")
|
| 148 |
+
input_data["H1_F3J2_eff"] = st.number_input("H1_F3J2_eff",
|
| 149 |
+
value=default_values["H1_F3J2_eff"] if input_type=="API Default Values" else 0.0,
|
| 150 |
+
format="%.5f")
|
| 151 |
|
| 152 |
+
input_data["H1_F3J3_pos"] = st.number_input("H1_F3J3_pos",
|
| 153 |
+
value=default_values["H1_F3J3_pos"] if input_type=="API Default Values" else 0.0,
|
| 154 |
+
format="%.5f")
|
| 155 |
+
input_data["H1_F3J3_vel"] = st.number_input("H1_F3J3_vel",
|
| 156 |
+
value=default_values["H1_F3J3_vel"] if input_type=="API Default Values" else 0.0,
|
| 157 |
+
format="%.5f")
|
| 158 |
+
input_data["H1_F3J3_eff"] = st.number_input("H1_F3J3_eff",
|
| 159 |
+
value=default_values["H1_F3J3_eff"] if input_type=="API Default Values" else 0.0,
|
| 160 |
+
format="%.5f")
|
| 161 |
|
| 162 |
with st.expander("F2 Joint Sensors"):
|
| 163 |
+
input_data["H1_F2J1_pos"] = st.number_input("H1_F2J1_pos",
|
| 164 |
+
value=default_values["H1_F2J1_pos"] if input_type=="API Default Values" else 0.0,
|
| 165 |
+
format="%.5f")
|
| 166 |
+
input_data["H1_F2J1_vel"] = st.number_input("H1_F2J1_vel",
|
| 167 |
+
value=default_values["H1_F2J1_vel"] if input_type=="API Default Values" else 0.0,
|
| 168 |
+
format="%.5f")
|
| 169 |
+
input_data["H1_F2J1_eff"] = st.number_input("H1_F2J1_eff",
|
| 170 |
+
value=default_values["H1_F2J1_eff"] if input_type=="API Default Values" else 0.0,
|
| 171 |
+
format="%.5f")
|
| 172 |
|
| 173 |
+
input_data["H1_F2J3_pos"] = st.number_input("H1_F2J3_pos",
|
| 174 |
+
value=default_values["H1_F2J3_pos"] if input_type=="API Default Values" else 0.0,
|
| 175 |
+
format="%.5f")
|
| 176 |
+
input_data["H1_F2J3_vel"] = st.number_input("H1_F2J3_vel",
|
| 177 |
+
value=default_values["H1_F2J3_vel"] if input_type=="API Default Values" else 0.0,
|
| 178 |
+
format="%.5f")
|
| 179 |
+
input_data["H1_F2J3_eff"] = st.number_input("H1_F2J3_eff",
|
| 180 |
+
value=default_values["H1_F2J3_eff"] if input_type=="API Default Values" else 0.0,
|
| 181 |
+
format="%.5f")
|
| 182 |
|
| 183 |
+
input_data["H1_F2J2_pos"] = st.number_input("H1_F2J2_pos",
|
| 184 |
+
value=default_values["H1_F2J2_pos"] if input_type=="API Default Values" else 0.0,
|
| 185 |
+
format="%.5f")
|
| 186 |
+
input_data["H1_F2J2_vel"] = st.number_input("H1_F2J2_vel",
|
| 187 |
+
value=default_values["H1_F2J2_vel"] if input_type=="API Default Values" else 0.0,
|
| 188 |
+
format="%.5f")
|
| 189 |
+
input_data["H1_F2J2_eff"] = st.number_input("H1_F2J2_eff",
|
| 190 |
+
value=default_values["H1_F2J2_eff"] if input_type=="API Default Values" else 0.0,
|
| 191 |
+
format="%.5f")
|
| 192 |
|
| 193 |
+
# When the "Predict" button is pressed, perform prediction
|
| 194 |
if st.button("Predict"):
|
| 195 |
input_df = pd.DataFrame([input_data])
|
| 196 |
prediction = model.predict(input_df)
|
| 197 |
st.success(f"The predicted grasp robustness is: {prediction[0]:.3f}")
|
| 198 |
|
| 199 |
+
# Create a gauge chart using Plotly to visualize the prediction.
|
| 200 |
+
# The axis range [0, 100] is an example; adjust based on your data.
|
| 201 |
fig_gauge = go.Figure(go.Indicator(
|
| 202 |
mode = "gauge+number",
|
| 203 |
value = prediction[0],
|
| 204 |
title = {'text': "Grasp Robustness"},
|
| 205 |
+
gauge = {'axis': {'range': [0, 100]},
|
| 206 |
'bar': {'color': "darkblue"},
|
| 207 |
'steps' : [
|
| 208 |
{'range': [0, 30], 'color': "red"},
|
|
|
|
| 212 |
))
|
| 213 |
st.plotly_chart(fig_gauge, use_container_width=True)
|
| 214 |
|
| 215 |
+
# If the model supports feature importances, display them.
|
| 216 |
try:
|
| 217 |
feature_importances = model.named_steps['model'].feature_importances_
|
| 218 |
imp_df = pd.DataFrame({
|