Spaces:
Sleeping
Sleeping
File size: 1,417 Bytes
9f88cc8 17e8031 9e74ae8 17e8031 9f88cc8 17e8031 856e458 17e8031 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
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) |