Spaces:
Sleeping
Sleeping
Upload folder using huggingface_hub
Browse files- .github/workflows/update_space.yml +28 -0
- .gitignore +11 -0
- .python-version +1 -0
- README.md +2 -8
- agents.py +23 -0
- main.py +130 -0
- pyproject.toml +12 -0
- uv.lock +0 -0
.github/workflows/update_space.yml
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
name: Run Python script
|
| 2 |
+
|
| 3 |
+
on:
|
| 4 |
+
push:
|
| 5 |
+
branches:
|
| 6 |
+
- main
|
| 7 |
+
|
| 8 |
+
jobs:
|
| 9 |
+
build:
|
| 10 |
+
runs-on: ubuntu-latest
|
| 11 |
+
|
| 12 |
+
steps:
|
| 13 |
+
- name: Checkout
|
| 14 |
+
uses: actions/checkout@v2
|
| 15 |
+
|
| 16 |
+
- name: Set up Python
|
| 17 |
+
uses: actions/setup-python@v2
|
| 18 |
+
with:
|
| 19 |
+
python-version: '3.9'
|
| 20 |
+
|
| 21 |
+
- name: Install Gradio
|
| 22 |
+
run: python -m pip install gradio
|
| 23 |
+
|
| 24 |
+
- name: Log in to Hugging Face
|
| 25 |
+
run: python -c 'import huggingface_hub; huggingface_hub.login(token="${{ secrets.hf_token }}")'
|
| 26 |
+
|
| 27 |
+
- name: Deploy to Spaces
|
| 28 |
+
run: gradio deploy
|
.gitignore
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Python-generated files
|
| 2 |
+
__pycache__/
|
| 3 |
+
*.py[oc]
|
| 4 |
+
build/
|
| 5 |
+
dist/
|
| 6 |
+
wheels/
|
| 7 |
+
*.egg-info
|
| 8 |
+
.env
|
| 9 |
+
|
| 10 |
+
# Virtual environments
|
| 11 |
+
.venv
|
.python-version
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
3.12
|
README.md
CHANGED
|
@@ -1,12 +1,6 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
-
|
| 4 |
-
colorFrom: green
|
| 5 |
-
colorTo: yellow
|
| 6 |
sdk: gradio
|
| 7 |
sdk_version: 5.38.0
|
| 8 |
-
app_file: app.py
|
| 9 |
-
pinned: false
|
| 10 |
---
|
| 11 |
-
|
| 12 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
| 1 |
---
|
| 2 |
+
title: debate-prep-ai
|
| 3 |
+
app_file: main.py
|
|
|
|
|
|
|
| 4 |
sdk: gradio
|
| 5 |
sdk_version: 5.38.0
|
|
|
|
|
|
|
| 6 |
---
|
|
|
|
|
|
agents.py
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from crewai import Agent
|
| 2 |
+
from gradio import Markdown
|
| 3 |
+
|
| 4 |
+
proposer = Agent(
|
| 5 |
+
role="Proposer",
|
| 6 |
+
goal="Argue that being vegan is better for the environment",
|
| 7 |
+
backstory="You are a passionate environmentalist with deep knowledge in sustainability and climate science.",
|
| 8 |
+
verbose=True
|
| 9 |
+
)
|
| 10 |
+
|
| 11 |
+
opposer = Agent(
|
| 12 |
+
role="Opposer",
|
| 13 |
+
goal="Argue that being vegan is not necessarily better for the environment",
|
| 14 |
+
backstory="You are a critical thinker who questions mainstream beliefs and supports nuanced ecological arguments.",
|
| 15 |
+
verbose=True
|
| 16 |
+
)
|
| 17 |
+
|
| 18 |
+
judge = Agent(
|
| 19 |
+
role="Judge",
|
| 20 |
+
goal="Impartially evaluate the arguments and decide who made a stronger case",
|
| 21 |
+
backstory="You are a neutral academic with expertise in logic, debate, and environmental science.",
|
| 22 |
+
verbose=True
|
| 23 |
+
)
|
main.py
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from dotenv import load_dotenv
|
| 2 |
+
from crewai import Agent, Task, Crew
|
| 3 |
+
from crewai.memory import LongTermMemory
|
| 4 |
+
from agents import proposer, opposer, judge
|
| 5 |
+
import gradio as gr
|
| 6 |
+
from gradio import themes
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
def format_as_chat(message, chat_history=[], role="user"):
|
| 10 |
+
chat_history.append({"role": role, "content": message})
|
| 11 |
+
return chat_history
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
def format_as_chat_history(messages):
|
| 15 |
+
return [
|
| 16 |
+
{"role": "user" if i % 2 == 0 else "assistant", "content": message}
|
| 17 |
+
for i, message in enumerate(messages)
|
| 18 |
+
]
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
def debate(motion="Being vegan is better for the environment", MAX_ROUNDS=4):
|
| 22 |
+
print("Hello from debate-prep-ai!")
|
| 23 |
+
load_dotenv(override=True)
|
| 24 |
+
|
| 25 |
+
turn = "proposer"
|
| 26 |
+
debate_log = []
|
| 27 |
+
yield format_as_chat("Starting debate...", [], "assistant")
|
| 28 |
+
|
| 29 |
+
print("Iterating now...")
|
| 30 |
+
for round_num in range(MAX_ROUNDS):
|
| 31 |
+
if turn == "proposer":
|
| 32 |
+
prompt = (
|
| 33 |
+
f"Start the debate by making your first argument supporting: '{motion}'."
|
| 34 |
+
if not debate_log
|
| 35 |
+
else f"The opponent said: '{debate_log[-1]}'. Respond with a strong counterargument supporting the motion. here is the entire debate log: {debate_log}"
|
| 36 |
+
)
|
| 37 |
+
agent = proposer
|
| 38 |
+
expected_output = (
|
| 39 |
+
f"A single sentence argument in favor of the motion: {motion}"
|
| 40 |
+
)
|
| 41 |
+
else:
|
| 42 |
+
prompt = f"The opponent said: '{debate_log[-1]}'. Respond with a strong counterargument against the motion. here is the entire debate log: {debate_log}"
|
| 43 |
+
agent = opposer
|
| 44 |
+
expected_output = f"A single sentence argument against the motion: {motion}"
|
| 45 |
+
|
| 46 |
+
task = Task(description=prompt, expected_output=expected_output, agent=agent)
|
| 47 |
+
|
| 48 |
+
result = Crew(agents=[agent], tasks=[task]).kickoff()
|
| 49 |
+
# print(result.raw)
|
| 50 |
+
debate_log.append(f"## {turn.capitalize()}: \n{result}")
|
| 51 |
+
chat_history = format_as_chat_history(debate_log)
|
| 52 |
+
yield chat_history
|
| 53 |
+
|
| 54 |
+
turn = "proposer" if turn == "opposer" else "opposer"
|
| 55 |
+
|
| 56 |
+
# Final Verdict by Judge
|
| 57 |
+
debate_summary = "\n\n".join(
|
| 58 |
+
[
|
| 59 |
+
(f"proposer: {point}" if i % 2 == 0 else f"opposer: {point}")
|
| 60 |
+
for i, point in enumerate(debate_log)
|
| 61 |
+
]
|
| 62 |
+
)
|
| 63 |
+
yield format_as_chat(
|
| 64 |
+
f"### Arguments Completed. \n\n #### Judging now ...", chat_history, "user"
|
| 65 |
+
)
|
| 66 |
+
|
| 67 |
+
judge_task = Task(
|
| 68 |
+
description=(
|
| 69 |
+
f"You are the judge of a debate on the motion: '{motion}'. "
|
| 70 |
+
f"Here is the full transcript of the debate:\n\n{debate_summary}\n\n"
|
| 71 |
+
"Evaluate the arguments and give a reasoned verdict on which side was more persuasive and why. Respond with an organized markdown with the following sections: \n\n"
|
| 72 |
+
"1. Introduction: \n\n"
|
| 73 |
+
"2. Arguments: \n\n"
|
| 74 |
+
"3. Conclusion: \n\n"
|
| 75 |
+
"4. Verdict: \n\n"
|
| 76 |
+
"5. Why: \n\n"
|
| 77 |
+
),
|
| 78 |
+
expected_output="A reasoned verdict on which side was more persuasive and why.",
|
| 79 |
+
agent=judge,
|
| 80 |
+
)
|
| 81 |
+
|
| 82 |
+
final_crew = Crew(tasks=[judge_task], agents=[judge], verbose=True)
|
| 83 |
+
verdict = final_crew.kickoff()
|
| 84 |
+
|
| 85 |
+
yield format_as_chat(
|
| 86 |
+
f"👨⚖️ FINAL VERDICT ARRIVED\n\n\n\n {verdict}", chat_history, "assistant"
|
| 87 |
+
)
|
| 88 |
+
|
| 89 |
+
|
| 90 |
+
def renderInterface():
|
| 91 |
+
with gr.Blocks(theme=themes.Default(primary_hue="blue")) as demo:
|
| 92 |
+
gr.Markdown("# Debate Prep AI")
|
| 93 |
+
gr.Markdown(
|
| 94 |
+
"This is a simple Agentic-AI developed using CrewAI that helps you prepare for a debate. It uses 3 agents: the proposer, the opposer and the judge. Use this app to understand what arguments (and counter-arguments) you can place during the debate."
|
| 95 |
+
)
|
| 96 |
+
gr.Markdown("## How to use:")
|
| 97 |
+
gr.Markdown("1. Enter the motion of the debate in the text box below.")
|
| 98 |
+
gr.Markdown("2. Click the 'Debate' button to start the debate.")
|
| 99 |
+
gr.Markdown(
|
| 100 |
+
"3. The AI will generate arguments for your side and evaluate the arguments of the other side."
|
| 101 |
+
)
|
| 102 |
+
gr.Markdown(
|
| 103 |
+
"4. The AI will give you a verdict on which side was more persuasive and why."
|
| 104 |
+
)
|
| 105 |
+
gr.Markdown(
|
| 106 |
+
"5. Confused where to begin? Try asking `AI is bad for humans` and click on *Debate* button."
|
| 107 |
+
)
|
| 108 |
+
|
| 109 |
+
motion = gr.Textbox(
|
| 110 |
+
label="Motion",
|
| 111 |
+
placeholder="What do you want to debate about?",
|
| 112 |
+
info="This is the motion of the debate. It is the statement that you want to debate about. For e.g. you could say Being vegan is better for the environment",
|
| 113 |
+
submit_btn="Debate",
|
| 114 |
+
)
|
| 115 |
+
max_rounds = gr.Slider(
|
| 116 |
+
label="Number of Rounds",
|
| 117 |
+
value=4,
|
| 118 |
+
minimum=1,
|
| 119 |
+
maximum=10,
|
| 120 |
+
info="This is the number of rounds of the debate. The more rounds, the more detailed the debate will be.",
|
| 121 |
+
visible=False,
|
| 122 |
+
)
|
| 123 |
+
chat = gr.Chatbot(label="Debate Log", value=[], type="messages")
|
| 124 |
+
motion.submit(debate, inputs=[motion, max_rounds], outputs=[chat])
|
| 125 |
+
|
| 126 |
+
demo.launch()
|
| 127 |
+
|
| 128 |
+
|
| 129 |
+
if __name__ == "__main__":
|
| 130 |
+
renderInterface()
|
pyproject.toml
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[project]
|
| 2 |
+
name = "debate-prep-ai"
|
| 3 |
+
version = "0.1.0"
|
| 4 |
+
description = "Add your description here"
|
| 5 |
+
readme = "README.md"
|
| 6 |
+
requires-python = ">=3.12"
|
| 7 |
+
dependencies = [
|
| 8 |
+
"chromadb>=1.0.15",
|
| 9 |
+
"crewai>=0.148.0",
|
| 10 |
+
"dotenv>=0.9.9",
|
| 11 |
+
"gradio>=5.38.0",
|
| 12 |
+
]
|
uv.lock
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|