Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,14 +1,13 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import openai
|
| 3 |
import os
|
| 4 |
-
import
|
| 5 |
|
| 6 |
-
# OpenAI
|
| 7 |
-
|
| 8 |
-
current_model = "gpt-3.5-turbo" # oder "gpt-4"
|
| 9 |
|
| 10 |
-
openai.api_key = OPENAI_API_KEY
|
| 11 |
conversation_history = []
|
|
|
|
| 12 |
|
| 13 |
def enhanced_chat_response(user_input, max_tokens, temperature, top_p):
|
| 14 |
if not user_input.strip():
|
|
@@ -28,8 +27,8 @@ def enhanced_chat_response(user_input, max_tokens, temperature, top_p):
|
|
| 28 |
messages.append(current_message)
|
| 29 |
|
| 30 |
try:
|
| 31 |
-
response =
|
| 32 |
-
model=
|
| 33 |
messages=messages,
|
| 34 |
max_tokens=min(max_tokens, 500),
|
| 35 |
temperature=temperature,
|
|
@@ -37,7 +36,7 @@ def enhanced_chat_response(user_input, max_tokens, temperature, top_p):
|
|
| 37 |
frequency_penalty=0.1,
|
| 38 |
presence_penalty=0.1
|
| 39 |
)
|
| 40 |
-
response_text = response
|
| 41 |
except Exception as e:
|
| 42 |
print("API Error:", e)
|
| 43 |
response_text = "*schweigt und starrt auf den Boden*"
|
|
@@ -59,8 +58,8 @@ def reset_conversation():
|
|
| 59 |
|
| 60 |
def test_api_connection():
|
| 61 |
try:
|
| 62 |
-
response =
|
| 63 |
-
model=
|
| 64 |
messages=[{"role": "user", "content": "Hi"}],
|
| 65 |
max_tokens=10
|
| 66 |
)
|
|
@@ -72,7 +71,6 @@ def test_api_connection():
|
|
| 72 |
with gr.Blocks() as demo:
|
| 73 |
gr.Markdown("## 🧠 Depression Training Simulator")
|
| 74 |
gr.Markdown("**Übe realistische Gespräche mit einem 16-jährigen Teenager mit Depressionen.**")
|
| 75 |
-
gr.Markdown("_Debug-Informationen erscheinen im Terminal._")
|
| 76 |
|
| 77 |
with gr.Row():
|
| 78 |
with gr.Column(scale=1):
|
|
@@ -133,8 +131,8 @@ with gr.Blocks() as demo:
|
|
| 133 |
)
|
| 134 |
|
| 135 |
if __name__ == "__main__":
|
| 136 |
-
if not OPENAI_API_KEY:
|
| 137 |
print("❌ FEHLER: OPENAI_API_KEY Umgebungsvariable ist nicht gesetzt!")
|
| 138 |
else:
|
| 139 |
print("✅ OpenAI API Key gefunden")
|
| 140 |
-
demo.launch(share=False)
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import openai
|
| 3 |
import os
|
| 4 |
+
from openai import OpenAI
|
| 5 |
|
| 6 |
+
# Initialisiere OpenAI-Client mit API Key
|
| 7 |
+
client = OpenAI(api_key=os.getenv("OPENAI_API_KEY"))
|
|
|
|
| 8 |
|
|
|
|
| 9 |
conversation_history = []
|
| 10 |
+
model_name = "gpt-3.5-turbo" # oder "gpt-4"
|
| 11 |
|
| 12 |
def enhanced_chat_response(user_input, max_tokens, temperature, top_p):
|
| 13 |
if not user_input.strip():
|
|
|
|
| 27 |
messages.append(current_message)
|
| 28 |
|
| 29 |
try:
|
| 30 |
+
response = client.chat.completions.create(
|
| 31 |
+
model=model_name,
|
| 32 |
messages=messages,
|
| 33 |
max_tokens=min(max_tokens, 500),
|
| 34 |
temperature=temperature,
|
|
|
|
| 36 |
frequency_penalty=0.1,
|
| 37 |
presence_penalty=0.1
|
| 38 |
)
|
| 39 |
+
response_text = response.choices[0].message.content
|
| 40 |
except Exception as e:
|
| 41 |
print("API Error:", e)
|
| 42 |
response_text = "*schweigt und starrt auf den Boden*"
|
|
|
|
| 58 |
|
| 59 |
def test_api_connection():
|
| 60 |
try:
|
| 61 |
+
response = client.chat.completions.create(
|
| 62 |
+
model=model_name,
|
| 63 |
messages=[{"role": "user", "content": "Hi"}],
|
| 64 |
max_tokens=10
|
| 65 |
)
|
|
|
|
| 71 |
with gr.Blocks() as demo:
|
| 72 |
gr.Markdown("## 🧠 Depression Training Simulator")
|
| 73 |
gr.Markdown("**Übe realistische Gespräche mit einem 16-jährigen Teenager mit Depressionen.**")
|
|
|
|
| 74 |
|
| 75 |
with gr.Row():
|
| 76 |
with gr.Column(scale=1):
|
|
|
|
| 131 |
)
|
| 132 |
|
| 133 |
if __name__ == "__main__":
|
| 134 |
+
if not os.getenv("OPENAI_API_KEY"):
|
| 135 |
print("❌ FEHLER: OPENAI_API_KEY Umgebungsvariable ist nicht gesetzt!")
|
| 136 |
else:
|
| 137 |
print("✅ OpenAI API Key gefunden")
|
| 138 |
+
demo.launch(share=False)
|