Spaces:
Running on Zero
Running on Zero
Repopulate GGUF dropdown via gr.update in Gradio 6
Browse filesReturning a bare list of (label, value) tuples no longer re-renders a
Dropdown under Gradio 6 SSR. Use gr.update(choices=..., value=...) so
the file picker populates and auto-selects the first GGUF.
Co-Authored-By: Claude <noreply@anthropic.com>
app.py
CHANGED
|
@@ -32,23 +32,31 @@ COMPUTE_DTYPES = ["f16", "bf16", "f32"]
|
|
| 32 |
|
| 33 |
|
| 34 |
def list_gguf_files(repo_id: str, hf_token: str):
|
| 35 |
-
"""List *.gguf files in a repo and auto-detect their quant names.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
if not repo_id or not repo_id.strip():
|
| 37 |
-
return [], "Enter a Hugging Face repo id."
|
| 38 |
try:
|
| 39 |
api = HfApi(token=hf_token or None)
|
| 40 |
files = api.list_repo_files(repo_id=repo_id.strip())
|
| 41 |
except Exception as e: # noqa: BLE001
|
| 42 |
-
return [], f"Error listing repo: {e}"
|
| 43 |
ggufs = sorted(f for f in files if f.lower().endswith(".gguf"))
|
| 44 |
if not ggufs:
|
| 45 |
-
return [], f"No .gguf files found in {repo_id!r}."
|
| 46 |
choices = []
|
| 47 |
for f in ggufs:
|
| 48 |
q = quant_from_filename(f)
|
| 49 |
label = f"{f}" + (f" [{q}]" if q else "")
|
| 50 |
choices.append((label, f))
|
| 51 |
-
return
|
|
|
|
|
|
|
|
|
|
| 52 |
|
| 53 |
|
| 54 |
def fetch_arch(repo_id: str, filename: str, hf_token: str):
|
|
|
|
| 32 |
|
| 33 |
|
| 34 |
def list_gguf_files(repo_id: str, hf_token: str):
|
| 35 |
+
"""List *.gguf files in a repo and auto-detect their quant names.
|
| 36 |
+
|
| 37 |
+
Returns gr.update objects (not bare lists) so Gradio 6 reliably re-renders
|
| 38 |
+
the dropdown and pre-selects the first file. A plain list return no longer
|
| 39 |
+
repopulates a Dropdown under SSR in Gradio 6.
|
| 40 |
+
"""
|
| 41 |
if not repo_id or not repo_id.strip():
|
| 42 |
+
return gr.update(choices=[], value=None), "Enter a Hugging Face repo id."
|
| 43 |
try:
|
| 44 |
api = HfApi(token=hf_token or None)
|
| 45 |
files = api.list_repo_files(repo_id=repo_id.strip())
|
| 46 |
except Exception as e: # noqa: BLE001
|
| 47 |
+
return gr.update(choices=[], value=None), f"Error listing repo: {e}"
|
| 48 |
ggufs = sorted(f for f in files if f.lower().endswith(".gguf"))
|
| 49 |
if not ggufs:
|
| 50 |
+
return gr.update(choices=[], value=None), f"No .gguf files found in {repo_id!r}."
|
| 51 |
choices = []
|
| 52 |
for f in ggufs:
|
| 53 |
q = quant_from_filename(f)
|
| 54 |
label = f"{f}" + (f" [{q}]" if q else "")
|
| 55 |
choices.append((label, f))
|
| 56 |
+
return (
|
| 57 |
+
gr.update(choices=choices, value=ggufs[0]),
|
| 58 |
+
f"Found {len(ggufs)} GGUF file(s).",
|
| 59 |
+
)
|
| 60 |
|
| 61 |
|
| 62 |
def fetch_arch(repo_id: str, filename: str, hf_token: str):
|