Spaces:
Sleeping
Sleeping
Commit ·
258cccc
1
Parent(s): 31a42cf
Update - Level
Browse files
app.py
CHANGED
|
@@ -45,9 +45,9 @@ def load_feedback_stats():
|
|
| 45 |
except pd.errors.EmptyDataError:
|
| 46 |
return {}
|
| 47 |
|
| 48 |
-
def save_feedback(action, rating):
|
| 49 |
if not action:
|
| 50 |
-
return "Please select a recommendation from the table first."
|
| 51 |
norm_action = normalize_action(action)
|
| 52 |
new_feedback = pd.DataFrame([{'action': norm_action, 'rating': int(rating)}])
|
| 53 |
if not os.path.exists(FEEDBACK_FILE):
|
|
@@ -55,7 +55,20 @@ def save_feedback(action, rating):
|
|
| 55 |
else:
|
| 56 |
new_feedback.to_csv(FEEDBACK_FILE, mode='a', header=False, index=False)
|
| 57 |
build_feedback_db()
|
| 58 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
|
| 60 |
def build_feedback_db():
|
| 61 |
global feedback_vector_store
|
|
@@ -203,6 +216,14 @@ def fmea_rag_interface(mode, effect, cause, severity, occurrence, detection):
|
|
| 203 |
|
| 204 |
return rpn_text, display_df, output_df
|
| 205 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 206 |
# --- 6. Main Application Execution ---
|
| 207 |
if build_rag_chain():
|
| 208 |
print("\n🚀 Launching Gradio Interface...")
|
|
@@ -217,9 +238,13 @@ if build_rag_chain():
|
|
| 217 |
f_effect = gr.Textbox(label="Effect", placeholder="e.g., Reduced vehicle performance")
|
| 218 |
f_cause = gr.Textbox(label="Cause", placeholder="e.g., Coolant leak")
|
| 219 |
with gr.Column(scale=1):
|
| 220 |
-
f_sev = gr.Slider(1, 10, value=5, step=1, label="Severity")
|
| 221 |
-
f_occ = gr.Slider(1, 10, value=5, step=1, label="Occurrence")
|
| 222 |
-
f_det = gr.Slider(1, 10, value=5, step=1, label="Detection")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 223 |
|
| 224 |
submit_btn = gr.Button("Get AI Recommendations", variant="primary")
|
| 225 |
|
|
@@ -268,8 +293,8 @@ if build_rag_chain():
|
|
| 268 |
|
| 269 |
submit_feedback_btn.click(
|
| 270 |
fn=save_feedback,
|
| 271 |
-
inputs=[selected_action_text, rating_slider],
|
| 272 |
-
outputs=[feedback_status]
|
| 273 |
)
|
| 274 |
|
| 275 |
# Simplified launch command for Hugging Face
|
|
|
|
| 45 |
except pd.errors.EmptyDataError:
|
| 46 |
return {}
|
| 47 |
|
| 48 |
+
def save_feedback(action, rating, display_df):
|
| 49 |
if not action:
|
| 50 |
+
return "Please select a recommendation from the table first.", display_df
|
| 51 |
norm_action = normalize_action(action)
|
| 52 |
new_feedback = pd.DataFrame([{'action': norm_action, 'rating': int(rating)}])
|
| 53 |
if not os.path.exists(FEEDBACK_FILE):
|
|
|
|
| 55 |
else:
|
| 56 |
new_feedback.to_csv(FEEDBACK_FILE, mode='a', header=False, index=False)
|
| 57 |
build_feedback_db()
|
| 58 |
+
|
| 59 |
+
msg = f"✅ Rating of {rating}/10 saved for: {action}"
|
| 60 |
+
|
| 61 |
+
# Update the displayed table dynamically
|
| 62 |
+
if display_df is not None and not display_df.empty:
|
| 63 |
+
try:
|
| 64 |
+
feedback_stats = load_feedback_stats()
|
| 65 |
+
default_stat = {'mean': 0, 'count': 0}
|
| 66 |
+
stats_list = [feedback_stats.get(normalize_action(act), default_stat) for act in display_df['Recommended Action']]
|
| 67 |
+
display_df['Avg. Feedback'] = [f"{stat['mean']:.2f}/10 ({int(stat['count'])})" for stat in stats_list]
|
| 68 |
+
except Exception as e:
|
| 69 |
+
print(f"Error updating display_df: {e}")
|
| 70 |
+
|
| 71 |
+
return msg, display_df
|
| 72 |
|
| 73 |
def build_feedback_db():
|
| 74 |
global feedback_vector_store
|
|
|
|
| 216 |
|
| 217 |
return rpn_text, display_df, output_df
|
| 218 |
|
| 219 |
+
def get_level_info(val):
|
| 220 |
+
levels = {
|
| 221 |
+
10: "Hazardous", 9: "Serious", 8: "Extreme", 7: "Major",
|
| 222 |
+
6: "Significant", 5: "Moderate", 4: "Minor", 3: "Slight",
|
| 223 |
+
2: "Very Slight", 1: "No Effect"
|
| 224 |
+
}
|
| 225 |
+
return gr.update(info=f"Level: {levels.get(val, '')}")
|
| 226 |
+
|
| 227 |
# --- 6. Main Application Execution ---
|
| 228 |
if build_rag_chain():
|
| 229 |
print("\n🚀 Launching Gradio Interface...")
|
|
|
|
| 238 |
f_effect = gr.Textbox(label="Effect", placeholder="e.g., Reduced vehicle performance")
|
| 239 |
f_cause = gr.Textbox(label="Cause", placeholder="e.g., Coolant leak")
|
| 240 |
with gr.Column(scale=1):
|
| 241 |
+
f_sev = gr.Slider(1, 10, value=5, step=1, label="Severity", info="Level: Moderate")
|
| 242 |
+
f_occ = gr.Slider(1, 10, value=5, step=1, label="Occurrence", info="Level: Moderate")
|
| 243 |
+
f_det = gr.Slider(1, 10, value=5, step=1, label="Detection", info="Level: Moderate")
|
| 244 |
+
|
| 245 |
+
f_sev.change(fn=get_level_info, inputs=f_sev, outputs=f_sev)
|
| 246 |
+
f_occ.change(fn=get_level_info, inputs=f_occ, outputs=f_occ)
|
| 247 |
+
f_det.change(fn=get_level_info, inputs=f_det, outputs=f_det)
|
| 248 |
|
| 249 |
submit_btn = gr.Button("Get AI Recommendations", variant="primary")
|
| 250 |
|
|
|
|
| 293 |
|
| 294 |
submit_feedback_btn.click(
|
| 295 |
fn=save_feedback,
|
| 296 |
+
inputs=[selected_action_text, rating_slider, recommendations_output],
|
| 297 |
+
outputs=[feedback_status, recommendations_output]
|
| 298 |
)
|
| 299 |
|
| 300 |
# Simplified launch command for Hugging Face
|