marks commited on
Commit
3404e9a
·
1 Parent(s): 9b11602

Fixed gradio reference

Browse files
Files changed (2) hide show
  1. api_clients.py +29 -6
  2. app.py +18 -18
api_clients.py CHANGED
@@ -12,17 +12,25 @@ class OpenRouterClient:
12
 
13
  def __init__(self, api_key: str):
14
  logger.info("Initializing OpenRouter client")
15
- if not api_key or len(api_key) < 32:
 
 
 
 
 
 
 
 
 
16
  logger.error("Invalid API key format")
17
  raise ValueError("Invalid OpenRouter API key")
18
-
19
- self.api_key = api_key
20
- self.base_url = "https://openrouter.ai/api/v1"
21
  self.headers = {
22
- "Authorization": f"Bearer {api_key}",
23
  "Content-Type": "application/json",
24
  }
25
- logger.debug("OpenRouter client initialized successfully")
26
 
27
  @asynccontextmanager
28
  async def get_session(self):
@@ -125,6 +133,21 @@ class ElevenLabsClient:
125
  self.api_key = api_key
126
  elevenlabs.set_api_key(api_key)
127
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
128
  @lru_cache(maxsize=1)
129
  def get_voices(self) -> List[Tuple[str, str]]:
130
  """
 
12
 
13
  def __init__(self, api_key: str):
14
  logger.info("Initializing OpenRouter client")
15
+ self.api_key = api_key
16
+ logger.debug("OpenRouter client initialized successfully")
17
+
18
+ @property
19
+ def api_key(self):
20
+ return self._api_key
21
+
22
+ @api_key.setter
23
+ def api_key(self, value: str):
24
+ if not value or len(value) < 32:
25
  logger.error("Invalid API key format")
26
  raise ValueError("Invalid OpenRouter API key")
27
+ self._api_key = value
28
+ # Update headers when API key changes
 
29
  self.headers = {
30
+ "Authorization": f"Bearer {value}",
31
  "Content-Type": "application/json",
32
  }
33
+ logger.info("OpenRouter API key updated successfully")
34
 
35
  @asynccontextmanager
36
  async def get_session(self):
 
133
  self.api_key = api_key
134
  elevenlabs.set_api_key(api_key)
135
 
136
+ @property
137
+ def api_key(self):
138
+ return self._api_key
139
+
140
+ @api_key.setter
141
+ def api_key(self, value: str):
142
+ if not value or len(value) < 32:
143
+ logger.error("Invalid API key format")
144
+ raise ValueError("Invalid ElevenLabs API key")
145
+ self._api_key = value
146
+ elevenlabs.set_api_key(value)
147
+ logger.info("ElevenLabs API key updated successfully")
148
+ # Clear cached voices when API key changes
149
+ self.get_voices.cache_clear()
150
+
151
  @lru_cache(maxsize=1)
152
  def get_voices(self) -> List[Tuple[str, str]]:
153
  """
app.py CHANGED
@@ -1,7 +1,7 @@
1
  import asyncio
2
  import os
 
3
  from typing import Optional
4
- from gradio import Blocks, Markdown, Row, Column, Textbox, Audio, Button, Dropdown
5
  from dotenv import load_dotenv
6
  from scraper import scrape_url
7
  from podcast_generator import PodcastGenerator
@@ -38,49 +38,49 @@ async def generate_podcast(
38
  return f"Error: {str(e)}"
39
 
40
  def create_ui():
41
- with Blocks(title='URL to Podcast Generator', theme='huggingface') as interface:
42
- Markdown('# URL to Podcast Generator')
43
- Markdown('Enter a URL to generate a podcast episode based on its content.')
44
 
45
- with Row():
46
- with Column(scale=2):
47
- url_input = Textbox(
48
  label="Website URL",
49
  placeholder="Enter the URL of the website you want to convert to a podcast"
50
  )
51
 
52
- with Row():
53
- with Column():
54
- openrouter_key = Textbox(
55
  label='OpenRouter API Key',
56
  type='password',
57
  placeholder='Enter key...'
58
  )
59
- openrouter_model = Dropdown(
60
  label='AI Model',
61
  choices=default_models,
62
  value=None,
63
  allow_custom_value=True
64
  )
65
 
66
- with Column():
67
- elevenlabs_key = Textbox(
68
  label='ElevenLabs API Key',
69
  type='password',
70
  placeholder='Enter key...'
71
  )
72
- voice_model = Dropdown(
73
  label='Voice',
74
  choices=default_voices,
75
  value=None,
76
  allow_custom_value=True
77
  )
78
 
79
- submit_btn = Button('Generate Podcast', variant='primary')
80
 
81
- with Column(scale=1):
82
- audio_output = Audio(label="Generated Podcast")
83
- status = Textbox(label='Status', interactive=False)
84
 
85
  # Event handlers for API key changes
86
  async def update_openrouter_models(key):
 
1
  import asyncio
2
  import os
3
+ import gradio as gr
4
  from typing import Optional
 
5
  from dotenv import load_dotenv
6
  from scraper import scrape_url
7
  from podcast_generator import PodcastGenerator
 
38
  return f"Error: {str(e)}"
39
 
40
  def create_ui():
41
+ with gr.Blocks(title='URL to Podcast Generator', theme='huggingface') as interface:
42
+ gr.Markdown('# URL to Podcast Generator')
43
+ gr.Markdown('Enter a URL to generate a podcast episode based on its content.')
44
 
45
+ with gr.Row():
46
+ with gr.Column(scale=2):
47
+ url_input = gr.Textbox(
48
  label="Website URL",
49
  placeholder="Enter the URL of the website you want to convert to a podcast"
50
  )
51
 
52
+ with gr.Row():
53
+ with gr.Column():
54
+ openrouter_key = gr.Textbox(
55
  label='OpenRouter API Key',
56
  type='password',
57
  placeholder='Enter key...'
58
  )
59
+ openrouter_model = gr.Dropdown(
60
  label='AI Model',
61
  choices=default_models,
62
  value=None,
63
  allow_custom_value=True
64
  )
65
 
66
+ with gr.Column():
67
+ elevenlabs_key = gr.Textbox(
68
  label='ElevenLabs API Key',
69
  type='password',
70
  placeholder='Enter key...'
71
  )
72
+ voice_model = gr.Dropdown(
73
  label='Voice',
74
  choices=default_voices,
75
  value=None,
76
  allow_custom_value=True
77
  )
78
 
79
+ submit_btn = gr.Button('Generate Podcast', variant='primary')
80
 
81
+ with gr.Column(scale=1):
82
+ audio_output = gr.Audio(label="Generated Podcast")
83
+ status = gr.Textbox(label='Status', interactive=False)
84
 
85
  # Event handlers for API key changes
86
  async def update_openrouter_models(key):