Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -21,9 +21,9 @@ token = os.environ.get("HF_TOKEN")
|
|
21 |
library_username = os.environ.get("OLLAMA_USERNAME").lower()
|
22 |
|
23 |
def regenerate_pubkey(oauth_token: gr.OAuthToken | None):
|
|
|
|
|
24 |
try:
|
25 |
-
if oauth_token.token is None:
|
26 |
-
raise ValueError("You must be logged in to use Ollamafy")
|
27 |
hash_oauth = hashlib.sha256(unicode_string.encode(oauth_token)).hexdigest()
|
28 |
generate_ollama_host_file = f"echo $(ss -natp | grep (cat ollama.pid) | awk '{{print $4}}') > ollama.host"
|
29 |
generate_ollama_pid_file = f"echo $! > ollama.pid"
|
@@ -59,6 +59,7 @@ def regenerate_pubkey(oauth_token: gr.OAuthToken | None):
|
|
59 |
|
60 |
def ollamafy_model(login, account, model_id, ollama_library_username , ollama_q_method, latest, maintainer, oauth_token: gr.OAuthToken | None):
|
61 |
ollama_library_username: library_username | None
|
|
|
62 |
if oauth_token.token is None:
|
63 |
raise ValueError("You must be logged in to use Ollamafy")
|
64 |
hash_oauth = hashlib.sha256(unicode_string.encode(oauth_token)).hexdigest()
|
@@ -66,6 +67,8 @@ def ollamafy_model(login, account, model_id, ollama_library_username , ollama_q_
|
|
66 |
# username = whoami(oauth_token.token)["name"]
|
67 |
model_name = model_id.split('/')[-1]
|
68 |
fp16 = f"{model_name}-fp16.gguf"
|
|
|
|
|
69 |
|
70 |
try:
|
71 |
api = HfApi(token=oauth_token.token)
|
@@ -183,6 +186,18 @@ def ollamafy_model(login, account, model_id, ollama_library_username , ollama_q_
|
|
183 |
finally:
|
184 |
shutil.rmtree(model_name, ignore_errors=True)
|
185 |
print("Folder cleaned up successfully!")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
186 |
|
187 |
|
188 |
css="""/* Custom CSS to allow scrolling */
|
|
|
21 |
library_username = os.environ.get("OLLAMA_USERNAME").lower()
|
22 |
|
23 |
def regenerate_pubkey(oauth_token: gr.OAuthToken | None):
|
24 |
+
if oauth_token.token is None:
|
25 |
+
raise ValueError("You must be logged in to use Ollamafy")
|
26 |
try:
|
|
|
|
|
27 |
hash_oauth = hashlib.sha256(unicode_string.encode(oauth_token)).hexdigest()
|
28 |
generate_ollama_host_file = f"echo $(ss -natp | grep (cat ollama.pid) | awk '{{print $4}}') > ollama.host"
|
29 |
generate_ollama_pid_file = f"echo $! > ollama.pid"
|
|
|
59 |
|
60 |
def ollamafy_model(login, account, model_id, ollama_library_username , ollama_q_method, latest, maintainer, oauth_token: gr.OAuthToken | None):
|
61 |
ollama_library_username: library_username | None
|
62 |
+
|
63 |
if oauth_token.token is None:
|
64 |
raise ValueError("You must be logged in to use Ollamafy")
|
65 |
hash_oauth = hashlib.sha256(unicode_string.encode(oauth_token)).hexdigest()
|
|
|
67 |
# username = whoami(oauth_token.token)["name"]
|
68 |
model_name = model_id.split('/')[-1]
|
69 |
fp16 = f"{model_name}-fp16.gguf"
|
70 |
+
ollama_stop = f"kill -9 'cat ${HOME}/{hash_oauth}/ollama.pid'"
|
71 |
+
delete_home = f"rm -Rf {HOME}/{hash_oauth}/.ollama"
|
72 |
|
73 |
try:
|
74 |
api = HfApi(token=oauth_token.token)
|
|
|
186 |
finally:
|
187 |
shutil.rmtree(model_name, ignore_errors=True)
|
188 |
print("Folder cleaned up successfully!")
|
189 |
+
|
190 |
+
result = subprocess.run(ollama_stop, shell=True, capture_output=True)
|
191 |
+
print(result)
|
192 |
+
if result.returncode != 0:
|
193 |
+
raise Exception(f"Error stoppping Ollama {result.stderr}")
|
194 |
+
print("Ollama stopped successfully!")
|
195 |
+
|
196 |
+
result = subprocess.run(delete_home, shell=True, capture_output=True)
|
197 |
+
print(result)
|
198 |
+
if result.returncode != 0:
|
199 |
+
raise Exception(f"Error removing Ollama HOME folder {result.stderr}")
|
200 |
+
print("Ollama HOME fodler removed successfully!")
|
201 |
|
202 |
|
203 |
css="""/* Custom CSS to allow scrolling */
|