marks
commited on
Commit
·
5f41e8a
1
Parent(s):
599efab
Moved API keys to config class
Browse files
app.py
CHANGED
|
@@ -57,29 +57,17 @@ class PodcasterUI:
|
|
| 57 |
|
| 58 |
with gr.Row():
|
| 59 |
with gr.Column():
|
| 60 |
-
openrouter_key = gr.Textbox(
|
| 61 |
-
label='OpenRouter API Key',
|
| 62 |
-
type='password',
|
| 63 |
-
placeholder='Enter key...'
|
| 64 |
-
)
|
| 65 |
openrouter_model = gr.Dropdown(
|
| 66 |
label='AI Model',
|
| 67 |
-
choices=
|
| 68 |
-
value=None
|
| 69 |
-
allow_custom_value=True
|
| 70 |
)
|
| 71 |
|
| 72 |
with gr.Column():
|
| 73 |
-
elevenlabs_key = gr.Textbox(
|
| 74 |
-
label='ElevenLabs API Key',
|
| 75 |
-
type='password',
|
| 76 |
-
placeholder='Enter key...'
|
| 77 |
-
)
|
| 78 |
voice_model = gr.Dropdown(
|
| 79 |
label='Voice',
|
| 80 |
-
choices=
|
| 81 |
-
value=None
|
| 82 |
-
allow_custom_value=True
|
| 83 |
)
|
| 84 |
|
| 85 |
submit_btn = gr.Button('Generate Podcast', variant='primary')
|
|
@@ -88,33 +76,6 @@ class PodcasterUI:
|
|
| 88 |
audio_output = gr.Audio(label="Generated Podcast")
|
| 89 |
status = gr.Textbox(label='Status', interactive=False)
|
| 90 |
|
| 91 |
-
# Event handlers for API key changes
|
| 92 |
-
async def update_openrouter_models(key):
|
| 93 |
-
if not key:
|
| 94 |
-
return gr.Dropdown(choices=default_models)
|
| 95 |
-
try:
|
| 96 |
-
client = OpenRouterClient(key)
|
| 97 |
-
models = await client.get_models()
|
| 98 |
-
return gr.Dropdown(choices=models)
|
| 99 |
-
except Exception as e:
|
| 100 |
-
return gr.Dropdown(choices=[("error", f"Error: {str(e)}")])
|
| 101 |
-
|
| 102 |
-
async def update_elevenlabs_voices(key):
|
| 103 |
-
if not key:
|
| 104 |
-
return gr.Dropdown(choices=default_voices)
|
| 105 |
-
try:
|
| 106 |
-
client = ElevenLabsClient(key)
|
| 107 |
-
voices = await client.get_voices()
|
| 108 |
-
return gr.Dropdown(
|
| 109 |
-
choices={name: id for id, name in voices}
|
| 110 |
-
)
|
| 111 |
-
except Exception as e:
|
| 112 |
-
return gr.Dropdown(choices={"Error": None})
|
| 113 |
-
|
| 114 |
-
# Set up event handlers
|
| 115 |
-
openrouter_key.change(fn=update_openrouter_models, inputs=openrouter_key, outputs=openrouter_model)
|
| 116 |
-
elevenlabs_key.change(fn=update_elevenlabs_voices, inputs=elevenlabs_key, outputs=voice_model)
|
| 117 |
-
|
| 118 |
submit_btn.click(
|
| 119 |
fn=self.on_submit,
|
| 120 |
inputs=[url_input, openrouter_model, voice_model],
|
|
|
|
| 57 |
|
| 58 |
with gr.Row():
|
| 59 |
with gr.Column():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
openrouter_model = gr.Dropdown(
|
| 61 |
label='AI Model',
|
| 62 |
+
choices=self.models,
|
| 63 |
+
value=self.models[0] if self.models else None
|
|
|
|
| 64 |
)
|
| 65 |
|
| 66 |
with gr.Column():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
voice_model = gr.Dropdown(
|
| 68 |
label='Voice',
|
| 69 |
+
choices=self.voices,
|
| 70 |
+
value=self.voices[0] if self.voices else None
|
|
|
|
| 71 |
)
|
| 72 |
|
| 73 |
submit_btn = gr.Button('Generate Podcast', variant='primary')
|
|
|
|
| 76 |
audio_output = gr.Audio(label="Generated Podcast")
|
| 77 |
status = gr.Textbox(label='Status', interactive=False)
|
| 78 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 79 |
submit_btn.click(
|
| 80 |
fn=self.on_submit,
|
| 81 |
inputs=[url_input, openrouter_model, voice_model],
|