Spaces:
Sleeping
Sleeping
import gradio as gr | |
import openai | |
import os | |
# Make sure your OPENAI_API_KEY is securely set | |
openai.api_key = os.getenv("OPENAI_API_KEY", None) | |
def render(online_mode: bool): | |
def get_response(message): | |
if not online_mode: | |
return "I'm here with you. It's okay to feel overwhelmed. You're not alone." | |
if openai.api_key is None: | |
return "Error: OpenAI API key is not configured." | |
try: | |
response = openai.ChatCompletion.create( | |
model="ft:gpt-4.1-2025-04-14:raiffs-bits:codettev5:BlPFHJgf", # or "gpt-3.5-turbo" | |
messages=[ | |
{"role": "system", "content": "You are Codette, an empathetic and supportive AI trained to provide emotional comfort in crisis situations."}, | |
{"role": "user", "content": message} | |
], | |
max_tokens=100, | |
temperature=0.7 | |
) | |
return response.choices[0].message["content"].strip() | |
except Exception as e: | |
return f"API error: {str(e)}" | |
with gr.Row(): | |
with gr.Column(): | |
gr.Markdown("### Emotional Support Check-In") | |
msg_box = gr.Textbox(label="How are you feeling?") | |
submit_btn = gr.Button("Send") | |
output_box = gr.Textbox(label="Codette's Response") | |
submit_btn.click(get_response, inputs=msg_box, outputs=output_box) |