Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,13 +2,16 @@ import gradio as gr
|
|
| 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
|
| 8 |
-
"Der Glitch": "deepseek-ai/DeepSeek-V3
|
| 9 |
-
"Der Debugger": "Qwen/Qwen2.5-Coder-32B-Instruct
|
| 10 |
}
|
| 11 |
|
|
|
|
|
|
|
|
|
|
| 12 |
client = InferenceClient(token=os.getenv("HF_TOKEN"))
|
| 13 |
|
| 14 |
def ask_model(model_id, system_prompt, user_input):
|
|
@@ -18,19 +21,21 @@ def ask_model(model_id, system_prompt, user_input):
|
|
| 18 |
]
|
| 19 |
response = ""
|
| 20 |
try:
|
| 21 |
-
for
|
| 22 |
model=model_id,
|
| 23 |
messages=messages,
|
| 24 |
max_tokens=500,
|
| 25 |
stream=True
|
| 26 |
):
|
| 27 |
-
|
|
|
|
|
|
|
|
|
|
| 28 |
return response
|
| 29 |
except Exception as e:
|
| 30 |
return f"🚨 Error: {str(e)}"
|
| 31 |
|
| 32 |
def run_council(user_prompt, rounds):
|
| 33 |
-
# Gradio 6 Standard: Dictionary-Format
|
| 34 |
history = [{"role": "user", "content": user_prompt}]
|
| 35 |
yield history
|
| 36 |
|
|
@@ -53,22 +58,21 @@ def run_council(user_prompt, rounds):
|
|
| 53 |
|
| 54 |
current_context += f"\nZusammenfassung Zyklus {r+1}:{round_notes}"
|
| 55 |
|
| 56 |
-
final_res = ask_model(
|
| 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("# 🏛️
|
| 64 |
|
| 65 |
with gr.Row():
|
| 66 |
-
input_text = gr.Textbox(label="
|
| 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 |
-
# Der magische Fix für Gradio 6.6.0: KEIN type="messages" mehr nötig!
|
| 72 |
chatbot = gr.Chatbot(label="Council Protokoll", height=600)
|
| 73 |
|
| 74 |
start_btn.click(run_council, inputs=[input_text, rounds_slider], outputs=[chatbot])
|
|
|
|
| 2 |
from huggingface_hub import InferenceClient
|
| 3 |
import os
|
| 4 |
|
| 5 |
+
# Die Ratsmitglieder - Sicher ohne Provider-Suffixe für maximale API-Kompatibilität
|
| 6 |
COUNCIL_MEMBERS = {
|
| 7 |
+
"Der Architekt": "meta-llama/Llama-3.3-70B-Instruct",
|
| 8 |
+
"Der Glitch": "deepseek-ai/DeepSeek-V3",
|
| 9 |
+
"Der Debugger": "Qwen/Qwen2.5-Coder-32B-Instruct"
|
| 10 |
}
|
| 11 |
|
| 12 |
+
# Ein garantierter Chat-Model-Moderator
|
| 13 |
+
MODERATOR_MODEL = "meta-llama/Meta-Llama-3-8B-Instruct"
|
| 14 |
+
|
| 15 |
client = InferenceClient(token=os.getenv("HF_TOKEN"))
|
| 16 |
|
| 17 |
def ask_model(model_id, system_prompt, user_input):
|
|
|
|
| 21 |
]
|
| 22 |
response = ""
|
| 23 |
try:
|
| 24 |
+
for chunk in client.chat_completion(
|
| 25 |
model=model_id,
|
| 26 |
messages=messages,
|
| 27 |
max_tokens=500,
|
| 28 |
stream=True
|
| 29 |
):
|
| 30 |
+
# DER FIX: Wir prüfen, ob der Provider-Chunk wirklich Text enthält, bevor wir ihn lesen
|
| 31 |
+
if hasattr(chunk, "choices") and chunk.choices and len(chunk.choices) > 0:
|
| 32 |
+
response += chunk.choices[0].delta.content or ""
|
| 33 |
+
|
| 34 |
return response
|
| 35 |
except Exception as e:
|
| 36 |
return f"🚨 Error: {str(e)}"
|
| 37 |
|
| 38 |
def run_council(user_prompt, rounds):
|
|
|
|
| 39 |
history = [{"role": "user", "content": user_prompt}]
|
| 40 |
yield history
|
| 41 |
|
|
|
|
| 58 |
|
| 59 |
current_context += f"\nZusammenfassung Zyklus {r+1}:{round_notes}"
|
| 60 |
|
| 61 |
+
final_res = ask_model(MODERATOR_MODEL, "Du bist der Moderator.", current_context + "\nFasse den Konsens in 3 Sätzen zusammen.")
|
| 62 |
history.append({"role": "assistant", "content": "### 🏆 FINALE ENTSCHEIDUNG"})
|
| 63 |
history.append({"role": "assistant", "content": final_res})
|
| 64 |
yield history
|
| 65 |
|
| 66 |
# Das UI Layout
|
| 67 |
with gr.Blocks() as demo:
|
| 68 |
+
gr.Markdown("# 🏛️ PromptPlenum42")
|
| 69 |
|
| 70 |
with gr.Row():
|
| 71 |
+
input_text = gr.Textbox(label="Deine Frage", placeholder="Ist das Holodeck sicher?")
|
| 72 |
rounds_slider = gr.Slider(minimum=1, maximum=3, value=1, step=1, label="Diskussionszyklen")
|
| 73 |
|
| 74 |
start_btn = gr.Button("Protokoll starten", variant="primary")
|
| 75 |
|
|
|
|
| 76 |
chatbot = gr.Chatbot(label="Council Protokoll", height=600)
|
| 77 |
|
| 78 |
start_btn.click(run_council, inputs=[input_text, rounds_slider], outputs=[chatbot])
|