Update app.py
Browse files
app.py
CHANGED
|
@@ -2,16 +2,16 @@ import os
|
|
| 2 |
import openai
|
| 3 |
import gradio as gr
|
| 4 |
|
| 5 |
-
# Secure API key
|
| 6 |
openai.api_key = os.getenv("OPENAI_API_KEY")
|
| 7 |
-
openai.
|
| 8 |
|
| 9 |
-
#
|
| 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 |
-
|
| 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
|
| 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 |
|