File size: 1,628 Bytes
117e709
 
 
 
 
96042a5
117e709
 
0fcc960
117e709
 
 
 
 
96042a5
117e709
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
96042a5
 
117e709
 
 
 
 
 
96042a5
 
117e709
 
 
 
 
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
51
52
53
54
55
56
57
import gradio as gr
import requests
from huggingface_hub import whoami
from huggingface_hub.utils import build_hf_headers, hf_raise_for_status

ENDPOINT = ""


def duplicate(dst_repo, 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": dst_repo},
        )
        hf_raise_for_status(r)

        repo_url = r.json().get("url")

        return (
            f'Find your repo <a href=\'{repo_url}\' target="_blank" style="text-decoration:underline">here</a>',
            "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"),
    ],
    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="<p>Find your write token at <a href='https://huggingface.co/settings/tokens' target='_blank'>token settings</a></p>",
    allow_flagging="never",
    live=False,
)
interface.launch(enable_queue=True)