Spaces:
Sleeping
Sleeping
Update emotional_core.py
Browse files- emotional_core.py +35 -14
emotional_core.py
CHANGED
@@ -1,17 +1,38 @@
|
|
1 |
import gradio as gr
|
2 |
-
import
|
|
|
3 |
|
4 |
-
|
5 |
-
|
6 |
-
history = history or []
|
7 |
-
history.append((msg, "I'm here with you. Stay strong."))
|
8 |
-
return history, history
|
9 |
|
10 |
-
def render(
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
import openai
|
3 |
+
import os
|
4 |
|
5 |
+
# Make sure your OPENAI_API_KEY is securely set
|
6 |
+
openai.api_key = os.getenv("OPENAI_API_KEY", None)
|
|
|
|
|
|
|
7 |
|
8 |
+
def render(online_mode: bool):
|
9 |
+
def get_response(message):
|
10 |
+
if not online_mode:
|
11 |
+
return "I'm here with you. It's okay to feel overwhelmed. You're not alone."
|
12 |
+
|
13 |
+
if openai.api_key is None:
|
14 |
+
return "Error: OpenAI API key is not configured."
|
15 |
+
|
16 |
+
try:
|
17 |
+
response = openai.ChatCompletion.create(
|
18 |
+
model="", # or "gpt-3.5-turbo"
|
19 |
+
messages=[
|
20 |
+
{"role": "system", "content": "You are Codette, an empathetic and supportive AI trained to provide emotional comfort in crisis situations."},
|
21 |
+
{"role": "user", "content": message}
|
22 |
+
],
|
23 |
+
max_tokens=100,
|
24 |
+
temperature=0.7
|
25 |
+
)
|
26 |
+
return response.choices[0].message["content"].strip()
|
27 |
+
except Exception as e:
|
28 |
+
return f"API error: {str(e)}"
|
29 |
+
|
30 |
+
with gr.Row():
|
31 |
+
with gr.Column():
|
32 |
+
gr.Markdown("### Emotional Support Check-In")
|
33 |
+
msg_box = gr.Textbox(label="How are you feeling?")
|
34 |
+
submit_btn = gr.Button("Send")
|
35 |
+
|
36 |
+
output_box = gr.Textbox(label="Codette's Response")
|
37 |
+
|
38 |
+
submit_btn.click(get_response, inputs=msg_box, outputs=output_box)
|