Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,6 +2,7 @@ import gradio as gr
|
|
| 2 |
from huggingface_hub import InferenceClient
|
| 3 |
import os
|
| 4 |
|
|
|
|
| 5 |
COUNCIL_MEMBERS = {
|
| 6 |
"Der Architekt": "meta-llama/Llama-3.3-70B-Instruct:cheapest",
|
| 7 |
"Der Glitch": "deepseek-ai/DeepSeek-V3:cheapest",
|
|
@@ -29,19 +30,20 @@ def ask_model(model_id, system_prompt, user_input):
|
|
| 29 |
return f"🚨 Error: {str(e)}"
|
| 30 |
|
| 31 |
def run_council(user_prompt, rounds):
|
| 32 |
-
#
|
| 33 |
-
history = []
|
| 34 |
-
|
|
|
|
|
|
|
| 35 |
|
| 36 |
for r in range(int(rounds)):
|
| 37 |
-
round_header = f"
|
| 38 |
-
|
| 39 |
-
history.append({"role": "assistant", "content": f"## {round_header}"})
|
| 40 |
yield history
|
| 41 |
|
| 42 |
round_notes = ""
|
| 43 |
for name, model_id in COUNCIL_MEMBERS.items():
|
| 44 |
-
system_msg = f"Du bist {name} in einem Expertenrat. Antworte
|
| 45 |
answer = ask_model(model_id, system_msg, current_context)
|
| 46 |
formatted_answer = f"**{name}**: {answer}"
|
| 47 |
|
|
@@ -49,27 +51,27 @@ def run_council(user_prompt, rounds):
|
|
| 49 |
round_notes += f"\n{formatted_answer}\n"
|
| 50 |
yield history
|
| 51 |
|
| 52 |
-
current_context += f"\nZusammenfassung
|
| 53 |
|
| 54 |
-
final_res = ask_model("mistralai/Mixtral-8x7B-Instruct-v0.1", "Moderator.", current_context)
|
| 55 |
history.append({"role": "assistant", "content": "### 🏆 FINALE ENTSCHEIDUNG"})
|
| 56 |
history.append({"role": "assistant", "content": final_res})
|
| 57 |
yield history
|
| 58 |
|
| 59 |
-
# Das UI
|
| 60 |
with gr.Blocks() as demo:
|
| 61 |
gr.Markdown("# 🏛️ Der Subraum-Stammtisch")
|
| 62 |
|
| 63 |
with gr.Row():
|
| 64 |
-
input_text = gr.Textbox(label="Input-Vektor", placeholder="
|
| 65 |
-
rounds_slider = gr.Slider(1, 3, value=1, step=1, label="Diskussionszyklen")
|
| 66 |
|
| 67 |
start_btn = gr.Button("Protokoll starten", variant="primary")
|
| 68 |
|
| 69 |
-
#
|
| 70 |
chatbot = gr.Chatbot(label="Council Protokoll", height=600, type="messages")
|
| 71 |
|
| 72 |
start_btn.click(run_council, inputs=[input_text, rounds_slider], outputs=[chatbot])
|
| 73 |
|
| 74 |
-
|
| 75 |
-
demo.launch(theme=gr.themes.Soft())
|
|
|
|
| 2 |
from huggingface_hub import InferenceClient
|
| 3 |
import os
|
| 4 |
|
| 5 |
+
# Die Ratsmitglieder
|
| 6 |
COUNCIL_MEMBERS = {
|
| 7 |
"Der Architekt": "meta-llama/Llama-3.3-70B-Instruct:cheapest",
|
| 8 |
"Der Glitch": "deepseek-ai/DeepSeek-V3:cheapest",
|
|
|
|
| 30 |
return f"🚨 Error: {str(e)}"
|
| 31 |
|
| 32 |
def run_council(user_prompt, rounds):
|
| 33 |
+
# Die Frage des Users wird direkt ins Protokoll aufgenommen
|
| 34 |
+
history = [{"role": "user", "content": user_prompt}]
|
| 35 |
+
yield history
|
| 36 |
+
|
| 37 |
+
current_context = f"Die zu diskutierende Frage lautet: {user_prompt}\n\n"
|
| 38 |
|
| 39 |
for r in range(int(rounds)):
|
| 40 |
+
round_header = f"### 🛰️ ZYKLUS {r+1} 🛰️"
|
| 41 |
+
history.append({"role": "assistant", "content": round_header})
|
|
|
|
| 42 |
yield history
|
| 43 |
|
| 44 |
round_notes = ""
|
| 45 |
for name, model_id in COUNCIL_MEMBERS.items():
|
| 46 |
+
system_msg = f"Du bist {name} in einem Expertenrat. Antworte in 2-3 Sätzen, bleib prägnant und nerdig."
|
| 47 |
answer = ask_model(model_id, system_msg, current_context)
|
| 48 |
formatted_answer = f"**{name}**: {answer}"
|
| 49 |
|
|
|
|
| 51 |
round_notes += f"\n{formatted_answer}\n"
|
| 52 |
yield history
|
| 53 |
|
| 54 |
+
current_context += f"\nZusammenfassung Zyklus {r+1}:{round_notes}"
|
| 55 |
|
| 56 |
+
final_res = ask_model("mistralai/Mixtral-8x7B-Instruct-v0.1", "Du bist der Moderator.", current_context + "\nFasse den Konsens zusammen.")
|
| 57 |
history.append({"role": "assistant", "content": "### 🏆 FINALE ENTSCHEIDUNG"})
|
| 58 |
history.append({"role": "assistant", "content": final_res})
|
| 59 |
yield history
|
| 60 |
|
| 61 |
+
# Das UI Layout
|
| 62 |
with gr.Blocks() as demo:
|
| 63 |
gr.Markdown("# 🏛️ Der Subraum-Stammtisch")
|
| 64 |
|
| 65 |
with gr.Row():
|
| 66 |
+
input_text = gr.Textbox(label="Input-Vektor (Deine Frage)", placeholder="Ist das Holodeck sicher?")
|
| 67 |
+
rounds_slider = gr.Slider(minimum=1, maximum=3, value=1, step=1, label="Diskussionszyklen")
|
| 68 |
|
| 69 |
start_btn = gr.Button("Protokoll starten", variant="primary")
|
| 70 |
|
| 71 |
+
# Hier funktioniert type="messages" jetzt fehlerfrei!
|
| 72 |
chatbot = gr.Chatbot(label="Council Protokoll", height=600, type="messages")
|
| 73 |
|
| 74 |
start_btn.click(run_council, inputs=[input_text, rounds_slider], outputs=[chatbot])
|
| 75 |
|
| 76 |
+
if __name__ == "__main__":
|
| 77 |
+
demo.launch(theme=gr.themes.Soft())
|