Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
|
| 4 |
+
roberta_sentiment = pipeline(
|
| 5 |
+
"text-classifier", model="rasyosef/roberta-base-finetuned-sst2"
|
| 6 |
+
)
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
def predict_sentiment(text):
|
| 10 |
+
return roberta_sentiment(text)
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
with gr.Blocks() as demo:
|
| 14 |
+
gr.Markdown(
|
| 15 |
+
"""
|
| 16 |
+
# Sentiment Classifier
|
| 17 |
+
|
| 18 |
+
This model is a fine-tuned version of roberta-base on
|
| 19 |
+
the glue sst2 dataset for sentiment classification.
|
| 20 |
+
The model classifies the input text as having either
|
| 21 |
+
`positive` or `negative` sentiment.
|
| 22 |
+
"""
|
| 23 |
+
)
|
| 24 |
+
with gr.Row():
|
| 25 |
+
with gr.Column():
|
| 26 |
+
inp = gr.Textbox(label="Input text", placeholder="Enter text here", lines=3)
|
| 27 |
+
btn = gr.Button("Classify")
|
| 28 |
+
with gr.Column():
|
| 29 |
+
out = gr.Textbox(label="Sentiment")
|
| 30 |
+
|
| 31 |
+
btn.click(fn=predict_sentiment, inputs=inp, outputs=out)
|
| 32 |
+
gr.Examples(
|
| 33 |
+
examples=["This movie was awesome.", "The movie was boring."],
|
| 34 |
+
inputs=[inp],
|
| 35 |
+
)
|
| 36 |
+
|
| 37 |
+
demo.launch()
|