Spaces:
Runtime error
Runtime error
refacto UI
Browse files
app.py
CHANGED
|
@@ -1,9 +1,8 @@
|
|
| 1 |
import pathlib
|
| 2 |
-
import subprocess
|
| 3 |
import tempfile
|
| 4 |
from typing import Generator
|
|
|
|
| 5 |
import gradio as gr
|
| 6 |
-
import huggingface_hub
|
| 7 |
import torch
|
| 8 |
import yaml
|
| 9 |
from gradio_logsview import LogsView
|
|
@@ -69,54 +68,51 @@ examples = [[f.name, f.read_text()] for f in pathlib.Path("examples").glob("*.ym
|
|
| 69 |
def merge(
|
| 70 |
example_filename: str, yaml_config: str, hf_token: str, repo_name: str
|
| 71 |
) -> Generator[str, None, None]:
|
| 72 |
-
output = ""
|
| 73 |
if not yaml_config:
|
| 74 |
raise gr.Error("Empty yaml, pick an example below")
|
| 75 |
try:
|
| 76 |
_ = yaml.safe_load(yaml_config)
|
| 77 |
-
except:
|
| 78 |
-
raise gr.Error("Invalid yaml")
|
| 79 |
|
| 80 |
with tempfile.TemporaryDirectory() as tmpdirname:
|
| 81 |
tmpdir = pathlib.Path(tmpdirname)
|
| 82 |
with open(tmpdir / "config.yaml", "w", encoding="utf-8") as f:
|
| 83 |
f.write(yaml_config)
|
| 84 |
-
|
| 85 |
yield from LogsView.run_process(cli.split())
|
| 86 |
|
| 87 |
## TODO(implement upload at the end of the merge, and display the repo URL)
|
| 88 |
|
| 89 |
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
gr.
|
| 96 |
-
gr.Code(
|
| 97 |
language="yaml",
|
| 98 |
lines=10,
|
| 99 |
label="config.yaml",
|
| 100 |
-
)
|
| 101 |
-
gr.
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
demo.launch()
|
|
|
|
| 1 |
import pathlib
|
|
|
|
| 2 |
import tempfile
|
| 3 |
from typing import Generator
|
| 4 |
+
|
| 5 |
import gradio as gr
|
|
|
|
| 6 |
import torch
|
| 7 |
import yaml
|
| 8 |
from gradio_logsview import LogsView
|
|
|
|
| 68 |
def merge(
|
| 69 |
example_filename: str, yaml_config: str, hf_token: str, repo_name: str
|
| 70 |
) -> Generator[str, None, None]:
|
|
|
|
| 71 |
if not yaml_config:
|
| 72 |
raise gr.Error("Empty yaml, pick an example below")
|
| 73 |
try:
|
| 74 |
_ = yaml.safe_load(yaml_config)
|
| 75 |
+
except Exception as e:
|
| 76 |
+
raise gr.Error(f"Invalid yaml {e}")
|
| 77 |
|
| 78 |
with tempfile.TemporaryDirectory() as tmpdirname:
|
| 79 |
tmpdir = pathlib.Path(tmpdirname)
|
| 80 |
with open(tmpdir / "config.yaml", "w", encoding="utf-8") as f:
|
| 81 |
f.write(yaml_config)
|
| 82 |
+
|
| 83 |
yield from LogsView.run_process(cli.split())
|
| 84 |
|
| 85 |
## TODO(implement upload at the end of the merge, and display the repo URL)
|
| 86 |
|
| 87 |
|
| 88 |
+
with gr.Blocks() as demo:
|
| 89 |
+
gr.Markdown(MARKDOWN_DESCRIPTION)
|
| 90 |
+
|
| 91 |
+
with gr.Row():
|
| 92 |
+
filename = gr.Textbox(visible=False, label="filename")
|
| 93 |
+
config = gr.Code(
|
|
|
|
| 94 |
language="yaml",
|
| 95 |
lines=10,
|
| 96 |
label="config.yaml",
|
| 97 |
+
)
|
| 98 |
+
with gr.Column():
|
| 99 |
+
token = gr.Textbox(
|
| 100 |
+
lines=1,
|
| 101 |
+
label="HF Write Token",
|
| 102 |
+
info="https://hf.co/settings/token",
|
| 103 |
+
type="password",
|
| 104 |
+
placeholder="optional, will not upload merge if empty (dry-run)",
|
| 105 |
+
)
|
| 106 |
+
repo_name = gr.Textbox(
|
| 107 |
+
lines=1,
|
| 108 |
+
label="Repo name",
|
| 109 |
+
placeholder="optional, will create a random name if empty",
|
| 110 |
+
)
|
| 111 |
+
button = gr.Button("Merge", variant="primary")
|
| 112 |
+
logs = LogsView()
|
| 113 |
+
gr.Examples(examples, label="Examples", inputs=[filename, config], outputs=[logs])
|
| 114 |
+
gr.Markdown(MARKDOWN_ARTICLE)
|
| 115 |
+
|
| 116 |
+
button.click(fn=merge, inputs=[filename, config, token, repo_name], outputs=[logs])
|
| 117 |
+
|
| 118 |
+
demo.queue(default_concurrency_limit=1).launch()
|
|
|