Spaces:
Sleeping
Sleeping
Create status_checker.py
Browse files- status_checker.py +33 -0
status_checker.py
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from pathlib import Path
|
| 2 |
+
from threading import Thread
|
| 3 |
+
import gradio as gr
|
| 4 |
+
from huggingface_hub import upload_folder, HfFolder, delete_repo
|
| 5 |
+
import sys
|
| 6 |
+
import time
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
HfFolder().save_token(os.getenv("HF_TOKEN"))
|
| 10 |
+
|
| 11 |
+
output_dataset_id = "nateraw/asdf123"
|
| 12 |
+
outputs_dir = Path('outputs')
|
| 13 |
+
output_file = Path('done.txt')
|
| 14 |
+
|
| 15 |
+
def status_checker():
|
| 16 |
+
while True:
|
| 17 |
+
if output_file.exists():
|
| 18 |
+
print("FOUND THE OUTPUT FILE WOAHH. Uploading the outputs from the script")
|
| 19 |
+
upload_folder(repo_id=output_dataset_id, folder_path=str(outputs_dir), path_in_repo='.', repo_type='dataset')
|
| 20 |
+
print("Finished uploading outputs from script. Done now!")
|
| 21 |
+
return
|
| 22 |
+
print(f"Waiting to find output file...sleeping for 1 second. Outputs Dir Exists - {outputs_dir.exists()}")
|
| 23 |
+
time.sleep(1)
|
| 24 |
+
|
| 25 |
+
with gr.Blocks() as demo:
|
| 26 |
+
gr.Markdown(Path('about.md').read_text())
|
| 27 |
+
|
| 28 |
+
if not output_file.exists():
|
| 29 |
+
print("Didnt find output file on init, so starting thread to watch for it!")
|
| 30 |
+
thread = Thread(target=status_checker, daemon=True)
|
| 31 |
+
|
| 32 |
+
thread.start()
|
| 33 |
+
demo.launch()
|