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