Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,11 +1,17 @@
|
|
| 1 |
-
import
|
| 2 |
import gradio as gr
|
|
|
|
| 3 |
|
| 4 |
-
#
|
| 5 |
-
|
| 6 |
-
openai.base_url = "https://openrouter.ai/api/v1"
|
| 7 |
|
| 8 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
def get_emotional_response(name, issue):
|
| 10 |
prompt = (
|
| 11 |
f"{name} is feeling emotionally low. Reason: {issue}. "
|
|
@@ -13,7 +19,7 @@ def get_emotional_response(name, issue):
|
|
| 13 |
)
|
| 14 |
|
| 15 |
try:
|
| 16 |
-
response =
|
| 17 |
model="deepseek/deepseek-r1:free",
|
| 18 |
messages=[
|
| 19 |
{"role": "system", "content": "You are a warm and emotionally intelligent mental health companion."},
|
|
@@ -21,14 +27,12 @@ def get_emotional_response(name, issue):
|
|
| 21 |
],
|
| 22 |
temperature=0.7
|
| 23 |
)
|
| 24 |
-
|
| 25 |
-
content = response.model_dump()["choices"][0]["message"]["content"]
|
| 26 |
-
return content
|
| 27 |
|
| 28 |
except Exception as e:
|
| 29 |
return f"⚠️ Error: {str(e)}"
|
| 30 |
|
| 31 |
-
#
|
| 32 |
with gr.Blocks(theme=gr.themes.Base()) as demo:
|
| 33 |
gr.Markdown("""
|
| 34 |
# 🧠 MindMate: Your Mental Health Companion
|
|
|
|
| 1 |
+
import os
|
| 2 |
import gradio as gr
|
| 3 |
+
from openai import OpenAI
|
| 4 |
|
| 5 |
+
# Set your OpenRouter API key here
|
| 6 |
+
openrouter_api_key = "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"
|
|
|
|
| 7 |
|
| 8 |
+
# Initialize the OpenAI client with OpenRouter settings
|
| 9 |
+
client = OpenAI(
|
| 10 |
+
base_url="https://openrouter.ai/api/v1",
|
| 11 |
+
api_key=openrouter_api_key,
|
| 12 |
+
)
|
| 13 |
+
|
| 14 |
+
# Function to get AI response
|
| 15 |
def get_emotional_response(name, issue):
|
| 16 |
prompt = (
|
| 17 |
f"{name} is feeling emotionally low. Reason: {issue}. "
|
|
|
|
| 19 |
)
|
| 20 |
|
| 21 |
try:
|
| 22 |
+
response = client.chat.completions.create(
|
| 23 |
model="deepseek/deepseek-r1:free",
|
| 24 |
messages=[
|
| 25 |
{"role": "system", "content": "You are a warm and emotionally intelligent mental health companion."},
|
|
|
|
| 27 |
],
|
| 28 |
temperature=0.7
|
| 29 |
)
|
| 30 |
+
return response.choices[0].message.content
|
|
|
|
|
|
|
| 31 |
|
| 32 |
except Exception as e:
|
| 33 |
return f"⚠️ Error: {str(e)}"
|
| 34 |
|
| 35 |
+
# Gradio UI setup
|
| 36 |
with gr.Blocks(theme=gr.themes.Base()) as demo:
|
| 37 |
gr.Markdown("""
|
| 38 |
# 🧠 MindMate: Your Mental Health Companion
|