garrettbaber
commited on
Commit
•
2925dbb
1
Parent(s):
416a17c
Format Output
Browse files
app.py
CHANGED
@@ -1,6 +1,12 @@
|
|
1 |
import gradio as gr
|
2 |
from transformers import AutoModelForSequenceClassification, AutoTokenizer
|
3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
def processInput(input):
|
5 |
#load model and tokenizer
|
6 |
model = AutoModelForSequenceClassification.from_pretrained("garrettbaber/twitter-roberta-base-fear-intensity")
|
@@ -9,9 +15,7 @@ def processInput(input):
|
|
9 |
tokens = tokenizer(input, return_tensors="pt")
|
10 |
#pass tokens to model
|
11 |
outputs = model(**tokens)
|
12 |
-
|
13 |
-
logits = outputs.get("logits")
|
14 |
-
return logits.tolist()
|
15 |
|
16 |
app = gr.Interface(fn=processInput, inputs="text", outputs="text")
|
17 |
|
|
|
1 |
import gradio as gr
|
2 |
from transformers import AutoModelForSequenceClassification, AutoTokenizer
|
3 |
|
4 |
+
def formatOutput(modelOutput):
|
5 |
+
#parse output
|
6 |
+
logits = outputs.get("logits")
|
7 |
+
rawScore = logits.tolist().pop().pop()
|
8 |
+
return f"{rawScore:.3f}"
|
9 |
+
|
10 |
def processInput(input):
|
11 |
#load model and tokenizer
|
12 |
model = AutoModelForSequenceClassification.from_pretrained("garrettbaber/twitter-roberta-base-fear-intensity")
|
|
|
15 |
tokens = tokenizer(input, return_tensors="pt")
|
16 |
#pass tokens to model
|
17 |
outputs = model(**tokens)
|
18 |
+
return formatOutput(outputs)
|
|
|
|
|
19 |
|
20 |
app = gr.Interface(fn=processInput, inputs="text", outputs="text")
|
21 |
|