bartowski commited on
Commit
e8675f9
·
1 Parent(s): bb7627c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -2
app.py CHANGED
@@ -13,6 +13,7 @@ HF_TOKEN = os.environ.get("HF_TOKEN")
13
  def process_model(
14
  model_id: str,
15
  file_path: str,
 
16
  key: str,
17
  value: str,
18
  oauth_token: gr.OAuthToken | None,
@@ -24,6 +25,11 @@ def process_model(
24
 
25
  MODEL_NAME = model_id.split("/")[-1]
26
 
 
 
 
 
 
27
  FILE_NAME = file_path.split("/")[-1]
28
 
29
  api.snapshot_download(
@@ -33,7 +39,7 @@ def process_model(
33
  )
34
  print("Model downloaded successully!")
35
 
36
- metadata_update = f"python3 llama.cpp/gguf-py/scripts/gguf_set_metadata.py {MODEL_NAME}/{file_path} {key} {value}"
37
  subprocess.run(metadata_update, shell=True)
38
  print(f"Model metadata {key} updated to {value} successully!")
39
 
@@ -60,13 +66,15 @@ with gr.Blocks() as demo:
60
 
61
  file_path = gr.Textbox(lines=1, label="File path")
62
 
 
 
63
  key = gr.Textbox(lines=1, label="Key")
64
 
65
  value = gr.Textbox(lines=1, label="Value")
66
 
67
  iface = gr.Interface(
68
  fn=process_model,
69
- inputs=[model_id, file_path, key, value],
70
  outputs=[
71
  gr.Markdown(label="output"),
72
  gr.Image(show_label=False),
@@ -76,6 +84,24 @@ with gr.Blocks() as demo:
76
  api_name=False,
77
  )
78
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
79
 
80
  def restart_space():
81
  HfApi().restart_space(
 
13
  def process_model(
14
  model_id: str,
15
  file_path: str,
16
+ file_path_dropdown: str,
17
  key: str,
18
  value: str,
19
  oauth_token: gr.OAuthToken | None,
 
25
 
26
  MODEL_NAME = model_id.split("/")[-1]
27
 
28
+ if file_path_dropdown:
29
+ FILE_PATH = file_path_dropdown
30
+ else:
31
+ FILE_PATH = file_path
32
+
33
  FILE_NAME = file_path.split("/")[-1]
34
 
35
  api.snapshot_download(
 
39
  )
40
  print("Model downloaded successully!")
41
 
42
+ metadata_update = f"yes | python3 llama.cpp/gguf-py/scripts/gguf_set_metadata.py {MODEL_NAME}/{FILE_PATH} {key} {value}"
43
  subprocess.run(metadata_update, shell=True)
44
  print(f"Model metadata {key} updated to {value} successully!")
45
 
 
66
 
67
  file_path = gr.Textbox(lines=1, label="File path")
68
 
69
+ file_path_dropdown = gr.Dropdown(["None"], label="File", visible=False)
70
+
71
  key = gr.Textbox(lines=1, label="Key")
72
 
73
  value = gr.Textbox(lines=1, label="Value")
74
 
75
  iface = gr.Interface(
76
  fn=process_model,
77
+ inputs=[model_id, file_path, file_path_dropdown, key, value],
78
  outputs=[
79
  gr.Markdown(label="output"),
80
  gr.Image(show_label=False),
 
84
  api_name=False,
85
  )
86
 
87
+ def updateFilePath(model_id: HuggingfaceHubSearch):
88
+ try:
89
+ api = HfApi()
90
+ files = []
91
+ for file in api.list_repo_tree(
92
+ repo_id=model_id,
93
+ recursive=True,
94
+ ):
95
+ files.append(file.path)
96
+
97
+ return gr.update(visible=False), gr.update(visible=True, choices=files)
98
+ except Exception:
99
+ return gr.update(visible=True), gr.update(visible=False)
100
+
101
+ model_id.change(
102
+ fn=updateFilePath, inputs=model_id, outputs=[file_path, file_path_dropdown]
103
+ )
104
+
105
 
106
  def restart_space():
107
  HfApi().restart_space(