WaveOAK commited on
Commit
ddce0ca
·
verified ·
1 Parent(s): 8e3024b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -21
app.py CHANGED
@@ -5,7 +5,7 @@ import time
5
 
6
  # --- CONFIGURATION ---
7
  MODEL_A = "llama-3.1-8b-instant"
8
- MODEL_B = "llama-3.1-8b-instant"
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
- # 1. We create a combined prompt to avoid history errors
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
- # --- THE FIX: NEW DATA FORMAT ---
47
- # Gradio now expects a list of dictionaries, not tuples!
48
- chat_log = []
 
49
 
50
- # Initial State
51
- chat_log.append({"role": "user", "content": f"Topic: {topic}"})
52
- chat_log.append({"role": "assistant", "content": "I am ready to debate."})
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
- # Add to chat log in the new format
64
- chat_log.append({"role": "user", "content": f"🔵 Llama (Pro): {response_a}"})
65
- yield chat_log
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
- # Add to chat log in the new format
75
- chat_log.append({"role": "assistant", "content": f"🟠 Opponent (Con): {response_b}"})
76
- yield chat_log
77
 
78
  current_argument = response_b
79
  time.sleep(1)
80
 
81
  # --- UI SETUP ---
82
- with gr.Blocks(theme=gr.themes.Soft()) as demo:
83
  gr.Markdown("# ⚔️ AI Debate Arena")
84
 
85
  with gr.Row():
86
- topic_input = gr.Textbox(label="Topic", value="Cats are better than Dogs")
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="MESSAGES" ---
91
- # We explicitly tell Gradio we are using the new format
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