Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,7 +5,7 @@ import time
|
|
| 5 |
|
| 6 |
# --- CONFIGURATION ---
|
| 7 |
MODEL_A = "llama-3.1-8b-instant"
|
| 8 |
-
MODEL_B = "
|
| 9 |
|
| 10 |
def call_groq_api(model, instruction, argument):
|
| 11 |
api_key = os.getenv("GROQ_API_KEY")
|
|
@@ -18,7 +18,7 @@ def call_groq_api(model, instruction, argument):
|
|
| 18 |
"Content-Type": "application/json"
|
| 19 |
}
|
| 20 |
|
| 21 |
-
#
|
| 22 |
final_content = f"""
|
| 23 |
INSTRUCTION: {instruction}
|
| 24 |
OPPONENT SAID: "{argument}"
|
|
@@ -43,14 +43,14 @@ def call_groq_api(model, instruction, argument):
|
|
| 43 |
return f"CONNECTION ERROR: {str(e)}"
|
| 44 |
|
| 45 |
def start_debate(topic, rounds):
|
| 46 |
-
# ---
|
| 47 |
-
#
|
| 48 |
-
|
|
|
|
| 49 |
|
| 50 |
-
#
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
yield chat_log
|
| 54 |
|
| 55 |
current_argument = f"I believe {topic} is 100% true."
|
| 56 |
|
|
@@ -60,9 +60,9 @@ def start_debate(topic, rounds):
|
|
| 60 |
instruction_a = f"You are arguing IN FAVOR of {topic}."
|
| 61 |
response_a = call_groq_api(MODEL_A, instruction_a, current_argument)
|
| 62 |
|
| 63 |
-
#
|
| 64 |
-
|
| 65 |
-
yield
|
| 66 |
|
| 67 |
current_argument = response_a
|
| 68 |
time.sleep(1)
|
|
@@ -71,29 +71,27 @@ def start_debate(topic, rounds):
|
|
| 71 |
instruction_b = f"You are arguing AGAINST {topic}."
|
| 72 |
response_b = call_groq_api(MODEL_B, instruction_b, current_argument)
|
| 73 |
|
| 74 |
-
#
|
| 75 |
-
|
| 76 |
-
yield
|
| 77 |
|
| 78 |
current_argument = response_b
|
| 79 |
time.sleep(1)
|
| 80 |
|
| 81 |
# --- UI SETUP ---
|
| 82 |
-
with gr.Blocks(
|
| 83 |
gr.Markdown("# ⚔️ AI Debate Arena")
|
| 84 |
|
| 85 |
with gr.Row():
|
| 86 |
-
topic_input = gr.Textbox(label="Topic", value="
|
| 87 |
rounds_input = gr.Slider(minimum=1, maximum=6, value=2, step=1, label="Rounds")
|
| 88 |
start_btn = gr.Button("🔥 FIGHT", variant="primary")
|
| 89 |
|
| 90 |
-
# --- THE FIX: TYPE
|
| 91 |
-
|
| 92 |
-
chatbot = gr.Chatbot(label="Live Feed", type="messages", height=500)
|
| 93 |
|
| 94 |
start_btn.click(fn=start_debate, inputs=[topic_input, rounds_input], outputs=chatbot)
|
| 95 |
|
| 96 |
if __name__ == "__main__":
|
| 97 |
demo.launch()
|
| 98 |
-
|
| 99 |
|
|
|
|
| 5 |
|
| 6 |
# --- CONFIGURATION ---
|
| 7 |
MODEL_A = "llama-3.1-8b-instant"
|
| 8 |
+
MODEL_B = "llama3-70b-8192"
|
| 9 |
|
| 10 |
def call_groq_api(model, instruction, argument):
|
| 11 |
api_key = os.getenv("GROQ_API_KEY")
|
|
|
|
| 18 |
"Content-Type": "application/json"
|
| 19 |
}
|
| 20 |
|
| 21 |
+
# Combined prompt
|
| 22 |
final_content = f"""
|
| 23 |
INSTRUCTION: {instruction}
|
| 24 |
OPPONENT SAID: "{argument}"
|
|
|
|
| 43 |
return f"CONNECTION ERROR: {str(e)}"
|
| 44 |
|
| 45 |
def start_debate(topic, rounds):
|
| 46 |
+
# --- UNIVERSAL FORMAT ---
|
| 47 |
+
# We use a simple list of lists. Every version of Gradio understands this.
|
| 48 |
+
# Format: [[User_Text, Bot_Text], [User_Text, Bot_Text]]
|
| 49 |
+
chat_history = []
|
| 50 |
|
| 51 |
+
# 1. Show Topic
|
| 52 |
+
chat_history.append([f"Topic: {topic}", None])
|
| 53 |
+
yield chat_history
|
|
|
|
| 54 |
|
| 55 |
current_argument = f"I believe {topic} is 100% true."
|
| 56 |
|
|
|
|
| 60 |
instruction_a = f"You are arguing IN FAVOR of {topic}."
|
| 61 |
response_a = call_groq_api(MODEL_A, instruction_a, current_argument)
|
| 62 |
|
| 63 |
+
# Visual: Player 1 is on the LEFT
|
| 64 |
+
chat_history.append([f"🔵 Llama (Pro): {response_a}", None])
|
| 65 |
+
yield chat_history
|
| 66 |
|
| 67 |
current_argument = response_a
|
| 68 |
time.sleep(1)
|
|
|
|
| 71 |
instruction_b = f"You are arguing AGAINST {topic}."
|
| 72 |
response_b = call_groq_api(MODEL_B, instruction_b, current_argument)
|
| 73 |
|
| 74 |
+
# Visual: Player 2 is on the RIGHT
|
| 75 |
+
chat_history.append([None, f"🟠 Llama 70B (Con): {response_b}"])
|
| 76 |
+
yield chat_history
|
| 77 |
|
| 78 |
current_argument = response_b
|
| 79 |
time.sleep(1)
|
| 80 |
|
| 81 |
# --- UI SETUP ---
|
| 82 |
+
with gr.Blocks() as demo:
|
| 83 |
gr.Markdown("# ⚔️ AI Debate Arena")
|
| 84 |
|
| 85 |
with gr.Row():
|
| 86 |
+
topic_input = gr.Textbox(label="Topic", value="Pineapple belongs on Pizza")
|
| 87 |
rounds_input = gr.Slider(minimum=1, maximum=6, value=2, step=1, label="Rounds")
|
| 88 |
start_btn = gr.Button("🔥 FIGHT", variant="primary")
|
| 89 |
|
| 90 |
+
# --- THE FIX: REMOVED 'TYPE' ARGUMENT ---
|
| 91 |
+
chatbot = gr.Chatbot(label="Live Feed", height=500)
|
|
|
|
| 92 |
|
| 93 |
start_btn.click(fn=start_debate, inputs=[topic_input, rounds_input], outputs=chatbot)
|
| 94 |
|
| 95 |
if __name__ == "__main__":
|
| 96 |
demo.launch()
|
|
|
|
| 97 |
|