Spaces:
Sleeping
Sleeping
Upload app.py
Browse files
app.py
CHANGED
@@ -17,6 +17,8 @@ def list_model_files(model_id):
|
|
17 |
return weights, configs
|
18 |
|
19 |
def run_teq_inference(model_id, weights_file, config_file, base_model, prompt, max_new_tokens, debug):
|
|
|
|
|
20 |
local_model_dir = f"./models/{model_id.replace('/', '_')}"
|
21 |
os.makedirs(local_model_dir, exist_ok=True)
|
22 |
hf_hub_download(model_id, weights_file, local_dir=local_model_dir)
|
@@ -42,9 +44,11 @@ def run_teq_inference(model_id, weights_file, config_file, base_model, prompt, m
|
|
42 |
|
43 |
def update_files(model_id):
|
44 |
weights, configs = list_model_files(model_id)
|
45 |
-
|
46 |
-
|
47 |
-
|
|
|
|
|
48 |
|
49 |
def build_ui():
|
50 |
teq_models = list_teq_models()
|
@@ -60,11 +64,11 @@ def build_ui():
|
|
60 |
output = gr.Textbox(label="Generated Text", lines=10)
|
61 |
run_btn = gr.Button("Run Inference")
|
62 |
|
63 |
-
#
|
64 |
model_id.change(
|
65 |
update_files,
|
66 |
inputs=model_id,
|
67 |
-
outputs=[weights_file,
|
68 |
)
|
69 |
run_btn.click(
|
70 |
run_teq_inference,
|
|
|
17 |
return weights, configs
|
18 |
|
19 |
def run_teq_inference(model_id, weights_file, config_file, base_model, prompt, max_new_tokens, debug):
|
20 |
+
if not weights_file or not config_file:
|
21 |
+
return "Please select both a weights file and a config file."
|
22 |
local_model_dir = f"./models/{model_id.replace('/', '_')}"
|
23 |
os.makedirs(local_model_dir, exist_ok=True)
|
24 |
hf_hub_download(model_id, weights_file, local_dir=local_model_dir)
|
|
|
44 |
|
45 |
def update_files(model_id):
|
46 |
weights, configs = list_model_files(model_id)
|
47 |
+
# Set value to first item if available, else None
|
48 |
+
weights_val = weights[0] if weights else None
|
49 |
+
configs_val = configs[0] if configs else None
|
50 |
+
return gr.Dropdown(choices=weights, value=weights_val, label="Weights File (.pt)", interactive=True), \
|
51 |
+
gr.Dropdown(choices=configs, value=configs_val, label="Config File (.json)", interactive=True)
|
52 |
|
53 |
def build_ui():
|
54 |
teq_models = list_teq_models()
|
|
|
64 |
output = gr.Textbox(label="Generated Text", lines=10)
|
65 |
run_btn = gr.Button("Run Inference")
|
66 |
|
67 |
+
# Dynamically update the dropdowns for weights and config
|
68 |
model_id.change(
|
69 |
update_files,
|
70 |
inputs=model_id,
|
71 |
+
outputs=[weights_file, config_file]
|
72 |
)
|
73 |
run_btn.click(
|
74 |
run_teq_inference,
|