Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import torch
|
2 |
+
from transformers import pipeline
|
3 |
+
import gradio as gr
|
4 |
+
|
5 |
+
# Load the sentiment analysis pipeline with a specified model
|
6 |
+
sentiment_analysis = pipeline("sentiment-analysis", model="distilbert-base-uncased-finetuned-sst-2-english")
|
7 |
+
|
8 |
+
# Define a simple Gradio interface function
|
9 |
+
def simple_sentiment_analysis(text):
|
10 |
+
sentiment = sentiment_analysis(text)
|
11 |
+
return sentiment[0]['label']
|
12 |
+
|
13 |
+
# Set up Gradio Interface
|
14 |
+
iface = gr.Interface(
|
15 |
+
fn=simple_sentiment_analysis,
|
16 |
+
inputs=gr.Textbox(lines=2, placeholder="Enter text here..."),
|
17 |
+
outputs=gr.Label(label="Sentiment"),
|
18 |
+
title="Sentiment Analysis",
|
19 |
+
description="Enter text to analyze its sentiment."
|
20 |
+
)
|
21 |
+
|
22 |
+
# Launch the interface with share=True for public access
|
23 |
+
iface.launch(share=True, debug=True)
|