Spaces:
Paused
Paused
error handling
Browse files- app.py +27 -14
- requirements.txt +1 -1
app.py
CHANGED
@@ -7,7 +7,7 @@ import gradio as gr
|
|
7 |
import huggingface_hub
|
8 |
import torch
|
9 |
import yaml
|
10 |
-
from gradio_logsview.logsview import LogsView
|
11 |
from mergekit.common import parse_kmb
|
12 |
from mergekit.config import MergeConfiguration
|
13 |
from mergekit.merge import run_merge
|
@@ -79,7 +79,7 @@ examples = [[str(f)] for f in pathlib.Path("examples").glob("*.yml")]
|
|
79 |
|
80 |
|
81 |
def merge(
|
82 |
-
example_filename: str, yaml_config: str, hf_token: str, repo_name: str
|
83 |
) -> Generator[str, None, None]:
|
84 |
if not yaml_config:
|
85 |
raise gr.Error("Empty yaml, pick an example below")
|
@@ -88,19 +88,27 @@ def merge(
|
|
88 |
except Exception as e:
|
89 |
raise gr.Error(f"Invalid yaml {e}")
|
90 |
|
|
|
|
|
91 |
with tempfile.TemporaryDirectory() as tmpdirname:
|
92 |
tmpdir = pathlib.Path(tmpdirname)
|
93 |
merged_path = tmpdir / "merged"
|
94 |
merged_path.mkdir(parents=True, exist_ok=True)
|
95 |
config_path = merged_path / "config.yaml"
|
96 |
config_path.write_text(yaml_config)
|
|
|
97 |
|
98 |
-
if repo_name == "":
|
99 |
name = "-".join(
|
100 |
model.model.path for model in merge_config.referenced_models()
|
101 |
)
|
102 |
repo_name = f"mergekit-{merge_config.merge_method}-{name}".replace("/", "-")
|
103 |
-
|
|
|
|
|
|
|
|
|
|
|
104 |
|
105 |
# Taken from https://github.com/arcee-ai/mergekit/blob/main/mergekit/scripts/run_yaml.py
|
106 |
yield from LogsView.run_thread(
|
@@ -112,11 +120,20 @@ def merge(
|
|
112 |
config_source=config_path,
|
113 |
)
|
114 |
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
120 |
|
121 |
|
122 |
with gr.Blocks() as demo:
|
@@ -124,11 +141,7 @@ with gr.Blocks() as demo:
|
|
124 |
|
125 |
with gr.Row():
|
126 |
filename = gr.Textbox(visible=False, label="filename")
|
127 |
-
config = gr.Code(
|
128 |
-
language="yaml",
|
129 |
-
lines=10,
|
130 |
-
label="config.yaml",
|
131 |
-
)
|
132 |
with gr.Column():
|
133 |
token = gr.Textbox(
|
134 |
lines=1,
|
|
|
7 |
import huggingface_hub
|
8 |
import torch
|
9 |
import yaml
|
10 |
+
from gradio_logsview.logsview import LogsView, LogsViewRunner
|
11 |
from mergekit.common import parse_kmb
|
12 |
from mergekit.config import MergeConfiguration
|
13 |
from mergekit.merge import run_merge
|
|
|
79 |
|
80 |
|
81 |
def merge(
|
82 |
+
example_filename: str, yaml_config: str, hf_token: str | None, repo_name: str | None
|
83 |
) -> Generator[str, None, None]:
|
84 |
if not yaml_config:
|
85 |
raise gr.Error("Empty yaml, pick an example below")
|
|
|
88 |
except Exception as e:
|
89 |
raise gr.Error(f"Invalid yaml {e}")
|
90 |
|
91 |
+
runner = LogsViewRunner()
|
92 |
+
|
93 |
with tempfile.TemporaryDirectory() as tmpdirname:
|
94 |
tmpdir = pathlib.Path(tmpdirname)
|
95 |
merged_path = tmpdir / "merged"
|
96 |
merged_path.mkdir(parents=True, exist_ok=True)
|
97 |
config_path = merged_path / "config.yaml"
|
98 |
config_path.write_text(yaml_config)
|
99 |
+
runner.log(f"Merge configuration saved in {config_path}")
|
100 |
|
101 |
+
if token is not None and repo_name == "":
|
102 |
name = "-".join(
|
103 |
model.model.path for model in merge_config.referenced_models()
|
104 |
)
|
105 |
repo_name = f"mergekit-{merge_config.merge_method}-{name}".replace("/", "-")
|
106 |
+
runner.log(f"Will save merged in {repo_name} once process is done.")
|
107 |
+
|
108 |
+
if token is None:
|
109 |
+
runner.log(
|
110 |
+
"No token provided, merge will run in dry-run mode (no upload at the end of the process)."
|
111 |
+
)
|
112 |
|
113 |
# Taken from https://github.com/arcee-ai/mergekit/blob/main/mergekit/scripts/run_yaml.py
|
114 |
yield from LogsView.run_thread(
|
|
|
120 |
config_source=config_path,
|
121 |
)
|
122 |
|
123 |
+
if runner.error:
|
124 |
+
return
|
125 |
+
|
126 |
+
if hf_token is not None:
|
127 |
+
api = huggingface_hub.HfApi(token=hf_token)
|
128 |
+
runner.log("Creating repo")
|
129 |
+
repo_url = api.create_repo(repo_name, exist_ok=True)
|
130 |
+
|
131 |
+
runner.log(f"Repo created: {repo_url}")
|
132 |
+
folder_url = api.upload_folder(
|
133 |
+
repo_id=repo_url.repo_id, folder_path=merged_path
|
134 |
+
)
|
135 |
+
|
136 |
+
runner.log(f"Model successfully uploaded to {folder_url}")
|
137 |
|
138 |
|
139 |
with gr.Blocks() as demo:
|
|
|
141 |
|
142 |
with gr.Row():
|
143 |
filename = gr.Textbox(visible=False, label="filename")
|
144 |
+
config = gr.Code(language="yaml", lines=10, label="config.yaml")
|
|
|
|
|
|
|
|
|
145 |
with gr.Column():
|
146 |
token = gr.Textbox(
|
147 |
lines=1,
|
requirements.txt
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
torch
|
2 |
git+https://github.com/arcee-ai/mergekit.git
|
3 |
# see https://huggingface.co/spaces/Wauplin/gradio_logsview
|
4 |
-
gradio_logsview@https://huggingface.co/spaces/Wauplin/gradio_logsview/resolve/main/gradio_logsview-0.0.
|
|
|
1 |
torch
|
2 |
git+https://github.com/arcee-ai/mergekit.git
|
3 |
# see https://huggingface.co/spaces/Wauplin/gradio_logsview
|
4 |
+
gradio_logsview@https://huggingface.co/spaces/Wauplin/gradio_logsview/resolve/main/gradio_logsview-0.0.3-py3-none-any.whl
|