Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,4 +1,3 @@
|
|
| 1 |
-
|
| 2 |
import gradio as gr
|
| 3 |
import json
|
| 4 |
from transformers import pipeline
|
|
@@ -15,46 +14,37 @@ def load_personas():
|
|
| 15 |
|
| 16 |
personas = load_personas()
|
| 17 |
|
| 18 |
-
# Use
|
| 19 |
-
bot = pipeline("text-generation", model="
|
| 20 |
|
| 21 |
-
# Debate
|
| 22 |
-
def
|
| 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=
|
| 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 |
-
|
| 40 |
-
|
| 41 |
-
return outputs
|
| 42 |
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
|
| 50 |
-
|
| 51 |
-
|
|
|
|
| 52 |
|
| 53 |
-
|
| 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()
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import json
|
| 3 |
from transformers import pipeline
|
|
|
|
| 14 |
|
| 15 |
personas = load_personas()
|
| 16 |
|
| 17 |
+
# Use distilgpt2 for faster responses
|
| 18 |
+
bot = pipeline("text-generation", model="distilgpt2")
|
| 19 |
|
| 20 |
+
# Debate generator (yields one response at a time)
|
| 21 |
+
def debate_generator(topic):
|
| 22 |
history = f"Debate Topic: {topic}\n"
|
|
|
|
| 23 |
|
| 24 |
for idx, persona in enumerate(personas):
|
| 25 |
prompt = f"{persona['prompt_style']}\n{history}\n{persona['name']}:"
|
| 26 |
+
response = bot(prompt, max_length=50, do_sample=True)[0]['generated_text']
|
| 27 |
response_text = response[len(prompt):].strip().split("\n")[0]
|
| 28 |
|
|
|
|
| 29 |
history += f"{persona['name']}: {response_text}\n"
|
| 30 |
|
|
|
|
| 31 |
tts = gTTS(response_text, lang='en')
|
| 32 |
audio_file = f"temp_{idx}.mp3"
|
| 33 |
tts.save(audio_file)
|
| 34 |
|
| 35 |
+
yield f"{persona['name']}: {response_text}", audio_file
|
|
|
|
|
|
|
| 36 |
|
| 37 |
+
with gr.Blocks() as iface:
|
| 38 |
+
gr.Markdown("# AI Persona Debate")
|
| 39 |
+
topic_input = gr.Textbox(label="Enter Debate Question")
|
| 40 |
+
start_button = gr.Button("Start Debate")
|
| 41 |
+
output_text = gr.Textbox(label="Current Response")
|
| 42 |
+
output_audio = gr.Audio(label="Voice", autoplay=True)
|
| 43 |
|
| 44 |
+
def run_debate(topic):
|
| 45 |
+
for text, audio in debate_generator(topic):
|
| 46 |
+
yield text, audio
|
| 47 |
|
| 48 |
+
start_button.click(run_debate, inputs=topic_input, outputs=[output_text, output_audio])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
|
| 50 |
iface.launch()
|