Spaces:
Runtime error
Runtime error
Download app.py from Ankoorkashyap/Sentiment_Analysis: direct link, hf CLI and curl.
- Browser
- Download file 492 Bytes
-
https://huggingface.co/spaces/Ankoorkashyap/Sentiment_Analysis/resolve/main/app.py
- Command line
-
hf download hf://spaces/Ankoorkashyap/Sentiment_Analysis/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Ankoorkashyap/Sentiment_Analysis/resolve/main/app.py
492 Bytes
| import gradio as gr | |
| from textblob import TextBlob | |
| # Define the sentiment analysis function | |
| def analyze_sentiment(text): | |
| blob = TextBlob(text) | |
| polarity = blob.sentiment.polarity | |
| subjectivity = blob.sentiment.subjectivity | |
| sentiment = "POSITIVE" if polarity >= 0 else "NEGATIVE" | |
| return f"Sentiment: {sentiment}\nPolarity: {polarity:.2f}\nSubjectivity: {subjectivity:.2%}" | |
| # Create a Gradio interface | |
| iface = gr.Interface(fn=analyze_sentiment, inputs="text", outputs="text") | |
| iface.launch() |