Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
@@ -6,6 +6,8 @@ import random
|
|
6 |
import yaml
|
7 |
import subprocess
|
8 |
from io import StringIO
|
|
|
|
|
9 |
|
10 |
import runpod
|
11 |
import shutil
|
@@ -25,29 +27,37 @@ USERNAME = 'automerger'
|
|
25 |
N_ROWS = 20
|
26 |
WAIT_TIME = 10800
|
27 |
|
|
|
|
|
28 |
|
29 |
# Logger from https://github.com/gradio-app/gradio/issues/2362
|
30 |
class Logger:
|
31 |
def __init__(self, filename):
|
32 |
self.terminal = sys.stdout
|
33 |
self.log = open(filename, "w")
|
|
|
34 |
|
35 |
def write(self, message):
|
36 |
-
self.
|
37 |
-
|
|
|
38 |
|
39 |
def flush(self):
|
40 |
self.terminal.flush()
|
41 |
self.log.flush()
|
42 |
|
43 |
def isatty(self):
|
44 |
-
return False
|
|
|
|
|
|
|
45 |
|
46 |
|
47 |
def read_logs():
|
48 |
-
|
49 |
-
|
50 |
-
|
|
|
51 |
|
52 |
|
53 |
def create_dataset() -> bool:
|
@@ -72,13 +82,14 @@ def merge_models() -> None:
|
|
72 |
"""
|
73 |
command = ["mergekit-yaml", "config.yaml", "/data/merge", "--copy-tokenizer"]
|
74 |
|
75 |
-
with
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
|
|
82 |
|
83 |
|
84 |
def make_df(file_path: str, n_rows: int) -> pd.DataFrame:
|
@@ -473,7 +484,7 @@ footer = '<div align="center"><p><em>Special thanks to <a href="https://huggingf
|
|
473 |
with gr.Blocks(theme=gr.themes.Soft(primary_hue="blue")) as demo:
|
474 |
gr.Markdown(title)
|
475 |
logs = gr.Textbox(label="Logs")
|
476 |
-
|
477 |
leaderboard = gr.Dataframe(value=get_dataframe, datatype=["markdown", "number", "number", "number", "number", "number"], every=3600)
|
478 |
gr.Markdown(footer)
|
479 |
demo.queue().launch(server_name="0.0.0.0", show_error=True, prevent_thread_lock=True)
|
|
|
6 |
import yaml
|
7 |
import subprocess
|
8 |
from io import StringIO
|
9 |
+
import threading
|
10 |
+
from subprocess import run, CalledProcessError
|
11 |
|
12 |
import runpod
|
13 |
import shutil
|
|
|
27 |
N_ROWS = 20
|
28 |
WAIT_TIME = 10800
|
29 |
|
30 |
+
log_file_lock = threading.Lock()
|
31 |
+
|
32 |
|
33 |
# Logger from https://github.com/gradio-app/gradio/issues/2362
|
34 |
class Logger:
|
35 |
def __init__(self, filename):
|
36 |
self.terminal = sys.stdout
|
37 |
self.log = open(filename, "w")
|
38 |
+
self.lock = log_file_lock
|
39 |
|
40 |
def write(self, message):
|
41 |
+
with self.lock:
|
42 |
+
self.terminal.write(message)
|
43 |
+
self.log.write(message)
|
44 |
|
45 |
def flush(self):
|
46 |
self.terminal.flush()
|
47 |
self.log.flush()
|
48 |
|
49 |
def isatty(self):
|
50 |
+
return False
|
51 |
+
|
52 |
+
def close(self):
|
53 |
+
self.log.close()
|
54 |
|
55 |
|
56 |
def read_logs():
|
57 |
+
with log_file_lock:
|
58 |
+
sys.stdout.flush()
|
59 |
+
with open("output.log", "r") as f:
|
60 |
+
return f.read()
|
61 |
|
62 |
|
63 |
def create_dataset() -> bool:
|
|
|
82 |
"""
|
83 |
command = ["mergekit-yaml", "config.yaml", "/data/merge", "--copy-tokenizer"]
|
84 |
|
85 |
+
with log_file_lock:
|
86 |
+
with open("output.log", "a") as log_file:
|
87 |
+
try:
|
88 |
+
result = subprocess.run(command, check=True, stdout=log_file,
|
89 |
+
stderr=log_file, text=True)
|
90 |
+
print(f"mergekit: {result.stdout}")
|
91 |
+
except subprocess.CalledProcessError as e:
|
92 |
+
print(f"Error: mergekit: {e.stderr}")
|
93 |
|
94 |
|
95 |
def make_df(file_path: str, n_rows: int) -> pd.DataFrame:
|
|
|
484 |
with gr.Blocks(theme=gr.themes.Soft(primary_hue="blue")) as demo:
|
485 |
gr.Markdown(title)
|
486 |
logs = gr.Textbox(label="Logs")
|
487 |
+
demo.load(read_logs, None, logs, every=10)
|
488 |
leaderboard = gr.Dataframe(value=get_dataframe, datatype=["markdown", "number", "number", "number", "number", "number"], every=3600)
|
489 |
gr.Markdown(footer)
|
490 |
demo.queue().launch(server_name="0.0.0.0", show_error=True, prevent_thread_lock=True)
|