Skip to content

Commit

Permalink
Add Environment Variable to config class
Browse files Browse the repository at this point in the history
  • Loading branch information
lilleswing authored and fedirz committed Jan 19, 2025
1 parent 5347c17 commit 56d06d7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
6 changes: 6 additions & 0 deletions src/speaches/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,3 +253,9 @@ class Config(BaseSettings):

transcription_base_url: str | None = None
transcription_api_key: str | None = None

loopback_host_url: str | None = None
"""
If set this is the URL that the gradio app will use to connect to the API server hosting speaches.
If not set the gradio app will use the url that the user connects to the gradio app on.
"""
6 changes: 4 additions & 2 deletions src/speaches/gradio_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,16 @@
# NOTE: `gr.Request` seems to be passed in as the last positional (not keyword) argument


def base_url_from_gradio_req(request: gr.Request) -> str:
def base_url_from_gradio_req(request: gr.Request, config: Config) -> str:
if config.loopback_host_url is not None and len(config.loopback_host_url) > 0:
return config.loopback_host_url
# NOTE: `request.request.url` seems to always have a path of "/gradio_api/queue/join"
assert request.request is not None
return f"{request.request.url.scheme}://{request.request.url.netloc}"


def http_client_from_gradio_req(request: gr.Request, config: Config) -> httpx.AsyncClient:
base_url = base_url_from_gradio_req(request)
base_url = base_url_from_gradio_req(request, config)
return httpx.AsyncClient(
base_url=base_url,
timeout=TIMEOUT,
Expand Down

0 comments on commit 56d06d7

Please sign in to comment.