File size: 855 Bytes
e6de672
 
 
f75b5a2
 
e6de672
f75b5a2
 
 
 
 
 
e6de672
f75b5a2
 
 
 
 
 
 
 
 
 
e6de672
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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()