Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,7 +2,7 @@ import gradio as gr
|
|
| 2 |
from huggingface_hub import InferenceClient
|
| 3 |
import os
|
| 4 |
|
| 5 |
-
# Die Ratsmitglieder
|
| 6 |
COUNCIL_MEMBERS = {
|
| 7 |
"Mitglied 1 (Llama3.3-70B)": ("meta-llama/Llama-3.3-70B-Instruct", "Fokus auf Philosophie, Logik und das große Ganze."),
|
| 8 |
"Mitglied 2 (DeepSeekV3)": ("deepseek-ai/DeepSeek-V3", "Fokus auf harte Fakten, Mathematik, Physik und Naturwissenschaften."),
|
|
@@ -23,8 +23,8 @@ def ask_model(model_id, system_prompt, user_input):
|
|
| 23 |
for chunk in client.chat_completion(
|
| 24 |
model=model_id,
|
| 25 |
messages=messages,
|
| 26 |
-
max_tokens=
|
| 27 |
-
temperature=0.7,
|
| 28 |
stream=True
|
| 29 |
):
|
| 30 |
if hasattr(chunk, "choices") and chunk.choices and len(chunk.choices) > 0:
|
|
@@ -32,9 +32,13 @@ def ask_model(model_id, system_prompt, user_input):
|
|
| 32 |
|
| 33 |
return response
|
| 34 |
except Exception as e:
|
| 35 |
-
return f"🚨 Error: {str(e)}"
|
| 36 |
|
| 37 |
def run_council(user_prompt, rounds):
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
history = [{"role": "user", "content": user_prompt}]
|
| 39 |
yield history
|
| 40 |
|
|
@@ -42,7 +46,7 @@ def run_council(user_prompt, rounds):
|
|
| 42 |
|
| 43 |
# --- PHASE 1: DAS PLENUM DISKUTIERT ---
|
| 44 |
for r in range(int(rounds)):
|
| 45 |
-
round_header = f"###
|
| 46 |
history.append({"role": "assistant", "content": round_header})
|
| 47 |
yield history
|
| 48 |
|
|
@@ -55,7 +59,7 @@ def run_council(user_prompt, rounds):
|
|
| 55 |
)
|
| 56 |
|
| 57 |
if discussion_history == "":
|
| 58 |
-
current_prompt = f"Das Thema lautet: '{user_prompt}'. Eröffne die Diskussion."
|
| 59 |
else:
|
| 60 |
current_prompt = (
|
| 61 |
f"Das Thema lautet: '{user_prompt}'.\n\n"
|
|
@@ -72,7 +76,7 @@ def run_council(user_prompt, rounds):
|
|
| 72 |
yield history
|
| 73 |
|
| 74 |
# --- PHASE 2: VORARBEIT DES MODERATORS (KONSENS FINDEN) ---
|
| 75 |
-
history.append({"role": "assistant", "content": "###
|
| 76 |
yield history
|
| 77 |
|
| 78 |
prep_prompt = (
|
|
@@ -84,7 +88,7 @@ def run_council(user_prompt, rounds):
|
|
| 84 |
yield history
|
| 85 |
|
| 86 |
# --- PHASE 3: FINALE UMSETZUNG (BENUTZERAUFTRAG ERFÜLLEN) ---
|
| 87 |
-
history.append({"role": "assistant", "content": "###
|
| 88 |
yield history
|
| 89 |
|
| 90 |
final_prompt = (
|
|
@@ -97,19 +101,60 @@ def run_council(user_prompt, rounds):
|
|
| 97 |
history.append({"role": "assistant", "content": final_res})
|
| 98 |
yield history
|
| 99 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 100 |
# Das UI Layout
|
| 101 |
-
with gr.Blocks() as demo:
|
| 102 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 103 |
|
| 104 |
with gr.Row():
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 109 |
|
| 110 |
-
chatbot = gr.Chatbot(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 111 |
|
|
|
|
|
|
|
| 112 |
start_btn.click(run_council, inputs=[input_text, rounds_slider], outputs=[chatbot])
|
| 113 |
|
| 114 |
if __name__ == "__main__":
|
| 115 |
-
demo.launch(
|
|
|
|
| 2 |
from huggingface_hub import InferenceClient
|
| 3 |
import os
|
| 4 |
|
| 5 |
+
# Die Ratsmitglieder
|
| 6 |
COUNCIL_MEMBERS = {
|
| 7 |
"Mitglied 1 (Llama3.3-70B)": ("meta-llama/Llama-3.3-70B-Instruct", "Fokus auf Philosophie, Logik und das große Ganze."),
|
| 8 |
"Mitglied 2 (DeepSeekV3)": ("deepseek-ai/DeepSeek-V3", "Fokus auf harte Fakten, Mathematik, Physik und Naturwissenschaften."),
|
|
|
|
| 23 |
for chunk in client.chat_completion(
|
| 24 |
model=model_id,
|
| 25 |
messages=messages,
|
| 26 |
+
max_tokens=600,
|
| 27 |
+
temperature=0.7,
|
| 28 |
stream=True
|
| 29 |
):
|
| 30 |
if hasattr(chunk, "choices") and chunk.choices and len(chunk.choices) > 0:
|
|
|
|
| 32 |
|
| 33 |
return response
|
| 34 |
except Exception as e:
|
| 35 |
+
return f"🚨 System Error ({model_id}): {str(e)}"
|
| 36 |
|
| 37 |
def run_council(user_prompt, rounds):
|
| 38 |
+
if not user_prompt:
|
| 39 |
+
yield [{"role": "assistant", "content": "Bitte gib ein Thema oder eine Frage ein, um die Sitzung zu starten."}]
|
| 40 |
+
return
|
| 41 |
+
|
| 42 |
history = [{"role": "user", "content": user_prompt}]
|
| 43 |
yield history
|
| 44 |
|
|
|
|
| 46 |
|
| 47 |
# --- PHASE 1: DAS PLENUM DISKUTIERT ---
|
| 48 |
for r in range(int(rounds)):
|
| 49 |
+
round_header = f"### ZYKLUS {r+1} - EXPERTENDEBATTE"
|
| 50 |
history.append({"role": "assistant", "content": round_header})
|
| 51 |
yield history
|
| 52 |
|
|
|
|
| 59 |
)
|
| 60 |
|
| 61 |
if discussion_history == "":
|
| 62 |
+
current_prompt = f"Das Thema lautet: '{user_prompt}'. Eröffne die Diskussion aus deiner Fachperspektive."
|
| 63 |
else:
|
| 64 |
current_prompt = (
|
| 65 |
f"Das Thema lautet: '{user_prompt}'.\n\n"
|
|
|
|
| 76 |
yield history
|
| 77 |
|
| 78 |
# --- PHASE 2: VORARBEIT DES MODERATORS (KONSENS FINDEN) ---
|
| 79 |
+
history.append({"role": "assistant", "content": "### MODERATOR: ANALYSE DER DISKUSSION"})
|
| 80 |
yield history
|
| 81 |
|
| 82 |
prep_prompt = (
|
|
|
|
| 88 |
yield history
|
| 89 |
|
| 90 |
# --- PHASE 3: FINALE UMSETZUNG (BENUTZERAUFTRAG ERFÜLLEN) ---
|
| 91 |
+
history.append({"role": "assistant", "content": "### FINALE AUSGABE (AUFTRAG ERFÜLLT)"})
|
| 92 |
yield history
|
| 93 |
|
| 94 |
final_prompt = (
|
|
|
|
| 101 |
history.append({"role": "assistant", "content": final_res})
|
| 102 |
yield history
|
| 103 |
|
| 104 |
+
|
| 105 |
+
# --- VALANTIC BRANDING THEME ---
|
| 106 |
+
valantic_theme = gr.themes.Soft(
|
| 107 |
+
primary_hue="indigo", # Grundfarbe für Slider etc.
|
| 108 |
+
font=[gr.themes.GoogleFont("Inter"), "ui-sans-serif", "system-ui", "sans-serif"], # Cleane Corporate Font
|
| 109 |
+
).set(
|
| 110 |
+
button_primary_background_fill="#4241A6", # valantic Indigo (Ungefährer Wert aus Bild)
|
| 111 |
+
button_primary_background_fill_hover="#2D2C73",
|
| 112 |
+
button_primary_text_color="white",
|
| 113 |
+
block_title_text_color="#FF5A4D", # valantic Korallrot
|
| 114 |
+
block_label_text_color="#4241A6",
|
| 115 |
+
body_text_color="#1F2937",
|
| 116 |
+
color_accent_soft="#FFEBE8", # Zartes Korallrot für Hervorhebungen
|
| 117 |
+
)
|
| 118 |
+
|
| 119 |
# Das UI Layout
|
| 120 |
+
with gr.Blocks(theme=valantic_theme) as demo:
|
| 121 |
+
# Cleane, professionelle Header-Sektion ohne Emojis
|
| 122 |
+
gr.HTML("""
|
| 123 |
+
<div style="text-align: center; margin-bottom: 2rem;">
|
| 124 |
+
<h1 style="color: #FF5A4D; font-weight: 800; font-size: 2.5rem; margin-bottom: 0.5rem;">PromptPlenum42</h1>
|
| 125 |
+
<p style="color: #4B5563; font-size: 1.1rem;">AI-Driven Multi-Agent Consensus System</p>
|
| 126 |
+
</div>
|
| 127 |
+
""")
|
| 128 |
|
| 129 |
with gr.Row():
|
| 130 |
+
with gr.Column(scale=4):
|
| 131 |
+
input_text = gr.Textbox(
|
| 132 |
+
label="Benutzerauftrag / Thema",
|
| 133 |
+
placeholder="z.B. 'Sollten wir KI regulieren? Schreibe einen LinkedIn Post dazu.'",
|
| 134 |
+
lines=2
|
| 135 |
+
)
|
| 136 |
+
with gr.Column(scale=1):
|
| 137 |
+
rounds_slider = gr.Slider(
|
| 138 |
+
minimum=1, maximum=3, value=1, step=1,
|
| 139 |
+
label="Diskussionszyklen"
|
| 140 |
+
)
|
| 141 |
+
|
| 142 |
+
with gr.Row():
|
| 143 |
+
start_btn = gr.Button("Sitzung starten", variant="primary", size="lg")
|
| 144 |
+
clear_btn = gr.ClearButton(components=[input_text], value="Protokoll leeren", size="lg")
|
| 145 |
|
| 146 |
+
chatbot = gr.Chatbot(
|
| 147 |
+
label="Sitzungsprotokoll",
|
| 148 |
+
height=650,
|
| 149 |
+
show_copy_button=True # Fügt einen praktischen Kopier-Button für das Endergebnis hinzu
|
| 150 |
+
)
|
| 151 |
+
|
| 152 |
+
# Clear Button leert auch den Chatbot
|
| 153 |
+
clear_btn.add(chatbot)
|
| 154 |
|
| 155 |
+
# Enter-Taste im Textfeld startet die Diskussion ebenfalls
|
| 156 |
+
input_text.submit(run_council, inputs=[input_text, rounds_slider], outputs=[chatbot])
|
| 157 |
start_btn.click(run_council, inputs=[input_text, rounds_slider], outputs=[chatbot])
|
| 158 |
|
| 159 |
if __name__ == "__main__":
|
| 160 |
+
demo.launch()
|