Spaces:
Runtime error
Runtime error
Commit
·
fba9f25
1
Parent(s):
fce3dc7
Update app.py
Browse files
app.py
CHANGED
@@ -2,7 +2,14 @@ import gradio as gr
|
|
2 |
import pandas as pd
|
3 |
import numpy as np
|
4 |
from transformers import AutoTokenizer, AutoModelForSequenceClassification, Trainer
|
5 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
# summary function - test for single gradio function interfrace
|
7 |
def bulk_function(filename):
|
8 |
# Create class for data preparation
|
@@ -16,24 +23,11 @@ def bulk_function(filename):
|
|
16 |
def __getitem__(self, idx):
|
17 |
return {k: v[idx] for k, v in self.tokenized_texts.items()}
|
18 |
|
19 |
-
# load tokenizer and model, create trainer
|
20 |
-
model_name = "j-hartmann/emotion-english-distilroberta-base"
|
21 |
-
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
22 |
-
model = AutoModelForSequenceClassification.from_pretrained(model_name)
|
23 |
-
trainer = Trainer(model=model)
|
24 |
-
print(filename, type(filename))
|
25 |
-
print(filename.name)
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
# read file lines
|
30 |
with open(filename.name, "r") as f:
|
31 |
lines = f.readlines()
|
32 |
# expects unnamed:0 or index, col name -> strip both
|
33 |
-
lines_s = [item.split("\n")[0].split(",")[-1] for item in lines]
|
34 |
-
print(lines_s)
|
35 |
-
print(filename)
|
36 |
-
|
37 |
|
38 |
# Tokenize texts and create prediction data set
|
39 |
tokenized_texts = tokenizer(lines_s,truncation=True,padding=True)
|
@@ -77,7 +71,7 @@ def bulk_function(filename):
|
|
77 |
df.to_csv(YOUR_FILENAME)
|
78 |
|
79 |
# return dataframe for space output
|
80 |
-
return
|
81 |
|
82 |
-
gr.Interface(bulk_function, [gr.inputs.File(file_count="single", type="file", label="str", optional=False),],"
|
83 |
).launch(debug=True)
|
|
|
2 |
import pandas as pd
|
3 |
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
|
|
|
23 |
def __getitem__(self, idx):
|
24 |
return {k: v[idx] for k, v in self.tokenized_texts.items()}
|
25 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
# read file lines
|
27 |
with open(filename.name, "r") as f:
|
28 |
lines = f.readlines()
|
29 |
# expects unnamed:0 or index, col name -> strip both
|
30 |
+
lines_s = [item.split("\n")[0].split(",")[-1] for item in lines][1:]
|
|
|
|
|
|
|
31 |
|
32 |
# Tokenize texts and create prediction data set
|
33 |
tokenized_texts = tokenizer(lines_s,truncation=True,padding=True)
|
|
|
71 |
df.to_csv(YOUR_FILENAME)
|
72 |
|
73 |
# return dataframe for space output
|
74 |
+
return YOUR_FILENAME
|
75 |
|
76 |
+
gr.Interface(bulk_function, [gr.inputs.File(file_count="single", type="file", label="str", optional=False),],["file"],
|
77 |
).launch(debug=True)
|