Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
|
| 4 |
+
# Load the pre-trained sentiment analysis model
|
| 5 |
+
sentiment_analysis = pipeline("sentiment-analysis")
|
| 6 |
+
|
| 7 |
+
# Define the function for sentiment prediction
|
| 8 |
+
def predict_sentiment(text):
|
| 9 |
+
result = sentiment_analysis(text)
|
| 10 |
+
return result[0]['label']
|
| 11 |
+
|
| 12 |
+
# Create the Gradio interface
|
| 13 |
+
iface = gr.Interface(fn=predict_sentiment, inputs="text", outputs="text",
|
| 14 |
+
title="Sentiment Analyser",
|
| 15 |
+
description="Here's a demo SA.",)
|
| 16 |
+
|
| 17 |
+
# Launch the app
|
| 18 |
+
iface.launch(share=True)
|