Spaces:
Running
Running
Pranav0111
commited on
Commit
•
1c07179
1
Parent(s):
0f79bc3
Update app.py
Browse files
app.py
CHANGED
@@ -11,6 +11,7 @@ sentiment_analyzer = pipeline("sentiment-analysis", model="distilbert-base-uncas
|
|
11 |
# Retrieve OpenAI API key from Hugging Face secret
|
12 |
openai.api_key = os.getenv("open_AI_API_key")
|
13 |
|
|
|
14 |
class JournalCompanion:
|
15 |
def __init__(self):
|
16 |
self.entries = []
|
@@ -52,13 +53,16 @@ class JournalCompanion:
|
|
52 |
def generate_dynamic_prompts(self, sentiment):
|
53 |
prompt_request = f"Generate three reflective journal prompts for a person feeling {sentiment.lower()}."
|
54 |
try:
|
55 |
-
response = openai.
|
56 |
-
|
57 |
-
|
|
|
|
|
|
|
58 |
max_tokens=60,
|
59 |
n=1
|
60 |
)
|
61 |
-
prompts = response.choices[0].
|
62 |
except Exception as e:
|
63 |
print("Error generating prompts:", e)
|
64 |
prompts = "Could not generate prompts at this time."
|
@@ -67,13 +71,16 @@ class JournalCompanion:
|
|
67 |
def generate_dynamic_affirmation(self, sentiment):
|
68 |
affirmation_request = f"Generate an affirmation for someone who is feeling {sentiment.lower()}."
|
69 |
try:
|
70 |
-
response = openai.
|
71 |
-
|
72 |
-
|
|
|
|
|
|
|
73 |
max_tokens=20,
|
74 |
n=1
|
75 |
)
|
76 |
-
affirmation = response.choices[0].
|
77 |
except Exception as e:
|
78 |
print("Error generating affirmation:", e)
|
79 |
affirmation = "Could not generate an affirmation at this time."
|
|
|
11 |
# Retrieve OpenAI API key from Hugging Face secret
|
12 |
openai.api_key = os.getenv("open_AI_API_key")
|
13 |
|
14 |
+
|
15 |
class JournalCompanion:
|
16 |
def __init__(self):
|
17 |
self.entries = []
|
|
|
53 |
def generate_dynamic_prompts(self, sentiment):
|
54 |
prompt_request = f"Generate three reflective journal prompts for a person feeling {sentiment.lower()}."
|
55 |
try:
|
56 |
+
response = openai.ChatCompletion.create(
|
57 |
+
model="gpt-3.5-turbo",
|
58 |
+
messages=[
|
59 |
+
{"role": "system", "content": "You are a helpful assistant."},
|
60 |
+
{"role": "user", "content": prompt_request}
|
61 |
+
],
|
62 |
max_tokens=60,
|
63 |
n=1
|
64 |
)
|
65 |
+
prompts = response.choices[0].message["content"].strip()
|
66 |
except Exception as e:
|
67 |
print("Error generating prompts:", e)
|
68 |
prompts = "Could not generate prompts at this time."
|
|
|
71 |
def generate_dynamic_affirmation(self, sentiment):
|
72 |
affirmation_request = f"Generate an affirmation for someone who is feeling {sentiment.lower()}."
|
73 |
try:
|
74 |
+
response = openai.ChatCompletion.create(
|
75 |
+
model="gpt-3.5-turbo",
|
76 |
+
messages=[
|
77 |
+
{"role": "system", "content": "You are a helpful assistant."},
|
78 |
+
{"role": "user", "content": affirmation_request}
|
79 |
+
],
|
80 |
max_tokens=20,
|
81 |
n=1
|
82 |
)
|
83 |
+
affirmation = response.choices[0].message["content"].strip()
|
84 |
except Exception as e:
|
85 |
print("Error generating affirmation:", e)
|
86 |
affirmation = "Could not generate an affirmation at this time."
|