Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -2,6 +2,7 @@ import os
|
|
2 |
import shutil
|
3 |
import subprocess
|
4 |
import signal
|
|
|
5 |
os.environ["GRADIO_ANALYTICS_ENABLED"] = "False"
|
6 |
import gradio as gr
|
7 |
|
@@ -11,16 +12,12 @@ from huggingface_hub import whoami
|
|
11 |
from huggingface_hub import ModelCard
|
12 |
|
13 |
from gradio_huggingfacehub_search import HuggingfaceHubSearch
|
14 |
-
|
15 |
from apscheduler.schedulers.background import BackgroundScheduler
|
16 |
-
|
17 |
from textwrap import dedent
|
18 |
|
19 |
HF_TOKEN = os.environ.get("HF_TOKEN")
|
20 |
OLLAMA_USERNAME = os.environ.get("OLLAMA_USERNAME").lower()
|
21 |
ollama_pubkey = open("/home/user/.ollama/id_ed25519.pub", "r")
|
22 |
-
ollama_q_methods = ["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"]
|
23 |
-
|
24 |
|
25 |
def process_model(model_id, ollamafy, ollama_q_method, latest, maintainer, oauth_token: gr.OAuthToken | None):
|
26 |
if oauth_token.token is None:
|
@@ -30,9 +27,7 @@ def process_model(model_id, ollamafy, ollama_q_method, latest, maintainer, oauth
|
|
30 |
|
31 |
try:
|
32 |
api = HfApi(token=oauth_token.token)
|
33 |
-
|
34 |
dl_pattern = ["*.md", "*.json", "*.model"]
|
35 |
-
|
36 |
pattern = (
|
37 |
"*.safetensors"
|
38 |
if any(
|
@@ -44,8 +39,8 @@ def process_model(model_id, ollamafy, ollama_q_method, latest, maintainer, oauth
|
|
44 |
)
|
45 |
else "*.bin"
|
46 |
)
|
47 |
-
|
48 |
dl_pattern += pattern
|
|
|
49 |
if not os.path.isfile(fp16):
|
50 |
api.snapshot_download(repo_id=model_id, local_dir=model_name, local_dir_use_symlinks=False, allow_patterns=dl_pattern)
|
51 |
print("Model downloaded successfully!")
|
@@ -81,11 +76,13 @@ def process_model(model_id, ollamafy, ollama_q_method, latest, maintainer, oauth
|
|
81 |
ollama_conversion = f"ollama create -f {model_file} {OLLAMA_USERNAME}/{ollama_model_name}:{ollama_q_method.lower()}"
|
82 |
else:
|
83 |
ollama_conversion = f"ollama create -q {ollama_q_method} -f {model_file} {OLLAMA_USERNAME}/{ollama_model_name}:{ollama_q_method.lower()}"
|
|
|
84 |
ollama_conversion_result = subprocess.run(ollama_conversion, shell=True, capture_output=True)
|
85 |
print(ollama_conversion_result)
|
86 |
if ollama_conversion_result.returncode != 0:
|
87 |
raise Exception(f"Error converting to Ollama: {ollama_conversion_result.stderr}")
|
88 |
-
|
|
|
89 |
|
90 |
if maintainer:
|
91 |
ollama_push = f"ollama push {OLLAMA_USERNAME}/{model_name}:{q_method.lower()}"
|
@@ -97,15 +94,17 @@ def process_model(model_id, ollamafy, ollama_q_method, latest, maintainer, oauth
|
|
97 |
ollama_push_result = subprocess.run(ollama_push, shell=True, capture_output=True)
|
98 |
print(ollama_push_result)
|
99 |
if ollama_push_result.returncode != 0:
|
100 |
-
raise Exception(f"Error pushing to Ollama: {ollama_push_result.stderr}")
|
101 |
-
|
|
|
102 |
|
103 |
ollama_rm_result = subprocess.run(ollama_rm, shell=True, capture_output=True)
|
104 |
print(ollama_rm_result)
|
105 |
if ollama_rm_result.returncode != 0:
|
106 |
raise Exception(f"Error removing to Ollama: {ollama_rm_result.stderr}")
|
107 |
-
|
108 |
-
|
|
|
109 |
|
110 |
if latest:
|
111 |
ollama_copy = f"ollama cp {OLLAMA_USERNAME}/{model_id.lower()}:{q_method.lower()} {OLLAMA_USERNAME}/{model_id.lower()}:latest"
|
@@ -115,7 +114,7 @@ def process_model(model_id, ollamafy, ollama_q_method, latest, maintainer, oauth
|
|
115 |
raise Exception(f"Error converting to Ollama: {ollama_push_result.stderr}")
|
116 |
print("Model pushed to Ollama library successfully!")
|
117 |
|
118 |
-
if maintainer
|
119 |
ollama_push_latest = f"ollama push {OLLAMA_USERNAME}/{model_name}:latest"
|
120 |
ollama_rm_latest = f"ollama rm {OLLAMA_USERNAME}/{model_name}:latest"
|
121 |
else:
|
@@ -159,7 +158,7 @@ with gr.Blocks(css=css) as demo:
|
|
159 |
)
|
160 |
|
161 |
ollama_q_method = gr.Dropdown(
|
162 |
-
|
163 |
label="Ollama Lastest Quantization Method",
|
164 |
info="Chose which quantization will be labled with the latest tag in the Ollama Library",
|
165 |
value="FP16",
|
@@ -176,7 +175,7 @@ with gr.Blocks(css=css) as demo:
|
|
176 |
maintainer = gr.Checkbox(
|
177 |
value=False,
|
178 |
label="Maintainer",
|
179 |
-
info="This is your original repository on both Hugging Face and Ollama.
|
180 |
)
|
181 |
|
182 |
iface = gr.Interface(
|
|
|
2 |
import shutil
|
3 |
import subprocess
|
4 |
import signal
|
5 |
+
|
6 |
os.environ["GRADIO_ANALYTICS_ENABLED"] = "False"
|
7 |
import gradio as gr
|
8 |
|
|
|
12 |
from huggingface_hub import ModelCard
|
13 |
|
14 |
from gradio_huggingfacehub_search import HuggingfaceHubSearch
|
|
|
15 |
from apscheduler.schedulers.background import BackgroundScheduler
|
|
|
16 |
from textwrap import dedent
|
17 |
|
18 |
HF_TOKEN = os.environ.get("HF_TOKEN")
|
19 |
OLLAMA_USERNAME = os.environ.get("OLLAMA_USERNAME").lower()
|
20 |
ollama_pubkey = open("/home/user/.ollama/id_ed25519.pub", "r")
|
|
|
|
|
21 |
|
22 |
def process_model(model_id, ollamafy, ollama_q_method, latest, maintainer, oauth_token: gr.OAuthToken | None):
|
23 |
if oauth_token.token is None:
|
|
|
27 |
|
28 |
try:
|
29 |
api = HfApi(token=oauth_token.token)
|
|
|
30 |
dl_pattern = ["*.md", "*.json", "*.model"]
|
|
|
31 |
pattern = (
|
32 |
"*.safetensors"
|
33 |
if any(
|
|
|
39 |
)
|
40 |
else "*.bin"
|
41 |
)
|
|
|
42 |
dl_pattern += pattern
|
43 |
+
|
44 |
if not os.path.isfile(fp16):
|
45 |
api.snapshot_download(repo_id=model_id, local_dir=model_name, local_dir_use_symlinks=False, allow_patterns=dl_pattern)
|
46 |
print("Model downloaded successfully!")
|
|
|
76 |
ollama_conversion = f"ollama create -f {model_file} {OLLAMA_USERNAME}/{ollama_model_name}:{ollama_q_method.lower()}"
|
77 |
else:
|
78 |
ollama_conversion = f"ollama create -q {ollama_q_method} -f {model_file} {OLLAMA_USERNAME}/{ollama_model_name}:{ollama_q_method.lower()}"
|
79 |
+
|
80 |
ollama_conversion_result = subprocess.run(ollama_conversion, shell=True, capture_output=True)
|
81 |
print(ollama_conversion_result)
|
82 |
if ollama_conversion_result.returncode != 0:
|
83 |
raise Exception(f"Error converting to Ollama: {ollama_conversion_result.stderr}")
|
84 |
+
else:
|
85 |
+
print("Model converted to Ollama successfully!")
|
86 |
|
87 |
if maintainer:
|
88 |
ollama_push = f"ollama push {OLLAMA_USERNAME}/{model_name}:{q_method.lower()}"
|
|
|
94 |
ollama_push_result = subprocess.run(ollama_push, shell=True, capture_output=True)
|
95 |
print(ollama_push_result)
|
96 |
if ollama_push_result.returncode != 0:
|
97 |
+
raise Exception(f"Error pushing to Ollama: {ollama_push_result.stderr}")
|
98 |
+
else:
|
99 |
+
print("Model pushed to Ollama library successfully!")
|
100 |
|
101 |
ollama_rm_result = subprocess.run(ollama_rm, shell=True, capture_output=True)
|
102 |
print(ollama_rm_result)
|
103 |
if ollama_rm_result.returncode != 0:
|
104 |
raise Exception(f"Error removing to Ollama: {ollama_rm_result.stderr}")
|
105 |
+
else:
|
106 |
+
print("Model pushed to Ollama library successfully!")
|
107 |
+
|
108 |
|
109 |
if latest:
|
110 |
ollama_copy = f"ollama cp {OLLAMA_USERNAME}/{model_id.lower()}:{q_method.lower()} {OLLAMA_USERNAME}/{model_id.lower()}:latest"
|
|
|
114 |
raise Exception(f"Error converting to Ollama: {ollama_push_result.stderr}")
|
115 |
print("Model pushed to Ollama library successfully!")
|
116 |
|
117 |
+
if maintainer:
|
118 |
ollama_push_latest = f"ollama push {OLLAMA_USERNAME}/{model_name}:latest"
|
119 |
ollama_rm_latest = f"ollama rm {OLLAMA_USERNAME}/{model_name}:latest"
|
120 |
else:
|
|
|
158 |
)
|
159 |
|
160 |
ollama_q_method = gr.Dropdown(
|
161 |
+
["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"],
|
162 |
label="Ollama Lastest Quantization Method",
|
163 |
info="Chose which quantization will be labled with the latest tag in the Ollama Library",
|
164 |
value="FP16",
|
|
|
175 |
maintainer = gr.Checkbox(
|
176 |
value=False,
|
177 |
label="Maintainer",
|
178 |
+
info="This is your original repository on both Hugging Face and Ollama. DO NOT USE Unless same USERNAME on both platforms!!!"
|
179 |
)
|
180 |
|
181 |
iface = gr.Interface(
|