Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import pipeline
|
3 |
+
|
4 |
+
# Load Hugging Face sentiment analysis pipeline
|
5 |
+
sentiment_pipeline = pipeline("sentiment-analysis")
|
6 |
+
|
7 |
+
# Define function to wrap the model
|
8 |
+
def analyze_sentiment(text):
|
9 |
+
result = sentiment_pipeline(text)[0]
|
10 |
+
return f"Label: {result['label']}, Confidence: {round(result['score'], 3)}"
|
11 |
+
|
12 |
+
# Create Gradio interface
|
13 |
+
interface = gr.Interface(fn=analyze_sentiment,
|
14 |
+
inputs="text",
|
15 |
+
outputs="text",
|
16 |
+
title="Sentiment Analysis App",
|
17 |
+
description="Enter a sentence to analyze its sentiment.")
|
18 |
+
|
19 |
+
# Launch app (not needed on Spaces, but useful for local testing)
|
20 |
+
if __name__ == "__main__":
|
21 |
+
interface.launch()
|