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