dhruvilhere commited on
Commit
c76b751
·
verified ·
1 Parent(s): 0458af3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -5
app.py CHANGED
@@ -2,16 +2,16 @@ import os
2
  import openai
3
  import gradio as gr
4
 
5
- # Secure API key loading from Hugging Face Secrets or local env
6
  openai.api_key = os.getenv("OPENAI_API_KEY")
7
- openai.api_base = "https://openrouter.ai/api/v1"
8
 
9
- # Define how the chatbot should respond
10
  def get_emotional_response(name, issue):
11
  prompt = f"{name} is feeling emotionally low. Reason: {issue}. Give a supportive, warm response like a mental health companion."
12
 
13
  try:
14
- response = openai.ChatCompletion.create(
15
  model="deepseek-chat",
16
  messages=[
17
  {"role": "system", "content": "You are a warm and emotionally intelligent mental health companion."},
@@ -19,7 +19,7 @@ def get_emotional_response(name, issue):
19
  ],
20
  temperature=0.7
21
  )
22
- return response.choices[0].message.content
23
  except Exception as e:
24
  return f"⚠️ Error: {str(e)}"
25
 
 
2
  import openai
3
  import gradio as gr
4
 
5
+ # Secure API key from Hugging Face Secrets or env
6
  openai.api_key = os.getenv("OPENAI_API_KEY")
7
+ openai.base_url = "https://openrouter.ai/api/v1"
8
 
9
+ # Function to generate emotional response using ChatCompletion (v1.0+)
10
  def get_emotional_response(name, issue):
11
  prompt = f"{name} is feeling emotionally low. Reason: {issue}. Give a supportive, warm response like a mental health companion."
12
 
13
  try:
14
+ chat_response = openai.chat.completions.create(
15
  model="deepseek-chat",
16
  messages=[
17
  {"role": "system", "content": "You are a warm and emotionally intelligent mental health companion."},
 
19
  ],
20
  temperature=0.7
21
  )
22
+ return chat_response.choices[0].message.content
23
  except Exception as e:
24
  return f"⚠️ Error: {str(e)}"
25