Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,13 +1,24 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
-
# Load
|
| 5 |
-
model = pipeline("
|
| 6 |
|
| 7 |
-
# Define
|
| 8 |
-
def
|
| 9 |
-
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
-
# Create Gradio
|
| 12 |
-
iface = gr.Interface(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
iface.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
+
# Load the text classification model
|
| 5 |
+
model = pipeline("text-classification", model="Phase-Technologies/RoBERTo")
|
| 6 |
|
| 7 |
+
# Define the function to classify text
|
| 8 |
+
def classify_text(text):
|
| 9 |
+
result = model(text)
|
| 10 |
+
label = result[0]['label'] # Get predicted label (e.g., "POSITIVE" or "NEGATIVE")
|
| 11 |
+
confidence = round(result[0]['score'] * 100, 2) # Get confidence score
|
| 12 |
+
return f"Prediction: {label} (Confidence: {confidence}%)"
|
| 13 |
|
| 14 |
+
# Create Gradio Interface
|
| 15 |
+
iface = gr.Interface(
|
| 16 |
+
fn=classify_text,
|
| 17 |
+
inputs=gr.Textbox(label="Enter Text for Sentiment Analysis"),
|
| 18 |
+
outputs=gr.Textbox(label="Model Prediction"),
|
| 19 |
+
title="RoBERTo Sentiment Classifier",
|
| 20 |
+
description="Enter a sentence, and the model will classify it as **Positive** or **Negative**."
|
| 21 |
+
)
|
| 22 |
+
|
| 23 |
+
# Launch the Gradio app
|
| 24 |
iface.launch()
|