douglasgoodwin commited on
Commit
6962b0d
·
verified ·
1 Parent(s): f4adf8a

fix the pass an index

Browse files
Files changed (1) hide show
  1. app.py +6 -5
app.py CHANGED
@@ -22,7 +22,7 @@ classifier = pipeline(
22
  logger.info("Pipeline initialized successfully")
23
 
24
  # Default DataFrame for BarPlot
25
- emotion_labels = [pred['label'] for pred in classifier("test")]
26
  default_scores = [0] * len(emotion_labels)
27
  default_df = pd.DataFrame({'label': emotion_labels, 'score': default_scores})
28
 
@@ -40,10 +40,11 @@ def predict_emotion(text):
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
@@ -69,7 +70,7 @@ demo = gr.Interface(
69
  x="label",
70
  y="score",
71
  title="Emotion Probabilities",
72
- color=["#ff6f61", "#6b5b95", "#88b04b", "#f7cac9", "#92a8d1", "#f7786b"], # Dynamic color
73
  height=400,
74
  vertical=True
75
  ),
 
22
  logger.info("Pipeline initialized successfully")
23
 
24
  # Default DataFrame for BarPlot
25
+ emotion_labels = [pred['label'] for pred in classifier("test input")]
26
  default_scores = [0] * len(emotion_labels)
27
  default_df = pd.DataFrame({'label': emotion_labels, 'score': default_scores})
28
 
 
40
  # Get predictions and handle result structure
41
  logger.info("Running prediction...")
42
  predictions = classifier(text)
43
+ logger.debug(f"Raw predictions output: {predictions}")
44
 
45
+ # Ensure predictions are a list of dictionaries
46
+ if isinstance(predictions, list) and len(predictions) > 0 and all(isinstance(item, dict) for item in predictions):
47
+ df = pd.DataFrame(predictions) # Convert list of dictionaries to DataFrame
48
  else:
49
  logger.error(f"Unexpected predictions format: {predictions}")
50
  return error_df
 
70
  x="label",
71
  y="score",
72
  title="Emotion Probabilities",
73
+ color=["#ff6f61", "#6b5b95", "#88b04b", "#f7cac9", "#92a8d1", "#f7786b"], # Dynamic colors
74
  height=400,
75
  vertical=True
76
  ),