Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -39,11 +39,26 @@ feature_options = {
|
|
| 39 |
|
| 40 |
def predict_mushroom(*features):
|
| 41 |
# Convert the feature names to a dictionary based on the order
|
| 42 |
-
feature_names = list(
|
| 43 |
-
numerical_features = {
|
| 44 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
input_df = pd.DataFrame([numerical_features])
|
| 46 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
return 'Poisonous' if prediction[0] == 1 else 'Edible'
|
| 48 |
|
| 49 |
demo = gr.Interface(
|
|
|
|
| 39 |
|
| 40 |
def predict_mushroom(*features):
|
| 41 |
# Convert the feature names to a dictionary based on the order
|
| 42 |
+
feature_names = list(mappings.keys())
|
| 43 |
+
numerical_features = {}
|
| 44 |
+
|
| 45 |
+
# Convert the string values to numerical values using the mappings
|
| 46 |
+
for i, feature in enumerate(features):
|
| 47 |
+
if feature in mappings[feature_names[i]]:
|
| 48 |
+
numerical_features[feature_names[i]] = mappings[feature_names[i]][feature]
|
| 49 |
+
else:
|
| 50 |
+
raise ValueError(f"Invalid value for feature '{feature_names[i]}': {feature}")
|
| 51 |
+
|
| 52 |
+
# Convert the numerical features into a DataFrame for the model
|
| 53 |
input_df = pd.DataFrame([numerical_features])
|
| 54 |
+
|
| 55 |
+
# Ensure the data is in the right format
|
| 56 |
+
try:
|
| 57 |
+
prediction = model.predict(input_df)
|
| 58 |
+
except Exception as e:
|
| 59 |
+
raise ValueError(f"Error during prediction: {e}")
|
| 60 |
+
|
| 61 |
+
# Return the classification result based on the model output
|
| 62 |
return 'Poisonous' if prediction[0] == 1 else 'Edible'
|
| 63 |
|
| 64 |
demo = gr.Interface(
|