File size: 1,435 Bytes
ecda8f8
4f86110
 
 
 
 
 
c212dfb
4f86110
 
c212dfb
 
4f86110
 
 
c212dfb
4f86110
c212dfb
 
 
4f86110
 
 
c212dfb
4f86110
 
c212dfb
4f86110
c212dfb
4f86110
c212dfb
9985e4e
4f86110
 
 
 
 
c212dfb
4f86110
c212dfb
4f86110
 
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
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
from huggingface_hub.utils import logging


logger = logging.get_logger(__name__)

HfFolder().save_token(os.getenv("HF_TOKEN"))

output_dataset_id = "nateraw/asdf123"
# Where user will write outputs from their script
outputs_dir = Path('outputs')

# A file that marks that the script has finished running
# TODO - maybe check process like this instead of with done.txt: https://stackoverflow.com/a/2944076
output_file = Path('done.txt')

def status_checker():
    logger.info("Waiting to find output_file to check if script is done running")
    while True:
        if output_file.exists():
            logger.info("Found the output file - Uploading the outputs from the script")
            upload_folder(repo_id=output_dataset_id, folder_path=str(outputs_dir), path_in_repo='.', repo_type='dataset')
            logger.info("Finished uploading outputs from script. Done now!")
            return
        logger.info("Didn't find it...sleeping for 5 seconds.")
        time.sleep(5)

with gr.Blocks() as demo:
    gr.Markdown(Path('about.md').read_text())

if not output_file.exists():
    logger.info("Didnt find output file on init, so starting thread to watch for it!")
    thread = Thread(target=status_checker, daemon=True)
    thread.start()

demo.launch()