Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,35 +1,35 @@
|
|
1 |
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM, pipeline
|
2 |
import gradio as gr
|
3 |
|
4 |
-
#
|
5 |
-
model_name = "
|
6 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
7 |
model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
|
8 |
pipe = pipeline("text2text-generation", model=model, tokenizer=tokenizer)
|
9 |
|
10 |
-
#
|
11 |
personas = {
|
12 |
-
"π’ Optimist": "
|
13 |
-
"π΄ Pessimist": "
|
14 |
-
"π‘ Neutral": "
|
15 |
}
|
16 |
|
17 |
# Debate function
|
18 |
def generate_debate(topic):
|
19 |
-
|
20 |
for label, instruction in personas.items():
|
21 |
-
prompt = f"You are a debater.
|
22 |
-
|
23 |
-
|
24 |
-
return "\n\n".join(
|
25 |
|
26 |
-
# Gradio
|
27 |
demo = gr.Interface(
|
28 |
fn=generate_debate,
|
29 |
inputs=gr.Textbox(label="Debate Topic"),
|
30 |
outputs=gr.Markdown(),
|
31 |
-
title="
|
32 |
-
description="
|
33 |
)
|
34 |
|
35 |
demo.launch()
|
|
|
1 |
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM, pipeline
|
2 |
import gradio as gr
|
3 |
|
4 |
+
# Use lightweight, instruction-tuned model
|
5 |
+
model_name = "google/flan-t5-base"
|
6 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
7 |
model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
|
8 |
pipe = pipeline("text2text-generation", model=model, tokenizer=tokenizer)
|
9 |
|
10 |
+
# Personas
|
11 |
personas = {
|
12 |
+
"π’ Optimist": "Provide a positive and hopeful opinion, mentioning 2 benefits.",
|
13 |
+
"π΄ Pessimist": "Provide a critical opinion, mentioning 2 drawbacks.",
|
14 |
+
"π‘ Neutral": "Provide a balanced perspective, listing pros and cons."
|
15 |
}
|
16 |
|
17 |
# Debate function
|
18 |
def generate_debate(topic):
|
19 |
+
results = []
|
20 |
for label, instruction in personas.items():
|
21 |
+
prompt = f"You are a debater. Topic: '{topic}'. {instruction}"
|
22 |
+
response = pipe(prompt, max_new_tokens=120, temperature=0.7)[0]['generated_text'].strip()
|
23 |
+
results.append(f"### {label}\n{response}")
|
24 |
+
return "\n\n".join(results)
|
25 |
|
26 |
+
# Gradio Interface
|
27 |
demo = gr.Interface(
|
28 |
fn=generate_debate,
|
29 |
inputs=gr.Textbox(label="Debate Topic"),
|
30 |
outputs=gr.Markdown(),
|
31 |
+
title="ποΈ Multi-Agent Debate Simulator",
|
32 |
+
description="Debate from 3 perspectives (Optimist, Pessimist, Neutral) using FLAN-T5-Base."
|
33 |
)
|
34 |
|
35 |
demo.launch()
|