Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,47 +1,45 @@
|
|
1 |
from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline
|
2 |
import gradio as gr
|
3 |
|
4 |
-
# Load
|
5 |
-
model_name = "
|
6 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
7 |
model = AutoModelForCausalLM.from_pretrained(model_name)
|
8 |
pipe = pipeline("text-generation", model=model, tokenizer=tokenizer)
|
9 |
|
10 |
-
# Define
|
11 |
personas = {
|
12 |
-
"π’ Optimist": "
|
13 |
-
"π΄ Pessimist": "
|
14 |
-
"π‘ Neutral": "
|
15 |
}
|
16 |
|
17 |
# Prompt template
|
18 |
-
def build_prompt(topic,
|
19 |
-
return
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
f"Your argument:"
|
24 |
-
)
|
25 |
|
26 |
-
# Generate
|
27 |
def debate(topic):
|
28 |
results = {}
|
29 |
-
for label,
|
30 |
-
prompt = build_prompt(topic,
|
31 |
-
output = pipe(prompt, max_new_tokens=200, temperature=0.9
|
32 |
-
|
33 |
-
results[label] =
|
34 |
return results
|
35 |
|
36 |
-
# Gradio
|
37 |
def run_debate(topic):
|
38 |
-
|
39 |
-
return "\n\n".join([f"**{k}**:\n{v}" for k, v in
|
40 |
|
41 |
gr.Interface(
|
42 |
fn=run_debate,
|
43 |
inputs=gr.Textbox(label="Enter a Debate Topic"),
|
44 |
outputs=gr.Markdown(),
|
45 |
title="ποΈ Multi-Agent Debate Simulator",
|
46 |
-
description="
|
47 |
).launch()
|
|
|
1 |
from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline
|
2 |
import gradio as gr
|
3 |
|
4 |
+
# Load Falcon-7B-Instruct (open and free)
|
5 |
+
model_name = "tiiuae/falcon-7b-instruct"
|
6 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
7 |
model = AutoModelForCausalLM.from_pretrained(model_name)
|
8 |
pipe = pipeline("text-generation", model=model, tokenizer=tokenizer)
|
9 |
|
10 |
+
# Define personas
|
11 |
personas = {
|
12 |
+
"π’ Optimist": "Someone who sees the good and hopeful side of any issue.",
|
13 |
+
"π΄ Pessimist": "Someone who focuses on the risks, negatives, or problems in any issue.",
|
14 |
+
"π‘ Neutral": "Someone who presents a balanced, unbiased view based on logic."
|
15 |
}
|
16 |
|
17 |
# Prompt template
|
18 |
+
def build_prompt(topic, style):
|
19 |
+
return f"""You are a debater. Take this persona: {style}.
|
20 |
+
Debate Topic: "{topic}"
|
21 |
+
Provide a thoughtful and opinionated response with reasoning.
|
22 |
+
Answer:"""
|
|
|
|
|
23 |
|
24 |
+
# Generate responses
|
25 |
def debate(topic):
|
26 |
results = {}
|
27 |
+
for label, persona in personas.items():
|
28 |
+
prompt = build_prompt(topic, persona)
|
29 |
+
output = pipe(prompt, max_new_tokens=200, temperature=0.9)[0]["generated_text"]
|
30 |
+
answer = output.split("Answer:")[-1].strip()
|
31 |
+
results[label] = answer
|
32 |
return results
|
33 |
|
34 |
+
# Gradio interface
|
35 |
def run_debate(topic):
|
36 |
+
responses = debate(topic)
|
37 |
+
return "\n\n".join([f"**{k}**:\n{v}" for k, v in responses.items()])
|
38 |
|
39 |
gr.Interface(
|
40 |
fn=run_debate,
|
41 |
inputs=gr.Textbox(label="Enter a Debate Topic"),
|
42 |
outputs=gr.Markdown(),
|
43 |
title="ποΈ Multi-Agent Debate Simulator",
|
44 |
+
description="Simulates multi-perspective debates using Falcon-7B on Hugging Face π€."
|
45 |
).launch()
|