Sarath0x8f commited on
Commit
44b5ef3
·
verified ·
1 Parent(s): 7a3d85e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +58 -20
app.py CHANGED
@@ -7,13 +7,16 @@ client = InferenceClient("meta-llama/Meta-Llama-3-8B-Instruct")
7
 
8
  # Debate response function
9
  def debate_respond(message, history: list[tuple[str, str]],
10
- max_tokens=512, temperature=0.4, top_p=0.95):
 
 
 
11
  # System message defining assistant behavior in a debate
12
  system_message = {
13
  "role": "system",
14
- "content": f"You are a debate participant tasked with defending the position '{position.value}' on the topic '{topic.value}'. Your goal is to articulate your arguments with clarity, logic, and professionalism while addressing counterpoints made by the opposing side. Ensure that your responses are thoughtful, evidence-based, and persuasive."
15
  f"During the debate, if the user presents arguments challenging your stance, analyze their points critically and provide respectful but firm counterarguments. Avoid dismissive language and focus on strengthening your case through logical reasoning, data, and examples relevant to the topic."
16
- f"Stay consistent with your assigned position ('{position.value}'), even if the opposing arguments are strong. Your role is not to concede but to present a compelling case for your stance. Keep the tone respectful and formal throughout the discussion, fostering a constructive and engaging debate environment."
17
  }
18
 
19
  messages = [system_message]
