Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| from transformers import pipeline | |
| from gradio.components import Textbox | |
| # Load the sentiment analysis pipeline with DistilBERT | |
| distilbert_pipeline = pipeline("sentiment-analysis", model="distilbert-base-uncased-finetuned-sst-2-english") | |
| def predict_sentiment(text): | |
| """ | |
| Predicts the sentiment of the input text using DistilBERT. | |
| :param text: str, input text to analyze. | |
| :return: str, predicted sentiment and confidence score. | |
| """ | |
| result = distilbert_pipeline(text)[0] | |
| label = result['label'] | |
| score = result['score'] | |
| return f"Sentiment: {label}, Confidence: {score:.2f}" | |
| input1 = Textbox(lines=2, placeholder="Type your text here...") | |
| # Create a Gradio interface | |
| iface = gr.Interface(fn=predict_sentiment, | |
| inputs=input1 | |
| outputs="text", | |
| title="Talk2Loop Sensitive statement tags", | |
| description="This model predicts the sensitivity of the input text. Enter a sentence to see if it's sensitive or not.") | |
| # Launch the interface | |
| iface.launch() | |