Spaces:
Build error
Build error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
|
| 4 |
+
# Load a pre-trained sentiment-analysis model
|
| 5 |
+
classifier = pipeline('ChavinloSocialRise/bot_rejection_model')
|
| 6 |
+
|
| 7 |
+
# Define a function to classify the input text
|
| 8 |
+
def classify_text(text):
|
| 9 |
+
result = classifier(text)[0] # Get the first result
|
| 10 |
+
label = result['label'] # The label (e.g., POSITIVE, NEGATIVE)
|
| 11 |
+
score = result['score'] # The confidence score
|
| 12 |
+
return f"Label: {label}, Confidence: {score:.4f}"
|
| 13 |
+
|
| 14 |
+
# Create a Gradio interface
|
| 15 |
+
iface = gr.Interface(
|
| 16 |
+
fn=classify_text, # Function to call
|
| 17 |
+
inputs="text", # Input: a text box
|
| 18 |
+
outputs="text", # Output: text
|
| 19 |
+
title="Text Classifier",
|
| 20 |
+
description="Enter some text and see the classification result."
|
| 21 |
+
)
|
| 22 |
+
|
| 23 |
+
# Launch the app
|
| 24 |
+
if __name__ == "__main__":
|
| 25 |
+
iface.launch()
|