ai-tomoni commited on
Commit
4b4858d
·
verified ·
1 Parent(s): fcf96df

Update app.py

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