Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
# Load a tweet classification model from Hugging Face
|
| 4 |
+
classifier = pipeline("text-classification", model="finiteautomata/bertweet-base-sentiment-analysis")
|
| 5 |
+
|
| 6 |
+
def classify_tweet(tweet):
|
| 7 |
+
result = classifier(tweet)[0]
|
| 8 |
+
label = result['label']
|
| 9 |
+
score = result['score']
|
| 10 |
+
return f"Label: {label} (Confidence: {score:.2f})"
|
| 11 |
+
|
| 12 |
+
# Create the Gradio interface
|
| 13 |
+
iface = gr.Interface(
|
| 14 |
+
fn=classify_tweet,
|
| 15 |
+
inputs=gr.Textbox(lines=3, placeholder="Enter a tweet here..."),
|
| 16 |
+
outputs="text",
|
| 17 |
+
title="Tweet Classifier",
|
| 18 |
+
description="Enter a tweet and click the button to classify it!"
|
| 19 |
+
)
|
| 20 |
+
|
| 21 |
+
# Launch the app
|
| 22 |
+
iface.launch()
|