Spaces:
Build error
Build error
upload to huggingface spaces
Browse files- app.py +39 -0
- requirements.txt +2 -0
app.py
ADDED
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification, pipeline
|
3 |
+
import gradio as gr
|
4 |
+
|
5 |
+
def text_sentiments(text):
|
6 |
+
|
7 |
+
model_name = "distilbert-base-uncased-finetuned-sst-2-english"
|
8 |
+
|
9 |
+
model = AutoModelForSequenceClassification.from_pretrained(model_name)
|
10 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
11 |
+
|
12 |
+
classifier = pipeline(task= "sentiment-analysis", model = model, tokenizer = tokenizer)
|
13 |
+
|
14 |
+
result = classifier(text)
|
15 |
+
|
16 |
+
label = result[0]["label"]
|
17 |
+
score = result[0]["score"] * 100
|
18 |
+
|
19 |
+
return f"Sentiment is : {label} and Confidence is : {score: 0.2f} %"
|
20 |
+
|
21 |
+
|
22 |
+
gr.Interface(fn = text_sentiments,
|
23 |
+
inputs = gr.inputs.Textbox(label = "Input Text"),
|
24 |
+
outputs = gr.outputs.Textbox(),
|
25 |
+
title = "Sentiment Classification with Bert",
|
26 |
+
).launch()
|
27 |
+
|
28 |
+
|
29 |
+
|
30 |
+
|
31 |
+
|
32 |
+
|
33 |
+
|
34 |
+
|
35 |
+
|
36 |
+
|
37 |
+
|
38 |
+
|
39 |
+
|
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
transformers
|
2 |
+
gradio
|