Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -37,7 +37,7 @@ def predict_fault(uploaded_csv):
|
|
37 |
if missing_cols:
|
38 |
return f"Missing required columns: {', '.join(missing_cols)}", None
|
39 |
|
40 |
-
#
|
41 |
X = df[required_columns]
|
42 |
X_scaled = scaler.transform(X)
|
43 |
|
@@ -45,13 +45,19 @@ def predict_fault(uploaded_csv):
|
|
45 |
predictions = model.predict(X_scaled)
|
46 |
predicted_faults = np.argmax(predictions, axis=1)
|
47 |
|
48 |
-
#
|
49 |
df['Predicted Fault Type'] = predicted_faults
|
50 |
df = df.merge(fault_table, left_on='Predicted Fault Type', right_on='Fault Type', how='left')
|
51 |
|
52 |
-
#
|
53 |
-
fig, ax = plt.subplots(
|
54 |
-
df[
|
|
|
|
|
|
|
|
|
|
|
|
|
55 |
plt.tight_layout()
|
56 |
|
57 |
return df[['Predicted Fault Type', 'Fault Name', 'Conditions']].head(10), fig
|
|
|
37 |
if missing_cols:
|
38 |
return f"Missing required columns: {', '.join(missing_cols)}", None
|
39 |
|
40 |
+
# Scale input
|
41 |
X = df[required_columns]
|
42 |
X_scaled = scaler.transform(X)
|
43 |
|
|
|
45 |
predictions = model.predict(X_scaled)
|
46 |
predicted_faults = np.argmax(predictions, axis=1)
|
47 |
|
48 |
+
# Merge fault descriptions
|
49 |
df['Predicted Fault Type'] = predicted_faults
|
50 |
df = df.merge(fault_table, left_on='Predicted Fault Type', right_on='Fault Type', how='left')
|
51 |
|
52 |
+
# Plot bar chart of fault type counts
|
53 |
+
fig, ax = plt.subplots()
|
54 |
+
fault_counts = df['Predicted Fault Type'].value_counts().sort_index()
|
55 |
+
fault_counts.plot(kind='bar', ax=ax)
|
56 |
+
ax.set_title("Predicted Fault Type Counts")
|
57 |
+
ax.set_xlabel("Fault Type")
|
58 |
+
ax.set_ylabel("Count")
|
59 |
+
ax.set_xticks(range(4))
|
60 |
+
ax.set_xticklabels(["No Fault", "Rich", "Lean", "Low Volt"], rotation=0)
|
61 |
plt.tight_layout()
|
62 |
|
63 |
return df[['Predicted Fault Type', 'Fault Name', 'Conditions']].head(10), fig
|