Spaces:
Runtime error
Runtime error
Commit
·
294751b
1
Parent(s):
39d01a8
Update app.py
Browse files
app.py
CHANGED
@@ -2,7 +2,7 @@ import gradio as gr
|
|
2 |
import pandas as pd
|
3 |
import numpy as np
|
4 |
from transformers import AutoTokenizer, AutoModelForSequenceClassification, Trainer
|
5 |
-
# summary function - test for single gradio function
|
6 |
def bulk_function(filename):
|
7 |
# Create class for data preparation
|
8 |
class SimpleDataset:
|
@@ -22,15 +22,13 @@ def bulk_function(filename):
|
|
22 |
trainer = Trainer(model=model)
|
23 |
|
24 |
# read file lines
|
25 |
-
with open(
|
26 |
lines = f.readlines()
|
27 |
# expects unnamed:0 or index, col name -> strip both
|
28 |
-
lines_s = [item.split("\n")[0].split(",")[-1] for item in lines]
|
29 |
-
print(lines_s[1:])
|
30 |
-
|
31 |
|
32 |
# Tokenize texts and create prediction data set
|
33 |
-
tokenized_texts = tokenizer(lines_s
|
34 |
pred_dataset = SimpleDataset(tokenized_texts)
|
35 |
|
36 |
# Run predictions
|
@@ -54,7 +52,7 @@ def bulk_function(filename):
|
|
54 |
surprise = []
|
55 |
|
56 |
# extract scores (as many entries as exist in pred_texts)
|
57 |
-
for i in range(len(lines_s
|
58 |
anger.append(temp[i][0])
|
59 |
disgust.append(temp[i][1])
|
60 |
fear.append(temp[i][2])
|
@@ -64,7 +62,7 @@ def bulk_function(filename):
|
|
64 |
surprise.append(temp[i][6])
|
65 |
|
66 |
# define df
|
67 |
-
df = pd.DataFrame(list(zip(lines_s
|
68 |
|
69 |
# save results to csv
|
70 |
YOUR_FILENAME = "YOUR_FILENAME_EMOTIONS_gradio.csv" # name your output file
|
|
|
2 |
import pandas as pd
|
3 |
import numpy as np
|
4 |
from transformers import AutoTokenizer, AutoModelForSequenceClassification, Trainer
|
5 |
+
# summary function - test for single gradio function interface
|
6 |
def bulk_function(filename):
|
7 |
# Create class for data preparation
|
8 |
class SimpleDataset:
|
|
|
22 |
trainer = Trainer(model=model)
|
23 |
|
24 |
# read file lines
|
25 |
+
with open(filename.name, "r") as f:
|
26 |
lines = f.readlines()
|
27 |
# expects unnamed:0 or index, col name -> strip both
|
28 |
+
lines_s = [item.split("\n")[0].split(",")[-1] for item in lines]
|
|
|
|
|
29 |
|
30 |
# Tokenize texts and create prediction data set
|
31 |
+
tokenized_texts = tokenizer(lines_s,truncation=True,padding=True)
|
32 |
pred_dataset = SimpleDataset(tokenized_texts)
|
33 |
|
34 |
# Run predictions
|
|
|
52 |
surprise = []
|
53 |
|
54 |
# extract scores (as many entries as exist in pred_texts)
|
55 |
+
for i in range(len(lines_s)):
|
56 |
anger.append(temp[i][0])
|
57 |
disgust.append(temp[i][1])
|
58 |
fear.append(temp[i][2])
|
|
|
62 |
surprise.append(temp[i][6])
|
63 |
|
64 |
# define df
|
65 |
+
df = pd.DataFrame(list(zip(lines_s,preds,labels,scores, anger, disgust, fear, joy, neutral, sadness, surprise)), columns=['text','pred','label','score', 'anger', 'disgust', 'fear', 'joy', 'neutral', 'sadness', 'surprise'])
|
66 |
|
67 |
# save results to csv
|
68 |
YOUR_FILENAME = "YOUR_FILENAME_EMOTIONS_gradio.csv" # name your output file
|