import gradio as gr import requests from huggingface_hub import whoami, hf_hub_download, upload_file from huggingface_hub.utils import build_hf_headers, hf_raise_for_status app_script = hf_hub_download(repo_id="whisper-event/whisper-demo", filename="app.py", repo_type="space") def replace_line(file_name, line_num, text): lines = open(file_name, 'r').readlines() lines[line_num] = text out = open(file_name, 'w') out.writelines(lines) out.close() def duplicate(destination_repo, model_id, token): try: _ = whoami(token) # ^ this will throw if token is invalid r = requests.post( "https://huggingface.co/api/spaces/whisper-event/whisper-demo/duplicate", headers=build_hf_headers(token=token), json={"repository": destination_repo}, ) hf_raise_for_status(r) repo_url = r.json().get("url") app_script = hf_hub_download(repo_id="whisper-event/whisper-demo", filename="app.py", repo_type="space") replace_line(app_script, 7, f"MODEL_NAME = \"{model_id}\"\n") upload_file( path_or_fileobj=app_script, path_in_repo="app.py", repo_id=destination_repo, repo_type="space", token=token ) return ( f'Find your repo here', "sp.jpg", ) except Exception as e: return ( f""" ### Error 😢😢😢 {e} """, None, ) interface = gr.Interface( fn=duplicate, inputs=[ gr.Textbox(placeholder="Destination repository (e.g. username/dst_repo_name)"), gr.Textbox(placeholder="Model id (e.g. openai/whisper-small)"), gr.Textbox(placeholder="Write access token", type="password"), ], outputs=[ gr.Markdown(label="output"), gr.Image(show_label=False), ], title="Build your Whisper demo!", description="Build your Whisper demo! You need to specify a write token obtained in https://hf.co/settings/tokens.", article="

Find your write token at token settings

", allow_flagging="never", live=False, ) interface.launch(enable_queue=True)