File size: 1,923 Bytes
6090f88
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7b22fab
6090f88
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
47
48
49
50
import gradio as gr
import os, shutil, requests, zipfile, io
from huggingface_hub import HfApi
SECRET_KEY = os.getenv('SECRET', None)
def refresh(token):
    if SECRET_KEY and token == SECRET_KEY:
        print("Clone repo")
        try:
            shutil.rmtree("repo")
        except:
            pass
        url = "https://github.com/SWivid/F5-TTS/archive/refs/heads/main.zip"
        response = requests.get(url)
        zip_file = io.BytesIO(response.content)
        repo_folder = "repo"
        os.makedirs(repo_folder)
        with zipfile.ZipFile(zip_file, 'r') as zip_ref:
            zip_ref.extractall(repo_folder)
        
        os.rename("repo/F5-TTS-main/gradio_app.py", "repo/F5-TTS-main/app.py")
        os.unlink("repo/F5-TTS-main/.gitignore")
        os.rename("repo/F5-TTS-main/README.md", "repo/F5-TTS-main/README_REPO.md")
        with open("repo/F5-TTS-main/README.md", "w") as f, open("README_TEMPLATE.md", "r") as template:
            f.write(template.read())
        api = HfApi(token=os.getenv('HF_TOKEN'))
        print("Upload")
        api.upload_folder(
            folder_path="repo/F5-TTS-main",
            repo_id="mrfakename/E2-F5-TTS",
            repo_type="space",
            commit_message="Sync from GitHub repo",
            commit_description="This Space is synced from the GitHub repo: https://github.com/SWivid/F5-TTS. Please submit contributions to the Space there"
        )
        try:
            shutil.rmtree("repo")
        except:
            pass
        return "Synced"
    else:
        raise gr.Error("Invalid token")
    

with gr.Blocks() as demo:
    gr.Markdown("This Space is to sync the F5-TTS HF demo with the GitHub repo.")
    token = gr.Textbox(label="Password", info="Enter password to sync demo")
    btn = gr.Button("Refresh")
    out = gr.Markdown("Press Refresh to sync")
    btn.click(refresh, inputs=token, outputs=out)

demo.queue().launch()