Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,35 +1,36 @@
|
|
| 1 |
-
from transformers import AutoTokenizer,
|
| 2 |
import gradio as gr
|
| 3 |
|
| 4 |
-
|
| 5 |
-
model_name = "google/flan-t5-base"
|
| 6 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 7 |
-
model =
|
| 8 |
-
pipe = pipeline("
|
| 9 |
|
| 10 |
-
# Personas
|
| 11 |
personas = {
|
| 12 |
-
"π’ Optimist": "
|
| 13 |
-
"π΄ Pessimist": "
|
| 14 |
-
"π‘ Neutral": "
|
| 15 |
}
|
| 16 |
|
| 17 |
-
# Debate function
|
| 18 |
def generate_debate(topic):
|
| 19 |
results = []
|
| 20 |
for label, instruction in personas.items():
|
| 21 |
-
prompt =
|
| 22 |
-
|
| 23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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="ποΈ
|
| 32 |
-
description="Debate
|
| 33 |
)
|
| 34 |
|
| 35 |
demo.launch()
|
|
|
|
| 1 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline
|
| 2 |
import gradio as gr
|
| 3 |
|
| 4 |
+
model_name = "EleutherAI/gpt-neo-1.3B"
|
|
|
|
| 5 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 6 |
+
model = AutoModelForCausalLM.from_pretrained(model_name)
|
| 7 |
+
pipe = pipeline("text-generation", model=model, tokenizer=tokenizer)
|
| 8 |
|
|
|
|
| 9 |
personas = {
|
| 10 |
+
"π’ Optimist": "Give an optimistic argument with 2 benefits and one example.",
|
| 11 |
+
"π΄ Pessimist": "Give a critical argument with 2 drawbacks and one example.",
|
| 12 |
+
"π‘ Neutral": "List pros and cons and give a neutral summary."
|
| 13 |
}
|
| 14 |
|
|
|
|
| 15 |
def generate_debate(topic):
|
| 16 |
results = []
|
| 17 |
for label, instruction in personas.items():
|
| 18 |
+
prompt = (
|
| 19 |
+
f"Debate Topic: {topic}\n"
|
| 20 |
+
f"Persona: {label}\n"
|
| 21 |
+
f"{instruction}\n"
|
| 22 |
+
f"Write 3β4 sentences."
|
| 23 |
+
)
|
| 24 |
+
output = pipe(prompt, max_new_tokens=180, temperature=0.7)[0]['generated_text']
|
| 25 |
+
results.append(f"### {label}\n{output.strip()}")
|
| 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 with GPT-Neo",
|
| 33 |
+
description="Debate with Optimist, Pessimist & Neutral perspectives using GPT-Neo-1.3B."
|
| 34 |
)
|
| 35 |
|
| 36 |
demo.launch()
|