osanseviero commited on
Commit
2058f6d
·
1 Parent(s): 037023d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -4
app.py CHANGED
@@ -1,12 +1,18 @@
1
  import gradio as gr
2
  import requests
3
- from huggingface_hub import whoami
4
  from huggingface_hub.utils import build_hf_headers, hf_raise_for_status
5
 
6
- ENDPOINT = ""
7
 
 
 
 
 
 
 
8
 
9
- def duplicate(dst_repo, token):
10
  try:
11
  _ = whoami(token)
12
  # ^ this will throw if token is invalid
@@ -14,12 +20,16 @@ def duplicate(dst_repo, token):
14
  r = requests.post(
15
  "https://huggingface.co/api/spaces/whisper-event/whisper-demo/duplicate",
16
  headers=build_hf_headers(token=token),
17
- json={"repository": dst_repo},
18
  )
19
  hf_raise_for_status(r)
20
 
21
  repo_url = r.json().get("url")
22
 
 
 
 
 
23
  return (
24
  f'Find your repo <a href=\'{repo_url}\' target="_blank" style="text-decoration:underline">here</a>',
25
  "sp.jpg",
 
1
  import gradio as gr
2
  import requests
3
+ from huggingface_hub import whoami, hf_hub_download
4
  from huggingface_hub.utils import build_hf_headers, hf_raise_for_status
5
 
6
+ app_script = hf_hub_download(repo_id="whisper-event/whisper-demo", filename="app.py", repo_type="space")
7
 
8
+ def replace_line(file_name, line_num, text):
9
+ lines = open(file_name, 'r').readlines()
10
+ lines[line_num] = text
11
+ out = open(file_name, 'w')
12
+ out.writelines(lines)
13
+ out.close()
14
 
15
+ def duplicate(destination_repo, model_id, token):
16
  try:
17
  _ = whoami(token)
18
  # ^ this will throw if token is invalid
 
20
  r = requests.post(
21
  "https://huggingface.co/api/spaces/whisper-event/whisper-demo/duplicate",
22
  headers=build_hf_headers(token=token),
23
+ json={"repository": destination_repo},
24
  )
25
  hf_raise_for_status(r)
26
 
27
  repo_url = r.json().get("url")
28
 
29
+
30
+ app_script = hf_hub_download(repo_id="whisper-event/whisper-demo", filename="app.py", repo_type="space")
31
+ replace_line(app_script, 7, f"MODEL_NAME = \"{model_id}\"\n")
32
+
33
  return (
34
  f'Find your repo <a href=\'{repo_url}\' target="_blank" style="text-decoration:underline">here</a>',
35
  "sp.jpg",