Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,36 +1,41 @@
|
|
1 |
-
from transformers import AutoTokenizer,
|
2 |
import gradio as gr
|
3 |
|
4 |
-
model_name = "
|
5 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
6 |
-
model =
|
7 |
-
pipe = pipeline("
|
8 |
|
|
|
9 |
personas = {
|
10 |
-
"π’ Optimist": "Give
|
11 |
-
"π΄ Pessimist": "Give a critical argument
|
12 |
-
"π‘ Neutral": "
|
13 |
}
|
14 |
|
15 |
def generate_debate(topic):
|
16 |
results = []
|
17 |
for label, instruction in personas.items():
|
18 |
prompt = (
|
19 |
-
f"
|
20 |
-
f"
|
21 |
f"{instruction}\n"
|
22 |
-
f"Write 3β4 sentences."
|
23 |
)
|
24 |
-
|
25 |
-
|
|
|
|
|
|
|
|
|
26 |
return "\n\n".join(results)
|
27 |
|
28 |
demo = gr.Interface(
|
29 |
fn=generate_debate,
|
30 |
inputs=gr.Textbox(label="Debate Topic"),
|
31 |
outputs=gr.Markdown(),
|
32 |
-
title="ποΈ Debate Simulator
|
33 |
-
description="
|
34 |
)
|
35 |
|
36 |
demo.launch()
|
|
|
1 |
+
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM, pipeline
|
2 |
import gradio as gr
|
3 |
|
4 |
+
model_name = "google/flan-t5-base"
|
5 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
6 |
+
model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
|
7 |
+
pipe = pipeline("text2text-generation", model=model, tokenizer=tokenizer)
|
8 |
|
9 |
+
# New, more specific instructions
|
10 |
personas = {
|
11 |
+
"π’ Optimist": "Give a detailed, optimistic argument with at least two clear benefits and an example.",
|
12 |
+
"π΄ Pessimist": "Give a detailed, critical argument highlighting at least two risks or drawbacks and an example.",
|
13 |
+
"π‘ Neutral": "Provide a balanced perspective. Start by listing pros, then cons, and conclude with a neutral summary."
|
14 |
}
|
15 |
|
16 |
def generate_debate(topic):
|
17 |
results = []
|
18 |
for label, instruction in personas.items():
|
19 |
prompt = (
|
20 |
+
f"You are an experienced debater.\n"
|
21 |
+
f"Debate Topic: \"{topic}\"\n"
|
22 |
f"{instruction}\n"
|
23 |
+
f"Write at least 3β4 sentences."
|
24 |
)
|
25 |
+
response = pipe(
|
26 |
+
prompt,
|
27 |
+
max_new_tokens=180, # increased from 120
|
28 |
+
temperature=0.7
|
29 |
+
)[0]['generated_text'].strip()
|
30 |
+
results.append(f"### {label}\n{response}")
|
31 |
return "\n\n".join(results)
|
32 |
|
33 |
demo = gr.Interface(
|
34 |
fn=generate_debate,
|
35 |
inputs=gr.Textbox(label="Debate Topic"),
|
36 |
outputs=gr.Markdown(),
|
37 |
+
title="ποΈ Multi-Agent Debate Simulator",
|
38 |
+
description="Debates with Optimist, Pessimist & Neutral perspectives using FLAN-T5-Base."
|
39 |
)
|
40 |
|
41 |
demo.launch()
|