

chore: gradio use openai client to list models
@37d6009430b3a7df1fb96b3805e0c8073f7d41a2
--- faster_whisper_server/gradio_app.py
+++ faster_whisper_server/gradio_app.py
... | ... | @@ -4,6 +4,7 @@ |
4 | 4 |
import gradio as gr |
5 | 5 |
import httpx |
6 | 6 |
from httpx_sse import connect_sse |
7 |
+from openai import OpenAI |
|
7 | 8 |
|
8 | 9 |
from faster_whisper_server.config import Config, Task |
9 | 10 |
|
... | ... | @@ -16,6 +17,7 @@ |
16 | 17 |
port = int(os.getenv("UVICORN_PORT", "8000")) |
17 | 18 |
# NOTE: worth looking into generated clients |
18 | 19 |
http_client = httpx.Client(base_url=f"http://{host}:{port}", timeout=None) |
20 |
+ openai_client = OpenAI(base_url=f"http://{host}:{port}/v1", api_key="cant-be-empty") |
|
19 | 21 |
|
20 | 22 |
def handler(file_path: str, model: str, task: Task, temperature: float, stream: bool) -> Generator[str, None, None]: |
21 | 23 |
if stream: |
... | ... | @@ -65,16 +67,15 @@ |
65 | 67 |
yield event.data |
66 | 68 |
|
67 | 69 |
def update_model_dropdown() -> gr.Dropdown: |
68 |
- res = http_client.get("/v1/models") |
|
69 |
- res_data = res.json() |
|
70 |
- models: list[str] = [model["id"] for model in res_data["data"]] |
|
71 |
- assert config.whisper.model in models |
|
72 |
- recommended_models = {model for model in models if model.startswith("Systran")} |
|
73 |
- other_models = [model for model in models if model not in recommended_models] |
|
74 |
- models = list(recommended_models) + other_models |
|
70 |
+ models = openai_client.models.list().data |
|
71 |
+ model_names: list[str] = [model.id for model in models] |
|
72 |
+ assert config.whisper.model in model_names |
|
73 |
+ recommended_models = {model for model in model_names if model.startswith("Systran")} |
|
74 |
+ other_models = [model for model in model_names if model not in recommended_models] |
|
75 |
+ model_names = list(recommended_models) + other_models |
|
75 | 76 |
return gr.Dropdown( |
76 | 77 |
# no idea why it's complaining |
77 |
- choices=models, # pyright: ignore[reportArgumentType] |
|
78 |
+ choices=model_names, # pyright: ignore[reportArgumentType] |
|
78 | 79 |
label="Model", |
79 | 80 |
value=config.whisper.model, |
80 | 81 |
) |
Add a comment
Delete comment
Once you delete this comment, you won't be able to recover it. Are you sure you want to delete this comment?