unclemusclez commited on
Commit
48e4738
1 Parent(s): 45aff13

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -6
app.py CHANGED
@@ -21,6 +21,7 @@ token = os.environ.get("HF_TOKEN")
21
  library_username = os.environ.get("OLLAMA_USERNAME").lower()
22
  ollama_pubkey = None
23
  ollama_model_name = None
 
24
  # model.num_parameters()
25
  def regenerate_pubkey(pubkey, oauth_token: gr.OAuthToken | None):
26
  if oauth_token.token is None:
@@ -30,7 +31,7 @@ def regenerate_pubkey(pubkey, oauth_token: gr.OAuthToken | None):
30
  generate_ollama_host_file = f"echo $(ss -natp | grep (cat ollama.pid) | awk '{{print $4}}') > ollama.host"
31
  generate_ollama_pid_file = f"echo $! > ollama.pid"
32
  ollama_pubkey = f"cat {HOME}/{hash_oauth}/.ollama/id_ed25519.pub"
33
- ollama_start = f"HOME={HOME}/{hash_oauth} ollama serve & {ollama_pid_file} & sleep 5 & {ollama_host_file}"
34
  ollama_stop = f"kill -9 'cat ${HOME}/{hash_oauth}/ollama.pid'"
35
  delete_home = f"rm -Rf {HOME}/{hash_oauth}/.ollama"
36
 
@@ -63,9 +64,10 @@ def regenerate_pubkey(pubkey, oauth_token: gr.OAuthToken | None):
63
  return (f"Error: {e}", "error.png")
64
  finally:
65
  # shutil.rmtree(model_name, ignore_errors=True)
66
- print("Ollama Pubkey Generated! Copy to your user profile in teh Ollama Library.")
67
 
68
 
 
69
  def ollamafy_model(login, model_id, ollama_library_username , ollama_q_method, latest, maintainer, oauth_token: gr.OAuthToken | None, ollama_model_name):
70
  ollama_library_username: library_username | None
71
 
