Update status_checker.py
Browse files- status_checker.py +13 -5
status_checker.py
CHANGED
@@ -5,30 +5,38 @@ import gradio as gr
|
|
5 |
from huggingface_hub import upload_folder, HfFolder, delete_repo
|
6 |
import sys
|
7 |
import time
|
|
|
8 |
|
9 |
|
|
|
|
|
10 |
HfFolder().save_token(os.getenv("HF_TOKEN"))
|
11 |
|
12 |
output_dataset_id = "nateraw/asdf123"
|
|
|
13 |
outputs_dir = Path('outputs')
|
|
|
|
|
|
|
14 |
output_file = Path('done.txt')
|
15 |
|
16 |
def status_checker():
|
|
|
17 |
while True:
|
18 |
if output_file.exists():
|
19 |
-
|
20 |
upload_folder(repo_id=output_dataset_id, folder_path=str(outputs_dir), path_in_repo='.', repo_type='dataset')
|
21 |
-
|
22 |
return
|
23 |
-
|
24 |
time.sleep(5)
|
25 |
|
26 |
with gr.Blocks() as demo:
|
27 |
gr.Markdown(Path('about.md').read_text())
|
28 |
|
29 |
if not output_file.exists():
|
30 |
-
|
31 |
thread = Thread(target=status_checker, daemon=True)
|
|
|
32 |
|
33 |
-
thread.start()
|
34 |
demo.launch()
|
|
|
5 |
from huggingface_hub import upload_folder, HfFolder, delete_repo
|
6 |
import sys
|
7 |
import time
|
8 |
+
from huggingface_hub.utils import logging
|
9 |
|
10 |
|
11 |
+
logger = logging.get_logger(__name__)
|
12 |
+
|
13 |
HfFolder().save_token(os.getenv("HF_TOKEN"))
|
14 |
|
15 |
output_dataset_id = "nateraw/asdf123"
|
16 |
+
# Where user will write outputs from their script
|
17 |
outputs_dir = Path('outputs')
|
18 |
+
|
19 |
+
# A file that marks that the script has finished running
|
20 |
+
# TODO - maybe check process like this instead of with done.txt: https://stackoverflow.com/a/2944076
|
21 |
output_file = Path('done.txt')
|
22 |
|
23 |
def status_checker():
|
24 |
+
logger.info("Waiting to find output_file to check if script is done running")
|
25 |
while True:
|
26 |
if output_file.exists():
|
27 |
+
logger.info("Found the output file - Uploading the outputs from the script")
|
28 |
upload_folder(repo_id=output_dataset_id, folder_path=str(outputs_dir), path_in_repo='.', repo_type='dataset')
|
29 |
+
logger.info("Finished uploading outputs from script. Done now!")
|
30 |
return
|
31 |
+
logger.info("Didn't find it...sleeping for 5 seconds.")
|
32 |
time.sleep(5)
|
33 |
|
34 |
with gr.Blocks() as demo:
|
35 |
gr.Markdown(Path('about.md').read_text())
|
36 |
|
37 |
if not output_file.exists():
|
38 |
+
logger.info("Didnt find output file on init, so starting thread to watch for it!")
|
39 |
thread = Thread(target=status_checker, daemon=True)
|
40 |
+
thread.start()
|
41 |
|
|
|
42 |
demo.launch()
|