Spaces:
Runtime error
Runtime error
robertselvam
commited on
Commit
•
7ee3783
1
Parent(s):
1dde3ad
Update app.py
Browse files
app.py
CHANGED
@@ -5,7 +5,7 @@ import validators
|
|
5 |
import requests
|
6 |
import tempfile
|
7 |
import gradio as gr
|
8 |
-
import
|
9 |
import re
|
10 |
import json
|
11 |
from transformers import pipeline
|
@@ -16,14 +16,19 @@ import pandas as pd
|
|
16 |
|
17 |
class SentimentAnalyzer:
|
18 |
def __init__(self):
|
19 |
-
|
20 |
-
|
|
|
|
|
|
|
|
|
|
|
21 |
def emotion_analysis(self,text):
|
22 |
prompt = f""" Your task is find the top 3 emotion for this converstion {text}: <Sadness, Happiness, Fear, Disgust, Anger> and it's emotion score for the Mental Healthcare Doctor Chatbot and patient conversation text.\
|
23 |
you 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 3 result having the highest score]
|
24 |
The scores should be in the range of 0.0 to 1.0, where 1.0 represents the highest intensity of the emotion.
|
25 |
"""
|
26 |
-
response =
|
27 |
model="text-davinci-003",
|
28 |
prompt=prompt,
|
29 |
temperature=0,
|
@@ -77,7 +82,7 @@ class Summarizer:
|
|
77 |
def __init__(self):
|
78 |
openai.api_key=os.getenv("OPENAI_API_KEY")
|
79 |
def generate_summary(self, text):
|
80 |
-
model_engine = "
|
81 |
prompt = f"""summarize the following conversation delimited by triple backticks. write within 30 words.```{text}``` """
|
82 |
completions = openai.Completion.create(
|
83 |
engine=model_engine,
|
@@ -97,7 +102,11 @@ sentiment = SentimentAnalyzer()
|
|
97 |
class LangChain_Document_QA:
|
98 |
|
99 |
def __init__(self):
|
100 |
-
|
|
|
|
|
|
|
|
|
101 |
|
102 |
def _add_text(self,history, text):
|
103 |
history = history + [(text, None)]
|
@@ -171,8 +180,8 @@ class LangChain_Document_QA:
|
|
171 |
Patient: ['''{text}''']
|
172 |
Perform as Mental Healthcare Doctor Chatbot
|
173 |
"""
|
174 |
-
response =
|
175 |
-
model="
|
176 |
prompt=prompt,
|
177 |
temperature=0,
|
178 |
max_tokens=500,
|
|
|
5 |
import requests
|
6 |
import tempfile
|
7 |
import gradio as gr
|
8 |
+
from openai import AzureOpenAI
|
9 |
import re
|
10 |
import json
|
11 |
from transformers import pipeline
|
|
|
16 |
|
17 |
class SentimentAnalyzer:
|
18 |
def __init__(self):
|
19 |
+
|
20 |
+
self.client = AzureOpenAI(
|
21 |
+
api_key = os.getenv("AZURE_OPENAI_API_KEY"),
|
22 |
+
api_version = "2024-02-01",
|
23 |
+
azure_endpoint = os.getenv("AZURE_OPENAI_ENDPOINT")
|
24 |
+
)
|
25 |
+
|
26 |
def emotion_analysis(self,text):
|
27 |
prompt = f""" Your task is find the top 3 emotion for this converstion {text}: <Sadness, Happiness, Fear, Disgust, Anger> and it's emotion score for the Mental Healthcare Doctor Chatbot and patient conversation text.\
|
28 |
you 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 3 result having the highest score]
|
29 |
The scores should be in the range of 0.0 to 1.0, where 1.0 represents the highest intensity of the emotion.
|
30 |
"""
|
31 |
+
response = self.client.Completion.create(
|
32 |
model="text-davinci-003",
|
33 |
prompt=prompt,
|
34 |
temperature=0,
|
|
|
82 |
def __init__(self):
|
83 |
openai.api_key=os.getenv("OPENAI_API_KEY")
|
84 |
def generate_summary(self, text):
|
85 |
+
model_engine = "GPT3"
|
86 |
prompt = f"""summarize the following conversation delimited by triple backticks. write within 30 words.```{text}``` """
|
87 |
completions = openai.Completion.create(
|
88 |
engine=model_engine,
|
|
|
102 |
class LangChain_Document_QA:
|
103 |
|
104 |
def __init__(self):
|
105 |
+
self.client = AzureOpenAI(
|
106 |
+
api_key = os.getenv("AZURE_OPENAI_API_KEY"),
|
107 |
+
api_version = "2024-02-01",
|
108 |
+
azure_endpoint = os.getenv("AZURE_OPENAI_ENDPOINT")
|
109 |
+
)
|
110 |
|
111 |
def _add_text(self,history, text):
|
112 |
history = history + [(text, None)]
|
|
|
180 |
Patient: ['''{text}''']
|
181 |
Perform as Mental Healthcare Doctor Chatbot
|
182 |
"""
|
183 |
+
response = self.client.Completion.create(
|
184 |
+
model="GPT3",
|
185 |
prompt=prompt,
|
186 |
temperature=0,
|
187 |
max_tokens=500,
|