Spaces:
Runtime error
Runtime error
Karthikeyan
commited on
Commit
•
b55512d
1
Parent(s):
3227853
Update app.py
Browse files
app.py
CHANGED
@@ -15,17 +15,34 @@ import plotly.express as px
|
|
15 |
|
16 |
class SentimentAnalyzer:
|
17 |
def __init__(self):
|
18 |
-
self.model="facebook/bart-large-mnli"
|
19 |
openai.api_key=os.getenv("OPENAI_API_KEY")
|
20 |
def analyze_sentiment(self, text):
|
21 |
-
pipe = pipeline("zero-shot-classification", model=self.model)
|
22 |
-
label=["positive","negative","neutral"]
|
23 |
-
result = pipe(text, label)
|
24 |
-
sentiment_scores= {result['labels'][0]:result['scores'][0],result['labels'][1]:result['scores'][1],result['labels'][2]:result['scores'][2]}
|
25 |
-
sentiment_scores_str = f"Positive: {sentiment_scores['positive']:.2f}, Neutral: {sentiment_scores['neutral']:.2f}, Negative: {sentiment_scores['negative']:.2f}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
return sentiment_scores_str
|
27 |
def emotion_analysis(self,text):
|
28 |
-
prompt = f""" Your task is find the top 3 emotion : <Sadness, Happiness, Joy, Fear, Disgust, Anger> and it's emotion score
|
29 |
your are analyze the text and provide the output in the following list format heigher to lower order: ["emotion1","emotion2","emotion3"][score1,score2,score3]''' [with top 1 result having the highest score]
|
30 |
The scores should be in the range of 0.0 to 1.0, where 1.0 represents the highest intensity of the emotion.\
|
31 |
analyze the text : '''{text}'''
|
|
|
15 |
|
16 |
class SentimentAnalyzer:
|
17 |
def __init__(self):
|
18 |
+
# self.model="facebook/bart-large-mnli"
|
19 |
openai.api_key=os.getenv("OPENAI_API_KEY")
|
20 |
def analyze_sentiment(self, text):
|
21 |
+
# pipe = pipeline("zero-shot-classification", model=self.model)
|
22 |
+
# label=["positive","negative","neutral"]
|
23 |
+
# result = pipe(text, label)
|
24 |
+
# sentiment_scores= {result['labels'][0]:result['scores'][0],result['labels'][1]:result['scores'][1],result['labels'][2]:result['scores'][2]}
|
25 |
+
# sentiment_scores_str = f"Positive: {sentiment_scores['positive']:.2f}, Neutral: {sentiment_scores['neutral']:.2f}, Negative: {sentiment_scores['negative']:.2f}"
|
26 |
+
prompt = f""" Your task is find the top 3 setiments : <positive, negative, neutral> and it's sentiment score for the Mental Healthcare Doctor Chatbot and patient conversation text.\
|
27 |
+
your are analyze the text and provide the output in the following json order: \"\"\"Positive: <sentiment_scores['positive']:.2f>, Neutral: <sentiment_scores['neutral']:.2f>, Negative: <sentiment_scores['negative']:.2f>\"\"\"
|
28 |
+
analyze the text : '''{text}'''
|
29 |
+
"""
|
30 |
+
response = openai.Completion.create(
|
31 |
+
model="text-davinci-003",
|
32 |
+
prompt=prompt,
|
33 |
+
temperature=1,
|
34 |
+
max_tokens=60,
|
35 |
+
top_p=1,
|
36 |
+
frequency_penalty=0,
|
37 |
+
presence_penalty=0
|
38 |
+
)
|
39 |
+
|
40 |
+
# Extract the generated text
|
41 |
+
sentiment_scores_str = response.choices[0].text.strip()
|
42 |
+
print(sentiment_scores_str)
|
43 |
return sentiment_scores_str
|
44 |
def emotion_analysis(self,text):
|
45 |
+
prompt = f""" Your task is find the top 3 emotion : <Sadness, Happiness, Joy, Fear, Disgust, Anger> and it's emotion score for the Mental Healthcare Doctor Chatbot and patient conversation text.\
|
46 |
your are analyze the text and provide the output in the following list format heigher to lower order: ["emotion1","emotion2","emotion3"][score1,score2,score3]''' [with top 1 result having the highest score]
|
47 |
The scores should be in the range of 0.0 to 1.0, where 1.0 represents the highest intensity of the emotion.\
|
48 |
analyze the text : '''{text}'''
|