Spaces:
Runtime error
Runtime error
from openai import AzureOpenAI | |
client = AzureOpenAI() | |
class SentimentAnalyzer: | |
def __init__(self): | |
pass | |
def analyze_sentiment(self, text): | |
conversation = [ | |
{"role": "system", "content": """You are a Sentiment Analyser.Your task is to analyze and predict the sentiment using scores. Sentiments are categorized into the following list: Positive,Negative,Neutral. You need to provide the sentiment with the highest score. The scores should be in the range of 0.0 to 1.0, where 1.0 represents the highest intensity of the emotion. | |
Please analyze the text and provide the output in the following format: Sentiment: score [with one result having the highest score]."""}, | |
{"role": "user", "content": f""" | |
input text{text} | |
"""} | |
] | |
response = client.chat.completions.create( | |
model="GPT-3", | |
messages=conversation, | |
temperature=1, | |
max_tokens=60 | |
) | |
message = response.choices[0].message.content | |
return message | |
def emotion_analysis(self,text): | |
conversation = [ | |
{"role": "system", "content": """You are a Emotion Analyser.Your task is to analyze and predict the emotion using scores. Emotions are categorized into the following list: Sadness, Happiness, Joy, Fear, Disgust, and Anger. You need to provide the emotion with the highest score. The scores should be in the range of 0.0 to 1.0, where 1.0 represents the highest intensity of the emotion. | |
Please analyze the text and provide the output in the following format: emotion: score [with one result having the highest score]."""}, | |
{"role": "user", "content": f""" | |
input text{text} | |
"""} | |
] | |
response = client.chat.completions.create( | |
model="GPT-3", | |
messages=conversation, | |
temperature=1, | |
max_tokens=60 | |
) | |
message = response.choices[0].message.content | |
return message | |
class Summarizer: | |
def __init__(self): | |
# self.client = OpenAI() | |
pass | |
def generate_summary(self, text): | |
conversation = [ | |
{"role": "system", "content": "You are a Summarizer"}, | |
{"role": "user", "content": f"""summarize the following conversation delimited by triple backticks. | |
```{text}``` | |
"""} | |
] | |
response = client.chat.completions.create( | |
model="GPT-3", | |
messages=conversation, | |
temperature=1, | |
max_tokens=500 | |
) | |
message = response.choices[0].message.content | |
return message | |