Spaces:
Sleeping
Sleeping
explicitly handle the structure of the HuggingFace pipeline output
Browse files
app.py
CHANGED
|
@@ -37,13 +37,19 @@ def predict_emotion(text):
|
|
| 37 |
# Return default DataFrame directly
|
| 38 |
return default_df
|
| 39 |
|
| 40 |
-
# Get predictions and
|
| 41 |
logger.info("Running prediction...")
|
| 42 |
-
predictions = classifier(text)
|
| 43 |
-
df = pd.DataFrame(predictions)
|
| 44 |
-
logger.info(f"Processed scores:\n{df}")
|
| 45 |
|
| 46 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
|
| 48 |
except Exception as e:
|
| 49 |
logger.error(f"Error in prediction: {str(e)}")
|
|
|
|
| 37 |
# Return default DataFrame directly
|
| 38 |
return default_df
|
| 39 |
|
| 40 |
+
# Get predictions and handle result structure
|
| 41 |
logger.info("Running prediction...")
|
| 42 |
+
predictions = classifier(text)
|
|
|
|
|
|
|
| 43 |
|
| 44 |
+
# Ensure predictions are in appropriate list-of-dicts format
|
| 45 |
+
if isinstance(predictions, list) and len(predictions) > 0 and isinstance(predictions[0], dict):
|
| 46 |
+
df = pd.DataFrame(predictions[0]) # Convert list of dicts to DataFrame
|
| 47 |
+
else:
|
| 48 |
+
logger.error(f"Unexpected predictions format: {predictions}")
|
| 49 |
+
return error_df
|
| 50 |
+
|
| 51 |
+
logger.info(f"Processed scores:\n{df}")
|
| 52 |
+
return df
|
| 53 |
|
| 54 |
except Exception as e:
|
| 55 |
logger.error(f"Error in prediction: {str(e)}")
|