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 HfFolder().save_token(os.getenv("HF_TOKEN")) output_dataset_id = "nateraw/asdf123" outputs_dir = Path('outputs') output_file = Path('done.txt') def status_checker(): while True: if output_file.exists(): print("FOUND THE OUTPUT FILE WOAHH. Uploading the outputs from the script") upload_folder(repo_id=output_dataset_id, folder_path=str(outputs_dir), path_in_repo='.', repo_type='dataset') print("Finished uploading outputs from script. Done now!") return print(f"Waiting to find output file...sleeping for 1 second. Outputs Dir Exists - {outputs_dir.exists()}") time.sleep(1) with gr.Blocks() as demo: gr.Markdown(Path('about.md').read_text()) if not output_file.exists(): print("Didnt find output file on init, so starting thread to watch for it!") thread = Thread(target=status_checker, daemon=True) thread.start() demo.launch()