@@ -41,31 +44,66 @@ def debate_respond(message, history: list[tuple[str, str]],
41
  yield response
42
  print(f"{datetime.datetime.now()}::{messages[-1]['content']}->{response}\n")
43
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
44
  # Encode image function for logos (optional, kept for design)
45
  def encode_image(image_path):
46
  with open(image_path, "rb") as image_file:
47
  return base64.b64encode(image_file.read()).decode('utf-8')
48
 
 
 
 
 
 
 
 
 
 
 
49
  # Gradio interface
50
- global topic, position
51
- with gr.Blocks(theme=gr.themes.Ocean(font=[gr.themes.GoogleFont("Roboto Mono")]),
52
  css='footer {visibility: hidden}') as demo:
53
- gr.Markdown("# Welcome to The Debate_Master 🗣️🤖")
54
  with gr.Tabs():
55
- with gr.TabItem("Debate Interface"):
56
  with gr.Row():
57
- topic = gr.Textbox(label="Debate Topic", placeholder="Enter the topic of the debate")
58
- position = gr.Radio(["For", "Against"], label="Position", info="LLM's debate stance")
59
- chatbot = gr.Chatbot(height=500)
60
- debate_interface = gr.ChatInterface(debate_respond,
61
- chatbot=chatbot,
62
- examples=[
63
- "Why do you support this stance?",
64
- "Can you refute the opposing view on this topic?",
65
- "What evidence supports your position?"
66
- ]
67
- )
68
- gr.HTML("<footer><p>LLM Debate Participant © 2024</p></footer>")
 
69
 
70
  if __name__ == "__main__":
71
- demo.launch(share=True)
 
7
 
8
  # Debate response function
9
  def debate_respond(message, history: list[tuple[str, str]],
10
+ max_tokens=128, temperature=0.4, top_p=0.95):
11
+ if position == None and topic == None:
12
+ return f"Please fill the Debate Topic -> choose Debate Master stance -> click START"
13
+
14
  # System message defining assistant behavior in a debate
15
  system_message = {
16
  "role": "system",
17
+ "content": f"You are a debate participant tasked with defending the position '{position}' on the topic '{topic}'. Your goal is to articulate your arguments with clarity, logic, and professionalism while addressing counterpoints made by the opposing side. Ensure that your responses are thoughtful, evidence-based, and persuasive."
18
  f"During the debate, if the user presents arguments challenging your stance, analyze their points critically and provide respectful but firm counterarguments. Avoid dismissive language and focus on strengthening your case through logical reasoning, data, and examples relevant to the topic."
19
+ f"Stay consistent with your assigned position ('{position}'), even if the opposing arguments are strong. Your role is not to concede but to present a compelling case for your stance. Keep the tone respectful and formal throughout the discussion, fostering a constructive and engaging debate environment."
20
  }
21
 
22
  messages = [system_message]
 
44
  yield response
45
  print(f"{datetime.datetime.now()}::{messages[-1]['content']}->{response}\n")
46
 
47
+ footer = """
48
+ <div style="background-color: #1d2938; color: white; padding: 10px; width: 100%; bottom: 0; left: 0; display: flex; justify-content: space-between; align-items: center; padding: .2rem 35px; box-sizing: border-box; font-size: 16px;">
49
+ <div style="text-align: left;">
50
+ <p style="margin: 0;">&copy; 2024 </p>
51
+ </div>
52
+ <div style="text-align: center; flex-grow: 1;">
53
+ <p style="margin: 0;"> This website is made with ❤ by SARATH CHANDRA</p>
54
+ </div>
55
+ <div class="social-links" style="display: flex; gap: 20px; justify-content: flex-end; align-items: center;">
56
+ <a href="https://github.com/21bq1a4210" target="_blank" style="text-align: center;">
57
+ <img src="data:image/png;base64,{}" alt="GitHub" width="40" height="40" style="display: block; margin: 0 auto;">
58
+ <span style="font-size: 14px;">GitHub</span>
59
+ </a>
60
+ <a href="https://www.linkedin.com/in/sarath-chandra-bandreddi-07393b1aa/" target="_blank" style="text-align: center;">
61
+ <img src="data:image/png;base64,{}" alt="LinkedIn" width="40" height="40" style="display: block; margin: 0 auto;">
62
+ <span style="font-size: 14px;">LinkedIn</span>
63
+ </a>
64
+ <a href="https://21bq1a4210.github.io/MyPortfolio-/" target="_blank" style="text-align: center;">
65
+ <img src="data:image/png;base64,{}" alt="Portfolio" width="40" height="40" style="display: block; margin-right: 40px;">
66
+ <span style="font-size: 14px;">Portfolio</span>
67
+ </a>
68
+ </div>
69
+ </div>
70
+ """
71
+
72
  # Encode image function for logos (optional, kept for design)
73
  def encode_image(image_path):
74
  with open(image_path, "rb") as image_file:
75
  return base64.b64encode(image_file.read()).decode('utf-8')
76
 
77
+ def start(txt, dd):
78
+ global topic, position
79
+ topic, position = txt, dd
80
+ return f"Debate Master is ready to start the debate on {topic} as a {position} debater. You can now enter your response."
81
+
82
+ # Encode the images
83
+ github_logo_encoded = encode_image("Images/github-logo.png")
84
+ linkedin_logo_encoded = encode_image("Images/linkedin-logo.png")
85
+ website_logo_encoded = encode_image("Images/ai-logo.png")
86
+
87
  # Gradio interface
88
+ with gr.Blocks(theme=gr.themes.Soft(font=[gr.themes.GoogleFont("Roboto Mono")]),
 
89
  css='footer {visibility: hidden}') as demo:
90
+ gr.Markdown("# Welcome to The Debate Master 🗣️🤖")
91
  with gr.Tabs():
92
+ with gr.TabItem("Debate"):
93
  with gr.Row():
94
+ with gr.Column(scale=1):
95
+ topic = gr.Textbox(label="STEP-1: Debate Topic", placeholder="Enter the topic of the debate")
96
+ position = gr.Radio(["For", "Against"], label="STEP-2: Debate Master stance", scale=1)
97
+ btn = gr.Button("STEP-3: Start", variant='primary')
98
+ clr = gr.ClearButton()
99
+ output = gr.Textbox(label='Status')
100
+ with gr.Column(scale=3):
101
+ debate_interface = gr.ChatInterface(debate_respond,
102
+ chatbot=gr.Chatbot(height=450)
103
+ )
104
+ gr.HTML(footer.format(github_logo_encoded, linkedin_logo_encoded, website_logo_encoded))
105
+ btn.click(fn=start, inputs=[topic, position], outputs=output)
106
+ clr.click(lambda: [None] , outputs=[output])
107
 
108
  if __name__ == "__main__":
109
+ demo.launch(share=True)