Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM, pipeline
|
| 3 |
+
import gradio as gr
|
| 4 |
+
|
| 5 |
+
# Load model
|
| 6 |
+
tokenizer = AutoTokenizer.from_pretrained("google/flan-t5-base")
|
| 7 |
+
model = AutoModelForSeq2SeqLM.from_pretrained("google/flan-t5-base")
|
| 8 |
+
pipe = pipeline("text2text-generation", model=model, tokenizer=tokenizer)
|
| 9 |
+
|
| 10 |
+
# Agent styles
|
| 11 |
+
personas = {
|
| 12 |
+
"π’ Optimist": "Take a positive and hopeful viewpoint",
|
| 13 |
+
"π΄ Pessimist": "Take a critical or negative viewpoint",
|
| 14 |
+
"π‘ Neutral": "Respond with a balanced and unbiased view"
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
# Generate debate response
|
| 18 |
+
def generate_debate(topic):
|
| 19 |
+
responses = {}
|
| 20 |
+
for label, style in personas.items():
|
| 21 |
+
prompt = f"You are a debater. {style}. The topic is: '{topic}'. What is your opinion?"
|
| 22 |
+
out = pipe(prompt, max_new_tokens=100, temperature=0.7)[0]["generated_text"]
|
| 23 |
+
responses[label] = out
|
| 24 |
+
return responses
|
| 25 |
+
|
| 26 |
+
# Gradio Interface
|
| 27 |
+
def interface_fn(topic):
|
| 28 |
+
responses = generate_debate(topic)
|
| 29 |
+
return "\n\n".join([f"**{k}**: {v}" for k, v in responses.items()])
|
| 30 |
+
|
| 31 |
+
demo = gr.Interface(fn=interface_fn,
|
| 32 |
+
inputs=gr.Textbox(label="Enter a Debate Topic"),
|
| 33 |
+
outputs=gr.Markdown(),
|
| 34 |
+
title="ποΈ Multi-Agent Debate Simulator",
|
| 35 |
+
description="This app simulates a debate from different viewpoints using FLAN-T5 on Hugging Face.")
|
| 36 |
+
|
| 37 |
+
demo.launch()
|