kunjshah01 commited on
Commit
69a98bf
·
verified ·
1 Parent(s): 3fa4702

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -0
app.py ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ from dotenv import load_dotenv
3
+ import gradio as gr
4
+ from textblob import TextBlob
5
+
6
+ # Load environment variables from .env file
7
+ load_dotenv()
8
+
9
+ def sentiment_analysis(text:str) -> dict:
10
+ """
11
+ Analyze the sentiment of the given text.
12
+
13
+ Args:
14
+ text (str): The text to analyze
15
+
16
+ Returns:
17
+ dict: A dictionary containing polarity, subjectivity, and assessment
18
+ """
19
+ blob=TextBlob(text)
20
+ sentiment = blob.sentiment
21
+
22
+ return{
23
+ "polarity": round(sentiment.polarity, 2),
24
+ "subjectivity": round(sentiment.subjectivity, 2),
25
+ "assessment": "positive" if sentiment.polarity > 0 else "negative" if sentiment.polarity < 0 else "neutral"
26
+ }
27
+
28
+ demo = gr.Interface(
29
+ fn=sentiment_analysis,
30
+ inputs=gr.Textbox(placeholder="Enter text to analyze..."),
31
+ outputs=gr.JSON(),
32
+ title="Text Sentiment Analysis",
33
+ description="Analyze the sentiment of text using TextBlob"
34
+ )
35
+
36
+ if __name__ == "__main__":
37
+ demo.launch(share=True)