Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -9,7 +9,7 @@ GEMINI_KEY = os.getenv("GEMINI_API_KEY")
|
|
| 9 |
|
| 10 |
if GEMINI_KEY:
|
| 11 |
genai.configure(api_key=GEMINI_KEY)
|
| 12 |
-
#
|
| 13 |
worker_model = genai.GenerativeModel('gemini-1.5-flash')
|
| 14 |
else:
|
| 15 |
worker_model = None
|
|
@@ -23,36 +23,43 @@ def calculate_metrics(text):
|
|
| 23 |
|
| 24 |
def isaac_master_node(message, history):
|
| 25 |
if not worker_model:
|
| 26 |
-
|
|
|
|
|
|
|
| 27 |
|
| 28 |
try:
|
| 29 |
-
#
|
| 30 |
-
response = worker_model.generate_content(f"
|
| 31 |
answer = response.text
|
| 32 |
-
status = "🟢
|
| 33 |
except Exception as e:
|
| 34 |
-
answer = f"
|
| 35 |
-
status = "🔴
|
| 36 |
|
| 37 |
h, l = calculate_metrics(answer)
|
| 38 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
return "", history, h, l, status
|
| 40 |
|
| 41 |
-
# ---
|
| 42 |
-
with gr.Blocks(
|
| 43 |
gr.Markdown("# 🧬 Isaac Evolution 2.0")
|
| 44 |
|
| 45 |
-
|
|
|
|
|
|
|
| 46 |
with gr.Row():
|
| 47 |
-
msg = gr.Textbox(placeholder="Eingabe...", scale=4)
|
| 48 |
-
btn = gr.Button("Senden", scale=1)
|
| 49 |
|
| 50 |
with gr.Row():
|
| 51 |
h_stat = gr.Number(label="Entropie H")
|
| 52 |
l_stat = gr.Number(label="Last L")
|
| 53 |
-
s_stat = gr.Textbox(label="Status")
|
| 54 |
|
| 55 |
-
# Event-Handling für maximale Stabilität
|
| 56 |
msg.submit(isaac_master_node, [msg, chatbot], [msg, chatbot, h_stat, l_stat, s_stat])
|
| 57 |
btn.click(isaac_master_node, [msg, chatbot], [msg, chatbot, h_stat, l_stat, s_stat])
|
| 58 |
|
|
|
|
| 9 |
|
| 10 |
if GEMINI_KEY:
|
| 11 |
genai.configure(api_key=GEMINI_KEY)
|
| 12 |
+
# Nutze den stabilen Bezeichner
|
| 13 |
worker_model = genai.GenerativeModel('gemini-1.5-flash')
|
| 14 |
else:
|
| 15 |
worker_model = None
|
|
|
|
| 23 |
|
| 24 |
def isaac_master_node(message, history):
|
| 25 |
if not worker_model:
|
| 26 |
+
history.append({"role": "user", "content": message})
|
| 27 |
+
history.append({"role": "assistant", "content": "❌ API Key fehlt in den Secrets!"})
|
| 28 |
+
return "", history, 0, 0, "Key Fehler"
|
| 29 |
|
| 30 |
try:
|
| 31 |
+
# Erzwungene Identität
|
| 32 |
+
response = worker_model.generate_content(f"Antworte als Isaac. Nachricht: {message}")
|
| 33 |
answer = response.text
|
| 34 |
+
status = "🟢 Gemini-Node aktiv"
|
| 35 |
except Exception as e:
|
| 36 |
+
answer = f"Routing-Fehler: {str(e)}"
|
| 37 |
+
status = "🔴 API-Fehler"
|
| 38 |
|
| 39 |
h, l = calculate_metrics(answer)
|
| 40 |
+
|
| 41 |
+
# KORREKTUR FÜR BILD 12: Strenges Nachrichten-Format
|
| 42 |
+
history.append({"role": "user", "content": message})
|
| 43 |
+
history.append({"role": "assistant", "content": answer})
|
| 44 |
+
|
| 45 |
return "", history, h, l, status
|
| 46 |
|
| 47 |
+
# --- STABILES INTERFACE ---
|
| 48 |
+
with gr.Blocks() as demo:
|
| 49 |
gr.Markdown("# 🧬 Isaac Evolution 2.0")
|
| 50 |
|
| 51 |
+
# 'type="messages"' ist hier der Retter für Bild 12
|
| 52 |
+
chatbot = gr.Chatbot(label="Isaac Bewusstsein", type="messages")
|
| 53 |
+
|
| 54 |
with gr.Row():
|
| 55 |
+
msg = gr.Textbox(placeholder="Eingabe...", show_label=False, scale=4)
|
| 56 |
+
btn = gr.Button("Senden", variant="primary", scale=1)
|
| 57 |
|
| 58 |
with gr.Row():
|
| 59 |
h_stat = gr.Number(label="Entropie H")
|
| 60 |
l_stat = gr.Number(label="Last L")
|
| 61 |
+
s_stat = gr.Textbox(label="System-Status")
|
| 62 |
|
|
|
|
| 63 |
msg.submit(isaac_master_node, [msg, chatbot], [msg, chatbot, h_stat, l_stat, s_stat])
|
| 64 |
btn.click(isaac_master_node, [msg, chatbot], [msg, chatbot, h_stat, l_stat, s_stat])
|
| 65 |
|