Spaces:
Build error
Build error
Upload 3 files
Browse files- app.py +60 -0
- personas.zip +3 -0
- requirements.txt +4 -0
app.py
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
import gradio as gr
|
| 3 |
+
import json
|
| 4 |
+
from transformers import pipeline
|
| 5 |
+
from gtts import gTTS
|
| 6 |
+
import os
|
| 7 |
+
|
| 8 |
+
# Load all personas
|
| 9 |
+
def load_personas():
|
| 10 |
+
personas = []
|
| 11 |
+
for i in range(1, 7):
|
| 12 |
+
with open(f'personas/persona_{i}.json', 'r') as f:
|
| 13 |
+
personas.append(json.load(f))
|
| 14 |
+
return personas
|
| 15 |
+
|
| 16 |
+
personas = load_personas()
|
| 17 |
+
|
| 18 |
+
# Use GPT-2 for demo purposes
|
| 19 |
+
bot = pipeline("text-generation", model="gpt2")
|
| 20 |
+
|
| 21 |
+
# Debate function
|
| 22 |
+
def start_debate(topic):
|
| 23 |
+
history = f"Debate Topic: {topic}\n"
|
| 24 |
+
outputs = []
|
| 25 |
+
|
| 26 |
+
for idx, persona in enumerate(personas):
|
| 27 |
+
prompt = f"{persona['prompt_style']}\n{history}\n{persona['name']}:"
|
| 28 |
+
response = bot(prompt, max_length=100, do_sample=True)[0]['generated_text']
|
| 29 |
+
response_text = response[len(prompt):].strip().split("\n")[0]
|
| 30 |
+
|
| 31 |
+
# Update history
|
| 32 |
+
history += f"{persona['name']}: {response_text}\n"
|
| 33 |
+
|
| 34 |
+
# Generate TTS using gTTS (placeholder for 11 Labs)
|
| 35 |
+
tts = gTTS(response_text, lang='en')
|
| 36 |
+
audio_file = f"temp_{idx}.mp3"
|
| 37 |
+
tts.save(audio_file)
|
| 38 |
+
|
| 39 |
+
outputs.append((f"{persona['name']}: {response_text}", audio_file))
|
| 40 |
+
|
| 41 |
+
return outputs
|
| 42 |
+
|
| 43 |
+
# Gradio Interface
|
| 44 |
+
def debate_interface(topic):
|
| 45 |
+
results = start_debate(topic)
|
| 46 |
+
texts = [r[0] for r in results]
|
| 47 |
+
audios = [r[1] for r in results]
|
| 48 |
+
return texts, audios
|
| 49 |
+
|
| 50 |
+
text_output = [gr.Textbox(label=f"Turn {i+1}") for i in range(6)]
|
| 51 |
+
audio_output = [gr.Audio(label=f"Voice {i+1}") for i in range(6)]
|
| 52 |
+
|
| 53 |
+
iface = gr.Interface(
|
| 54 |
+
fn=debate_interface,
|
| 55 |
+
inputs=gr.Textbox(label="Enter Debate Question"),
|
| 56 |
+
outputs=[text_output, audio_output],
|
| 57 |
+
title="AI Persona Debate"
|
| 58 |
+
)
|
| 59 |
+
|
| 60 |
+
iface.launch()
|
personas.zip
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:9dae1f6f61b924d5617968028ac3f320b12f80142308cb34df4cddf2f87ed1a4
|
| 3 |
+
size 1906
|
requirements.txt
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
gradio
|
| 3 |
+
transformers
|
| 4 |
+
gtts
|