Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,12 +1,13 @@
|
|
|
|
1 |
import gradio as gr
|
2 |
import openai
|
3 |
import os
|
4 |
from openai import OpenAI
|
5 |
|
6 |
-
#
|
|
|
7 |
client = OpenAI(api_key=os.getenv("openai"))
|
8 |
|
9 |
-
print("Gradio version:", gr.__version__)
|
10 |
|
11 |
conversation_history = []
|
12 |
model_name = "gpt-3.5-turbo"
|
@@ -69,72 +70,58 @@ def test_api_connection():
|
|
69 |
except Exception as e:
|
70 |
return f"❌ API Error: {str(e)}"
|
71 |
|
72 |
-
# UI
|
73 |
-
|
74 |
-
gr.
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
with gr.
|
79 |
-
gr.
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
gr.
|
93 |
-
|
94 |
-
label="Deine Nachricht",
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
fn=
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
user_input.submit(
|
120 |
-
fn=enhanced_chat_response,
|
121 |
-
inputs=[user_input, max_tokens, temperature, top_p],
|
122 |
-
outputs=[user_input, bot_response, chat_history]
|
123 |
-
)
|
124 |
-
|
125 |
-
reset_btn.click(
|
126 |
-
fn=reset_conversation,
|
127 |
-
outputs=[bot_response, chat_history]
|
128 |
-
)
|
129 |
-
|
130 |
-
api_test_btn.click(
|
131 |
-
fn=test_api_connection,
|
132 |
-
outputs=[api_status]
|
133 |
-
)
|
134 |
|
135 |
if __name__ == "__main__":
|
|
|
136 |
if not os.getenv("openai"):
|
137 |
print("❌ FEHLER: openai Umgebungsvariable ist nicht gesetzt!")
|
138 |
else:
|
139 |
print("✅ OpenAI API Key gefunden")
|
140 |
-
demo.queue().launch()
|
|
|
1 |
+
|
2 |
import gradio as gr
|
3 |
import openai
|
4 |
import os
|
5 |
from openai import OpenAI
|
6 |
|
7 |
+
print("Gradio version:", gr.__version__) # <-- This prints the current version
|
8 |
+
|
9 |
client = OpenAI(api_key=os.getenv("openai"))
|
10 |
|
|
|
11 |
|
12 |
conversation_history = []
|
13 |
model_name = "gpt-3.5-turbo"
|
|
|
70 |
except Exception as e:
|
71 |
return f"❌ API Error: {str(e)}"
|
72 |
|
73 |
+
# Build the UI
|
74 |
+
def build_app():
|
75 |
+
with gr.Blocks() as demo:
|
76 |
+
gr.Markdown("## 🧠 Depression Training Simulator")
|
77 |
+
gr.Markdown("**Übe realistische Gespräche mit einem 16-jährigen Teenager mit Depressionen.**")
|
78 |
+
|
79 |
+
with gr.Row():
|
80 |
+
with gr.Column(scale=1):
|
81 |
+
gr.Markdown("### ⚙️ Einstellungen")
|
82 |
+
max_tokens = gr.Slider(50, 500, value=200, step=10, label="Max. Antwortlänge")
|
83 |
+
temperature = gr.Slider(0.7, 1.3, value=1.0, step=0.1, label="Kreativität (Temperature)")
|
84 |
+
top_p = gr.Slider(0.5, 1.0, value=0.9, step=0.05, label="Top-p (Fokus)")
|
85 |
+
|
86 |
+
gr.Markdown("### 🔧 API Status")
|
87 |
+
api_status = gr.Textbox(label="Status", value="")
|
88 |
+
api_test_btn = gr.Button("API testen")
|
89 |
+
|
90 |
+
gr.Markdown("### 🔄 Aktionen")
|
91 |
+
reset_btn = gr.Button("Neues Gespräch")
|
92 |
+
|
93 |
+
with gr.Column(scale=2):
|
94 |
+
gr.Markdown("### 💬 Gespräch")
|
95 |
+
user_input = gr.Textbox(label="Deine Nachricht", placeholder="Hallo, wie geht es dir heute?", lines=2)
|
96 |
+
send_btn = gr.Button("📨 Senden")
|
97 |
+
|
98 |
+
bot_response = gr.Textbox(label="Antwort", value="", lines=3)
|
99 |
+
chat_history = gr.Textbox(label="Gesprächsverlauf", value="", lines=15)
|
100 |
+
|
101 |
+
# Event bindings
|
102 |
+
send_btn.click(
|
103 |
+
fn=enhanced_chat_response,
|
104 |
+
inputs=[user_input, max_tokens, temperature, top_p],
|
105 |
+
outputs=[user_input, bot_response, chat_history]
|
106 |
+
)
|
107 |
+
|
108 |
+
user_input.submit(
|
109 |
+
fn=enhanced_chat_response,
|
110 |
+
inputs=[user_input, max_tokens, temperature, top_p],
|
111 |
+
outputs=[user_input, bot_response, chat_history]
|
112 |
+
)
|
113 |
+
|
114 |
+
reset_btn.click(fn=reset_conversation, outputs=[bot_response, chat_history])
|
115 |
+
api_test_btn.click(fn=test_api_connection, outputs=[api_status])
|
116 |
+
|
117 |
+
return demo
|
118 |
+
|
119 |
+
demo = build_app()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
120 |
|
121 |
if __name__ == "__main__":
|
122 |
+
print("Gradio version:", gr.__version__)
|
123 |
if not os.getenv("openai"):
|
124 |
print("❌ FEHLER: openai Umgebungsvariable ist nicht gesetzt!")
|
125 |
else:
|
126 |
print("✅ OpenAI API Key gefunden")
|
127 |
+
demo.queue().launch()
|