Spaces:
Runtime error
Runtime error
unclemusclez
commited on
Commit
•
f55c2a7
1
Parent(s):
bcfd37f
added: ollama_host_file , ollama_pid_file , ollama_pubkey ollama_start , ollama_stop , delete_home
Browse filesollama_host_file = f"echo $(ss -natp | grep (cat ollama.pid) | awk '{{print $4}}') > ollama.host"
ollama_pid_file = f"echo $! > ollama.pid"
ollama_pubkey = open(f"{HOME}/.ollama/{hash_oauth}/id_ed25519.pub", "r")
ollama_start = f"HOME={HOME}/{hash_oauth} ollama serve & {ollama_pid_file} & sleep 5 & {ollama_host_file}"
ollama_stop = f"kill -9 'cat ${HOME}/{hash_oauth}/ollama.pid'"
delete_home = f"rm -Rf {HOME}/{hash_oauth}/.ollama"
app.py
CHANGED
@@ -20,8 +20,7 @@ HOME = os.environ.get("HOME")
|
|
20 |
# token = os.environ.get("HF_TOKEN")
|
21 |
library_username = os.environ.get("OLLAMA_USERNAME").lower()
|
22 |
|
23 |
-
|
24 |
-
ollama_stop = f"kill -9 'cat ${HOME}/ollama.pid'"
|
25 |
|
26 |
|
27 |
def regenerate_pubkey(login, oauth_token: gr.OAuthToken | None):
|
@@ -29,24 +28,26 @@ def regenerate_pubkey(login, oauth_token: gr.OAuthToken | None):
|
|
29 |
if oauth_token.token is None:
|
30 |
raise ValueError("You must be logged in to use Ollamafy")
|
31 |
hash_oauth = hashlib.sha256(unicode_string.encode(oauth_token)).hexdigest()
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
|
|
|
|
36 |
|
37 |
-
result = subprocess.run(
|
38 |
print(result)
|
39 |
if result.returncode != 0:
|
40 |
raise Exception(f"Error stoppping Ollama {result.stderr}")
|
41 |
print("Ollama stopped successfully!")
|
42 |
|
43 |
-
result = subprocess.run(
|
44 |
print(result)
|
45 |
if result.returncode != 0:
|
46 |
raise Exception(f"Error removing Ollama HOME folder {result.stderr}")
|
47 |
print("Ollama HOME fodler removed successfully!")
|
48 |
|
49 |
-
result = subprocess.run(
|
50 |
print(result)
|
51 |
if result.returncode != 0:
|
52 |
raise Exception(f"Error starting Ollama {result.stderr}")
|
@@ -191,7 +192,7 @@ with gr.Blocks(css=css) as demo:
|
|
191 |
min_width=250,
|
192 |
)
|
193 |
with gr.Column(scale=1):
|
194 |
-
generate_pubkey = gr.Button (
|
195 |
fn=regenerate_pubkey,
|
196 |
value=regenerate_pubkey,
|
197 |
min_width=250,
|
|
|
20 |
# token = os.environ.get("HF_TOKEN")
|
21 |
library_username = os.environ.get("OLLAMA_USERNAME").lower()
|
22 |
|
23 |
+
|
|
|
24 |
|
25 |
|
26 |
def regenerate_pubkey(login, oauth_token: gr.OAuthToken | None):
|
|
|
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}")
|
|
|
192 |
min_width=250,
|
193 |
)
|
194 |
with gr.Column(scale=1):
|
195 |
+
generate_pubkey = gr.Button (
|
196 |
fn=regenerate_pubkey,
|
197 |
value=regenerate_pubkey,
|
198 |
min_width=250,
|