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 |
-
# Liste der Ratsmitglieder
|
| 6 |
COUNCIL_MEMBERS = {
|
| 7 |
"Der Architekt": "meta-llama/Llama-3.3-70B-Instruct:cheapest",
|
| 8 |
"Der Glitch": "deepseek-ai/DeepSeek-V3:cheapest",
|
|
@@ -30,13 +30,14 @@ def ask_model(model_id, system_prompt, user_input):
|
|
| 30 |
return f"🚨 Error: {str(e)}"
|
| 31 |
|
| 32 |
def run_council(user_prompt, rounds):
|
|
|
|
| 33 |
history = []
|
| 34 |
current_context = f"Die ursprüngliche Frage lautet: {user_prompt}\n\n"
|
| 35 |
|
| 36 |
for r in range(int(rounds)):
|
| 37 |
round_header = f"--- RUNDE {r+1} ---"
|
| 38 |
-
#
|
| 39 |
-
history.append(
|
| 40 |
yield history
|
| 41 |
|
| 42 |
round_notes = ""
|
|
@@ -48,21 +49,20 @@ def run_council(user_prompt, rounds):
|
|
| 48 |
answer = ask_model(model_id, system_msg, current_context)
|
| 49 |
formatted_answer = f"**{name}**: {answer}"
|
| 50 |
|
| 51 |
-
history.append(
|
| 52 |
round_notes += f"\n{formatted_answer}\n"
|
| 53 |
-
yield history
|
| 54 |
|
| 55 |
current_context += f"\nZusammenfassung Runde {r+1}:{round_notes}"
|
| 56 |
|
| 57 |
# Finale Einigung
|
| 58 |
final_res = ask_model("mistralai/Mixtral-8x7B-Instruct-v0.1", "Du bist der Moderator.", current_context + "Fasse alles final zusammen.")
|
| 59 |
-
|
| 60 |
-
history.append(
|
| 61 |
-
history.append({"role": "assistant", "content": final_res})
|
| 62 |
yield history
|
| 63 |
|
| 64 |
-
# Gradio
|
| 65 |
-
with gr.Blocks() as demo:
|
| 66 |
gr.Markdown("# 🏛️ Der Subraum-Stammtisch")
|
| 67 |
gr.Markdown("> Status: Initialisiere Prompt-Plenum auf Frequenz 0x42...")
|
| 68 |
|
|
@@ -71,10 +71,9 @@ with gr.Blocks() as demo:
|
|
| 71 |
rounds_slider = gr.Slider(minimum=1, maximum=3, value=1, step=1, label="Diskussionszyklen")
|
| 72 |
|
| 73 |
start_btn = gr.Button("Protokoll starten", variant="primary")
|
| 74 |
-
# type="messages"
|
| 75 |
-
chatbot = gr.Chatbot(label="Council Protokoll", height=600
|
| 76 |
|
| 77 |
start_btn.click(run_council, inputs=[input_text, rounds_slider], outputs=[chatbot])
|
| 78 |
|
| 79 |
-
|
| 80 |
-
demo.launch(theme=gr.themes.Soft())
|
|
|
|
| 2 |
from huggingface_hub import InferenceClient
|
| 3 |
import os
|
| 4 |
|
| 5 |
+
# Liste der 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 |
+
# Gradio 5 Format: Liste von [User, Bot] Tuples
|
| 34 |
history = []
|
| 35 |
current_context = f"Die ursprüngliche Frage lautet: {user_prompt}\n\n"
|
| 36 |
|
| 37 |
for r in range(int(rounds)):
|
| 38 |
round_header = f"--- RUNDE {r+1} ---"
|
| 39 |
+
# In Gradio 5: [User-Teil, Bot-Teil]
|
| 40 |
+
history.append([None, f"## {round_header}"])
|
| 41 |
yield history
|
| 42 |
|
| 43 |
round_notes = ""
|
|
|
|
| 49 |
answer = ask_model(model_id, system_msg, current_context)
|
| 50 |
formatted_answer = f"**{name}**: {answer}"
|
| 51 |
|
| 52 |
+
history.append([None, formatted_answer])
|
| 53 |
round_notes += f"\n{formatted_answer}\n"
|
| 54 |
+
yield history
|
| 55 |
|
| 56 |
current_context += f"\nZusammenfassung Runde {r+1}:{round_notes}"
|
| 57 |
|
| 58 |
# Finale Einigung
|
| 59 |
final_res = ask_model("mistralai/Mixtral-8x7B-Instruct-v0.1", "Du bist der Moderator.", current_context + "Fasse alles final zusammen.")
|
| 60 |
+
history.append([None, "### 🏆 FINALE ENTSCHEIDUNG"])
|
| 61 |
+
history.append([None, final_res])
|
|
|
|
| 62 |
yield history
|
| 63 |
|
| 64 |
+
# Gradio 5 UI
|
| 65 |
+
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
| 66 |
gr.Markdown("# 🏛️ Der Subraum-Stammtisch")
|
| 67 |
gr.Markdown("> Status: Initialisiere Prompt-Plenum auf Frequenz 0x42...")
|
| 68 |
|
|
|
|
| 71 |
rounds_slider = gr.Slider(minimum=1, maximum=3, value=1, step=1, label="Diskussionszyklen")
|
| 72 |
|
| 73 |
start_btn = gr.Button("Protokoll starten", variant="primary")
|
| 74 |
+
# KEIN type="messages" hier für Gradio 5
|
| 75 |
+
chatbot = gr.Chatbot(label="Council Protokoll", height=600)
|
| 76 |
|
| 77 |
start_btn.click(run_council, inputs=[input_text, rounds_slider], outputs=[chatbot])
|
| 78 |
|
| 79 |
+
demo.launch()
|
|
|