@@ -78,6 +80,7 @@ def ollamafy_model(login, model_id, ollama_library_username , ollama_q_method, l
78
  fp16 = f"{model_name}-fp16.gguf"
79
  ollama_stop = f"kill -9 'cat ${HOME}/{hash_oauth}/ollama.pid'"
80
  delete_home = f"rm -Rf {HOME}/{hash_oauth}/.ollama"
 
81
 
82
  try:
83
  api = HfApi(token=oauth_token.token)
@@ -95,6 +98,7 @@ def ollamafy_model(login, model_id, ollama_library_username , ollama_q_method, l
95
  )
96
  dl_pattern += pattern
97
 
 
98
  if not os.path.isfile(fp16):
99
  api.snapshot_download(repo_id=model_id, local_dir=model_name, local_dir_use_symlinks=False, allow_patterns=dl_pattern)
100
  print("Model downloaded successfully!")
@@ -111,22 +115,31 @@ def ollamafy_model(login, model_id, ollama_library_username , ollama_q_method, l
111
  print(f"Converted model path: {fp16}")
112
 
113
  HfApi().delete_repo(repo_id=model_id)
 
 
 
 
 
 
 
 
 
 
114
 
115
  ### Ollamafy ###
116
  model_maintainer = model_id.split('/')[-2]
117
  if ollama_model_name is None:
118
  ollama_model_name = model_maintainer.lower() + '_' + model_name.lower()
119
  ollama_modelfile_name = model_name + '_modelfile'
120
- # model_path = f"{HOME}/.cache/huggingface/hub/{model_id}"
121
 
122
  ollama_modelfile = open(ollama_modelfile_name, "w")
123
- # ollama_modelfile_path = quantized_gguf_path
124
  ollama_modelfile.write(quantized_gguf_path)
125
  ollama_modelfile.close()
126
 
127
  print(quantized_gguf_path)
128
 
129
- # for ollama_q_method in ollama_q_methods:
130
  if ollama_q_method == "FP16":
131
  ollama_conversion = f"ollama create -f {model_file} {library_username}/{ollama_model_name}:{ollama_q_method.lower()}"
132
  else:
@@ -230,7 +243,12 @@ with gr.Blocks(css=css) as demo:
230
  placeholder="Search for model id on Huggingface",
231
  search_type="model",
232
  )
233
-
 
 
 
 
 
234
  ollama_q_method = gr.Dropdown(
235
  ["FP16", "Q3_K_S", "Q3_K_M", "Q3_K_L", "Q4_0", "Q4_1", "Q4_K_S", "Q4_K_M", "Q5_0", "Q5_1", "Q5_K_S", "Q5_K_M", "Q6_K", "Q8_0"],
236
  label="Ollama Quantization Method",
@@ -282,6 +300,7 @@ with gr.Blocks(css=css) as demo:
282
  generate_pubkey,
283
  model_id,
284
  ollama_model_name,
 
285
  ollama_library_username,
286
  ollama_q_method,
287
  latest,
 
21
  library_username = os.environ.get("OLLAMA_USERNAME").lower()
22
  ollama_pubkey = None
23
  ollama_model_name = None
24
+ download_gguf_link = None
25
  # model.num_parameters()
26
  def regenerate_pubkey(pubkey, oauth_token: gr.OAuthToken | None):
27
  if oauth_token.token is None:
 
31
  generate_ollama_host_file = f"echo $(ss -natp | grep (cat ollama.pid) | awk '{{print $4}}') > ollama.host"
32
  generate_ollama_pid_file = f"echo $! > ollama.pid"
33
  ollama_pubkey = f"cat {HOME}/{hash_oauth}/.ollama/id_ed25519.pub"
34
+ ollama_start = f"HOME={HOME}/{hash_oauth} ollama serve & {generate_ollama_pid_file} & sleep 5 & {generate_ollama_host_file}"
35
  ollama_stop = f"kill -9 'cat ${HOME}/{hash_oauth}/ollama.pid'"
36
  delete_home = f"rm -Rf {HOME}/{hash_oauth}/.ollama"
37
 
 
64
  return (f"Error: {e}", "error.png")
65
  finally:
66
  # shutil.rmtree(model_name, ignore_errors=True)
67
+ print("Ollama Pubkey Generated! Copy to your user profile in the Ollama Library.")
68
 
69
 
70
+ # def ollamafy_model(login, model_id, ollama_library_username , ollama_q_method, latest, download_gguf_link, maintainer, oauth_token: gr.OAuthToken | None, ollama_model_name):
71
  def ollamafy_model(login, model_id, ollama_library_username , ollama_q_method, latest, maintainer, oauth_token: gr.OAuthToken | None, ollama_model_name):
72
  ollama_library_username: library_username | None
73
 
 
80
  fp16 = f"{model_name}-fp16.gguf"
81
  ollama_stop = f"kill -9 'cat ${HOME}/{hash_oauth}/ollama.pid'"
82
  delete_home = f"rm -Rf {HOME}/{hash_oauth}/.ollama"
83
+ # download_gguf = f"wget download_gguf_link"
84
 
85
  try:
86
  api = HfApi(token=oauth_token.token)
 
98
  )
99
  dl_pattern += pattern
100
 
101
+ # if not os.path.isfile(fp16) and if download_gguf_link is None:
102
  if not os.path.isfile(fp16):
103
  api.snapshot_download(repo_id=model_id, local_dir=model_name, local_dir_use_symlinks=False, allow_patterns=dl_pattern)
104
  print("Model downloaded successfully!")
 
115
  print(f"Converted model path: {fp16}")
116
 
117
  HfApi().delete_repo(repo_id=model_id)
118
+ else:
119
+ if urlparse.urlparse(download_gguf_link).scheme:
120
+ result = subprocess.run(download_gguf, shell=True, capture_output=True)
121
+ print(result)
122
+ if result.returncode != 0:
123
+ raise Exception(f"Error converting to fp16: {result.stderr}")
124
+ print("Model converted to fp16 successfully!")
125
+ else:
126
+ print("Invalid GGUF Download Link")
127
+
128
 
129
  ### Ollamafy ###
130
  model_maintainer = model_id.split('/')[-2]
131
  if ollama_model_name is None:
132
  ollama_model_name = model_maintainer.lower() + '_' + model_name.lower()
133
  ollama_modelfile_name = model_name + '_modelfile'
134
+ model_path = f"{HOME}/.cache/huggingface/hub/{model_id}"
135
 
136
  ollama_modelfile = open(ollama_modelfile_name, "w")
137
+ ollama_modelfile_path = quantized_gguf_path
138
  ollama_modelfile.write(quantized_gguf_path)
139
  ollama_modelfile.close()
140
 
141
  print(quantized_gguf_path)
142
 
 
143
  if ollama_q_method == "FP16":
144
  ollama_conversion = f"ollama create -f {model_file} {library_username}/{ollama_model_name}:{ollama_q_method.lower()}"
145
  else:
 
243
  placeholder="Search for model id on Huggingface",
244
  search_type="model",
245
  )
246
+
247
+ download_gguf_link = gr.Textbox(
248
+ label="Download Link",
249
+ info="If you have access to the GGUF, you can insert the downlaod link here.",
250
+ )
251
+
252
  ollama_q_method = gr.Dropdown(
253
  ["FP16", "Q3_K_S", "Q3_K_M", "Q3_K_L", "Q4_0", "Q4_1", "Q4_K_S", "Q4_K_M", "Q5_0", "Q5_1", "Q5_K_S", "Q5_K_M", "Q6_K", "Q8_0"],
254
  label="Ollama Quantization Method",
 
300
  generate_pubkey,
301
  model_id,
302
  ollama_model_name,
303
+ download_gguf_link,
304
  ollama_library_username,
305
  ollama_q_method,
306
  latest,