import gradio as gr from transformers import pipeline # Load the text classification model model = pipeline("text-classification", model="Phase-Technologies/RoBERTo") # Define the function to classify text def classify_text(text): result = model(text) label = result[0]['label'] # Get predicted label (e.g., "POSITIVE" or "NEGATIVE") confidence = round(result[0]['score'] * 100, 2) # Get confidence score return f"Prediction: {label} (Confidence: {confidence}%)" # Create Gradio Interface iface = gr.Interface( fn=classify_text, inputs=gr.Textbox(label="Enter Text for Sentiment Analysis"), outputs=gr.Textbox(label="Model Prediction"), title="RoBERTo Sentiment Classifier", description="Enter a sentence, and the model will classify it as **Positive** or **Negative**." ) # Launch the Gradio app iface.launch()