anshu-man853 commited on
Commit
bcb9497
·
verified ·
1 Parent(s): 78fc150

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -6
app.py CHANGED
@@ -3,12 +3,17 @@ from textblob import TextBlob
3
 
4
  # Define the sentiment analysis function
5
  def analyze_sentiment(text):
6
- blob = TextBlob(text)
7
- polarity = blob.sentiment.polarity
8
- subjectivity = blob.sentiment.subjectivity
9
- sentiment = "POSITIVE" if polarity >= 0 else "NEGATIVE"
10
- return f"Sentiment: {sentiment}\nPolarity: {polarity:.2f}\nSubjectivity: {subjectivity:.2%}"
 
 
 
 
11
 
12
  # Create a Gradio interface
13
  iface = gr.Interface(fn=analyze_sentiment, inputs="text", outputs="text")
14
- iface.launch()
 
 
3
 
4
  # Define the sentiment analysis function
5
  def analyze_sentiment(text):
6
+ # Create a TextBlob object
7
+ blob = TextBlob(text)
8
+ # Extract sentiment
9
+ polarity = blob.sentiment.polarity
10
+ subjectivity = blob.sentiment.subjectivity
11
+ # Determine sentiment type
12
+ sentiment = "POSITIVE" if polarity >= 0 else "NEGATIVE"
13
+ # Return formatted string with results
14
+ return f"Sentiment: {sentiment}\nPolarity: {polarity:.2f}\nSubjectivity: {subjectivity:.2%}"
15
 
16
  # Create a Gradio interface
17
  iface = gr.Interface(fn=analyze_sentiment, inputs="text", outputs="text")
18
+ # Launch the interface
19
+ iface.launch()