Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import pipeline
|
3 |
+
|
4 |
+
# Load the pre-trained pipeline for sentiment analysis
|
5 |
+
sentiment_analysis = pipeline('text-classification', model='distilbert-base-uncased-finetuned-sst-2-english')
|
6 |
+
|
7 |
+
# Define the function that will be called by Gradio
|
8 |
+
def analyze_sentiment(input_text):
|
9 |
+
output = sentiment_analysis(input_text)
|
10 |
+
sentiment = output[0]['label']
|
11 |
+
score = output[0]['score']
|
12 |
+
return f"Sentiment: {sentiment} (Score: {score:.2f})"
|
13 |
+
|
14 |
+
# Create the Gradio interface
|
15 |
+
gr.Interface(fn=analyze_sentiment, inputs="text", outputs="text", title="Sentiment Analysis AI").launch()
|