Raiff1982 commited on
Commit
17e8031
·
verified ·
1 Parent(s): 477ed9e

Update emotional_core.py

Browse files
Files changed (1) hide show
  1. emotional_core.py +35 -14
emotional_core.py CHANGED
@@ -1,17 +1,38 @@
1
  import gradio as gr
2
- import ethics_audit
 
3
 
4
- def respond(msg, history):
5
- ethics_audit.log_event("EmotionalCore interaction")
6
- history = history or []
7
- history.append((msg, "I'm here with you. Stay strong."))
8
- return history, history
9
 
10
- def render(online):
11
- with gr.Column():
12
- gr.Markdown("### Emotional Support Chatbot")
13
- chatbot = gr.Chatbot()
14
- msg = gr.Textbox(label="How are you feeling?")
15
- submit = gr.Button("Send")
16
- state = gr.State([])
17
- submit.click(fn=respond, inputs=[msg, state], outputs=[chatbot, state])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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)