Spaces:
Sleeping
Sleeping
File size: 1,459 Bytes
ecda8f8 4f86110 9ae4278 4f86110 c212dfb 4f86110 3fef76f 4f86110 c212dfb 4f86110 c212dfb 3fef76f 9ae4278 51c618a 4f86110 b3a4bd4 4f86110 3fef76f 89be081 4f86110 3fef76f 4f86110 2b046ab 9985e4e 4f86110 b3a4bd4 4f86110 c212dfb b3a4bd4 4f86110 b3a4bd4 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
import os
from pathlib import Path
from threading import Thread
import gradio as gr
from huggingface_hub import upload_folder, HfFolder, delete_repo
import sys
import time
import subprocess
HfFolder().save_token(os.getenv("HF_TOKEN"))
# Where outputs from user script will be pushed to for safe keeping
output_dataset_id = "nateraw/asdf123"
# Where user will write outputs from their script
outputs_dir = Path('outputs')
# Watch python script's process to see when it's done running
process_pid = os.getenv('USER_SCRIPT_PID', None)
def process_is_complete():
p = subprocess.Popen(['ps', '-p', process_pid], stdout=subprocess.PIPE)
out = p.communicate()[0].decode('utf-8').strip().split('\n')
return len(out) == 1
def status_checker():
print("Watching PID of script to see if it is done running")
while True:
if process_is_complete():
print("Process is complete! Uploading assets to output dataset repo")
upload_folder(repo_id=output_dataset_id, folder_path=str(outputs_dir), path_in_repo='.', repo_type='dataset')
print("Finished uploading outputs to dataset repo. Done!")
return
print("Didn't find it...sleeping for 5 seconds.")
time.sleep(5)
with gr.Blocks() as demo:
gr.Markdown(Path('about.md').read_text())
def main():
thread = Thread(target=status_checker, daemon=True)
thread.start()
demo.launch()
if __name__ == '__main__':
main() |