Update app.py
Browse files
app.py
CHANGED
|
@@ -1,28 +1,4 @@
|
|
| 1 |
-
pip install diffusers transformers torch numpy scipy gradio datasets
|
| 2 |
-
pip3 install torch==1.9.1+cu111 torchvision==0.10.1+cu111 torchaudio===0.9.1 -f https://download.pytorch.org/whl/torch_stable.html
|
| 3 |
-
|
| 4 |
-
import torch
|
| 5 |
-
from transformers import AutoModelForSequenceClassification, AutoTokenizer, AutoConfig
|
| 6 |
-
import numpy as np
|
| 7 |
-
from scipy.special import softmax
|
| 8 |
import gradio as gr
|
| 9 |
-
torch.cuda.is_available()
|
| 10 |
-
|
| 11 |
-
model_path = "cardiffnlp/twitter-roberta-base-sentiment-latest"
|
| 12 |
-
|
| 13 |
-
tokenizer = AutoTokenizer.from_pretrained(model_path)
|
| 14 |
-
config = AutoConfig.from_pretrained(model_path)
|
| 15 |
-
model = AutoModelForSequenceClassification.from_pretrained(model_path)
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
def sentiment_analysis(text):
|
| 19 |
-
encoded_input = tokenizer(text, return_tensors='pt')
|
| 20 |
-
output = model(**encoded_input)
|
| 21 |
-
scores_ = output[0][0].detach().numpy()
|
| 22 |
-
scores_ = softmax(scores_)
|
| 23 |
-
labels = ['Negative', 'Neutral', 'Positive']
|
| 24 |
-
scores = {l: float(s) for (l, s) in zip(labels, scores_)}
|
| 25 |
-
return scores
|
| 26 |
|
| 27 |
demo = gr.Interface(
|
| 28 |
theme=gr.themes.Base(),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
demo = gr.Interface(
|
| 4 |
theme=gr.themes.Base(),
|