Spaces:
Sleeping
Sleeping
use a dataframe
Browse files
app.py
CHANGED
|
@@ -3,6 +3,7 @@ import gradio as gr
|
|
| 3 |
from transformers import pipeline
|
| 4 |
import logging
|
| 5 |
import sys
|
|
|
|
| 6 |
|
| 7 |
# Set up logging
|
| 8 |
logging.basicConfig(level=logging.INFO, stream=sys.stdout,
|
|
@@ -41,14 +42,14 @@ def predict_emotion(text):
|
|
| 41 |
predictions = classifier(text)[0]
|
| 42 |
logger.info(f"Raw predictions: {predictions}")
|
| 43 |
|
| 44 |
-
# Convert predictions to
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
logger.info(f"Processed scores: {
|
| 48 |
|
| 49 |
return (
|
| 50 |
-
[
|
| 51 |
-
[score
|
| 52 |
)
|
| 53 |
|
| 54 |
except Exception as e:
|
|
|
|
| 3 |
from transformers import pipeline
|
| 4 |
import logging
|
| 5 |
import sys
|
| 6 |
+
import pandas as pd
|
| 7 |
|
| 8 |
# Set up logging
|
| 9 |
logging.basicConfig(level=logging.INFO, stream=sys.stdout,
|
|
|
|
| 42 |
predictions = classifier(text)[0]
|
| 43 |
logger.info(f"Raw predictions: {predictions}")
|
| 44 |
|
| 45 |
+
# Convert predictions to a pandas DataFrame for Gradio's BarPlot
|
| 46 |
+
df = pd.DataFrame(predictions)
|
| 47 |
+
df = df.sort_values('score', ascending=True) # Sort for better visualization
|
| 48 |
+
logger.info(f"Processed scores as DataFrame: {df.to_dict()}")
|
| 49 |
|
| 50 |
return (
|
| 51 |
+
df['label'].tolist(), # x values (emotions)
|
| 52 |
+
df['score'].tolist() # y values (probabilities)
|
| 53 |
)
|
| 54 |
|
| 55 |
except Exception as e:
|