Spaces:
Sleeping
Sleeping
Julien Simon
commited on
Commit
·
8952566
1
Parent(s):
2c1eccc
Initial version
Browse files- app.py +19 -0
- requirements.txt +2 -0
app.py
ADDED
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import torch
|
2 |
+
import numpy as np
|
3 |
+
import gradio as gr
|
4 |
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
5 |
+
|
6 |
+
tokenizer = AutoTokenizer.from_pretrained("juliensimon/autonlp-imdb-sentiment-analysis-15862661")
|
7 |
+
model = AutoModelForSequenceClassification.from_pretrained("juliensimon/autonlp-imdb-sentiment-analysis-15862661")
|
8 |
+
|
9 |
+
def predict(review):
|
10 |
+
inputs = tokenizer(review, padding=True, truncation=True, return_tensors="pt")
|
11 |
+
outputs = model(**inputs)
|
12 |
+
predictions = torch.nn.functional.softmax(outputs.logits, dim=-1)
|
13 |
+
predictions = predictions.detach().numpy()[0]
|
14 |
+
index = np.argmax(predictions)
|
15 |
+
score = predictions[index]
|
16 |
+
return "This review is {:.2f}% {}".format(100*score, "negative" if index==0 else "positive")
|
17 |
+
|
18 |
+
iface = gr.Interface(fn=predict, inputs="text", outputs="text")
|
19 |
+
iface.launch()
|
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
torch
|
2 |
+
transformers
|