Nitin00043 commited on
Commit
623c9e7
·
verified ·
1 Parent(s): c1fa731

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -0
app.py ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import pipeline
2
+ import gradio as gr
3
+
4
+ # Load sentiment and emotion models
5
+ sentiment_model = "cardiffnlp/twitter-roberta-base-sentiment"
6
+ emotion_model = "bhadresh-savani/bert-base-uncased-emotion"
7
+
8
+ sentiment_pipeline = pipeline("sentiment-analysis", model=sentiment_model, tokenizer=sentiment_model)
9
+ emotion_pipeline = pipeline("text-classification", model=emotion_model, tokenizer=emotion_model)
10
+
11
+ # Function to analyze sentiment and emotion
12
+ def analyze_text(text):
13
+ sentiment_result = sentiment_pipeline(text)[0]
14
+ emotion_result = emotion_pipeline(text)[0]
15
+
16
+ return {
17
+ "Sentiment": {sentiment_result['label']: sentiment_result['score']},
18
+ "Emotion": {emotion_result['label']: emotion_result['score']}
19
+ }
20
+
21
+ # Gradio interface
22
+ demo = gr.Interface(
23
+ fn=analyze_text,
24
+ inputs=gr.Textbox(placeholder="Enter your text here...", label="Input Text"),
25
+ outputs=gr.Label(label="Analysis Results"),
26
+ title="Sentiment and Emotion Analysis",
27
+ description="Analyze the sentiment and emotion of your text using advanced NLP models.",
28
+ examples=[
29
+ ["I'm thrilled to start this new adventure!"],
30
+ ["This situation is making me really frustrated."],
31
+ ["I feel so heartbroken and lost."]
32
+ ],
33
+ theme="soft"
34
+ )
35
+
36
+ # Deploy the application
37
+ if __name__ == "__main__":
38
+ demo.launch()