unclemusclez commited on
Commit
7e07a21
1 Parent(s): f55c2a7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -28
app.py CHANGED
@@ -24,34 +24,41 @@ library_username = os.environ.get("OLLAMA_USERNAME").lower()
24
 
25
 
26
  def regenerate_pubkey(login, oauth_token: gr.OAuthToken | None):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27
 
28
- if oauth_token.token is None:
29
- raise ValueError("You must be logged in to use Ollamafy")
30
- hash_oauth = hashlib.sha256(unicode_string.encode(oauth_token)).hexdigest()
31
- ollama_host_file = f"echo $(ss -natp | grep (cat ollama.pid) | awk '{{print $4}}') > ollama.host"
32
- ollama_pid_file = f"echo $! > ollama.pid"
33
- ollama_pubkey = open(f"{HOME}/.ollama/{hash_oauth}/id_ed25519.pub", "r")
34
- ollama_start = f"HOME={HOME}/{hash_oauth} ollama serve & {ollama_pid_file} & sleep 5 & {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
-
38
- result = subprocess.run(ollama_stop, shell=True, capture_output=True)
39
- print(result)
40
- if result.returncode != 0:
41
- raise Exception(f"Error stoppping Ollama {result.stderr}")
42
- print("Ollama stopped successfully!")
43
-
44
- result = subprocess.run(delete_home, shell=True, capture_output=True)
45
- print(result)
46
- if result.returncode != 0:
47
- raise Exception(f"Error removing Ollama HOME folder {result.stderr}")
48
- print("Ollama HOME fodler removed successfully!")
49
-
50
- result = subprocess.run(ollama_start, shell=True, capture_output=True)
51
- print(result)
52
- if result.returncode != 0:
53
- raise Exception(f"Error starting Ollama {result.stderr}")
54
- print("Ollama started successfully!")
55
 
56
  def ollamafy_model(login, account, model_id, ollama_library_username , ollama_q_method, latest, maintainer, oauth_token: gr.OAuthToken | None):
57
  ollama_library_username: library_username | None
@@ -193,7 +200,6 @@ with gr.Blocks(css=css) as demo:
193
  )
194
  with gr.Column(scale=1):
195
  generate_pubkey = gr.Button (
196
- fn=regenerate_pubkey,
197
  value=regenerate_pubkey,
198
  min_width=250,
199
  )
 
24
 
25
 
26
  def regenerate_pubkey(login, oauth_token: gr.OAuthToken | None):
27
+ try:
28
+ if oauth_token.token is None:
29
+ raise ValueError("You must be logged in to use Ollamafy")
30
+ hash_oauth = hashlib.sha256(unicode_string.encode(oauth_token)).hexdigest()
31
+ ollama_host_file = f"echo $(ss -natp | grep (cat ollama.pid) | awk '{{print $4}}') > ollama.host"
32
+ ollama_pid_file = f"echo $! > ollama.pid"
33
+ ollama_pubkey = open(f"{HOME}/.ollama/{hash_oauth}/id_ed25519.pub", "r")
34
+ ollama_start = f"HOME={HOME}/{hash_oauth} ollama serve & {ollama_pid_file} & sleep 5 & {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
+
38
+ result = subprocess.run(ollama_stop, shell=True, capture_output=True)
39
+ print(result)
40
+ if result.returncode != 0:
41
+ raise Exception(f"Error stoppping Ollama {result.stderr}")
42
+ print("Ollama stopped successfully!")
43
+
44
+ result = subprocess.run(delete_home, shell=True, capture_output=True)
45
+ print(result)
46
+ if result.returncode != 0:
47
+ raise Exception(f"Error removing Ollama HOME folder {result.stderr}")
48
+ print("Ollama HOME fodler removed successfully!")
49
+
50
+ result = subprocess.run(ollama_start, shell=True, capture_output=True)
51
+ print(result)
52
+ if result.returncode != 0:
53
+ raise Exception(f"Error starting Ollama {result.stderr}")
54
+ print("Ollama started successfully!")
55
+
56
+ except Exception as e:
57
+ return (f"Error: {e}", "error.png")
58
+ finally:
59
+ shutil.rmtree(model_name, ignore_errors=True)
60
+ print("Folder cleaned up successfully`!")
61
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
62
 
63
  def ollamafy_model(login, account, model_id, ollama_library_username , ollama_q_method, latest, maintainer, oauth_token: gr.OAuthToken | None):
64
  ollama_library_username: library_username | None
 
200
  )
201
  with gr.Column(scale=1):
202
  generate_pubkey = gr.Button (
 
203
  value=regenerate_pubkey,
204
  min_width=250,
205
  )