Spaces:
Runtime error
Runtime error
Commit ·
257616f
1
Parent(s): 190fdab
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,12 +4,6 @@ import numpy as np
|
|
| 4 |
from transformers import AutoTokenizer, AutoModelForSequenceClassification, Trainer
|
| 5 |
|
| 6 |
|
| 7 |
-
# load tokenizer and model, create trainer
|
| 8 |
-
model_name = "j-hartmann/emotion-english-distilroberta-base"
|
| 9 |
-
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 10 |
-
model = AutoModelForSequenceClassification.from_pretrained(model_name)
|
| 11 |
-
trainer = Trainer(model=model)
|
| 12 |
-
|
| 13 |
# summary function - test for single gradio function interfrace
|
| 14 |
def bulk_function(filename):
|
| 15 |
# Create class for data preparation
|
|
@@ -32,10 +26,26 @@ def bulk_function(filename):
|
|
| 32 |
print(filename.name)
|
| 33 |
|
| 34 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
# read csv
|
| 36 |
# even if index given, drop it
|
| 37 |
-
df_input = pd.read_csv(filename.name, index_col=False)
|
| 38 |
-
print("df_input", df_input)
|
| 39 |
|
| 40 |
# expect csv format to be in:
|
| 41 |
# 1: ID
|
|
@@ -87,7 +97,7 @@ def bulk_function(filename):
|
|
| 87 |
surprise.append(round(temp[i][6], 2))
|
| 88 |
|
| 89 |
# define df
|
| 90 |
-
df = pd.DataFrame(list(zip(ids,lines_s,labels,scores_rounded, anger, disgust, fear, joy, neutral, sadness, surprise)), columns=[df_input.columns[0],
|
| 91 |
print(df)
|
| 92 |
# save results to csv
|
| 93 |
YOUR_FILENAME = filename.name.split(".")[0] + "_emotion_predictions" + ".csv" # name your output file
|
|
|
|
| 4 |
from transformers import AutoTokenizer, AutoModelForSequenceClassification, Trainer
|
| 5 |
|
| 6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
# summary function - test for single gradio function interfrace
|
| 8 |
def bulk_function(filename):
|
| 9 |
# Create class for data preparation
|
|
|
|
| 26 |
print(filename.name)
|
| 27 |
|
| 28 |
|
| 29 |
+
# check type of input file
|
| 30 |
+
if filename.name.split(".")[1] == "csv":
|
| 31 |
+
print("entered")
|
| 32 |
+
# read file, drop index if exists
|
| 33 |
+
df_input = pd.read_csv(filename.name, index_col=False)
|
| 34 |
+
if df_input.columns[0] == "Unnamed: 0":
|
| 35 |
+
df_input = df_input.drop("Unnamed: 0", axis=1)
|
| 36 |
+
elif filename.name.split(".")[1] == "xlsx":
|
| 37 |
+
df_input = pd.read_excel(filename.name, index_col=False)
|
| 38 |
+
# handle Unnamed
|
| 39 |
+
if df_input.columns[0] == "Unnamed: 0":
|
| 40 |
+
df_input = df_input.drop("Unnamed: 0", axis=1)
|
| 41 |
+
else:
|
| 42 |
+
return
|
| 43 |
+
|
| 44 |
+
|
| 45 |
# read csv
|
| 46 |
# even if index given, drop it
|
| 47 |
+
#df_input = pd.read_csv(filename.name, index_col=False)
|
| 48 |
+
#print("df_input", df_input)
|
| 49 |
|
| 50 |
# expect csv format to be in:
|
| 51 |
# 1: ID
|
|
|
|
| 97 |
surprise.append(round(temp[i][6], 2))
|
| 98 |
|
| 99 |
# define df
|
| 100 |
+
df = pd.DataFrame(list(zip(ids,lines_s,labels,scores_rounded, anger, disgust, fear, joy, neutral, sadness, surprise)), columns=[df_input.columns[0], df_input.columns[1],'label','score', 'anger', 'disgust', 'fear', 'joy', 'neutral', 'sadness', 'surprise'])
|
| 101 |
print(df)
|
| 102 |
# save results to csv
|
| 103 |
YOUR_FILENAME = filename.name.split(".")[0] + "_emotion_predictions" + ".csv" # name your output file
|