File size: 510 Bytes
3c7449e 8bc28bd 6cf2da3 8bc28bd 3c7449e 6cf2da3 3c7449e 8bc28bd 3c7449e 6cf2da3 3c7449e 6cf2da3 3c7449e 8bc28bd 3c7449e | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | import gradio as gr
from transformers import pipeline
MODEL = "cardiffnlp/twitter-roberta-base-sentiment-latest"
classifier = pipeline("sentiment-analysis", model=MODEL)
def analyze(text):
result = classifier(text)[0]
return {
"Sentiment": result["label"].capitalize(),
"Confidence": f"{result['score']:.2%}"
}
demo = gr.Interface(
fn=analyze,
inputs=gr.Textbox(lines=4),
outputs="json",
title="Sentiment Analyzer"
)
if __name__ == "__main__":
demo.launch() |