Spaces:
Sleeping
Sleeping
| 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() |