frascuchon HF Staff commited on
Commit
386c48c
·
1 Parent(s): 0ee209d

using a custom script to upload files to the HF space

Browse files
Files changed (1) hide show
  1. upload_file.py +31 -0
upload_file.py ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import requests
2
+ from huggingface_hub import space_info
3
+
4
+
5
+ def upload_file_to_huggingface(file_path: str, url: str) -> str:
6
+ """Upload a file to Hugging Face gradio API"""
7
+ with open(file_path, 'rb') as f:
8
+ files = {'files': f}
9
+
10
+ upload_url = f"{url}/gradio_api/upload"
11
+ response = requests.post(upload_url, files=files)
12
+ result = response.json()[0]
13
+ return f"{url}/gradio_api/file={result}"
14
+
15
+
16
+
17
+ if __name__ == "__main__":
18
+ import argparse
19
+
20
+ parser = argparse.ArgumentParser(description="Upload an audio file for processing.")
21
+ parser.add_argument("file", type=str, help="Path to the audio file to upload")
22
+ parser.add_argument("space_id", type=str, help="Hugging Face Space ID to upload the file to")
23
+ args = parser.parse_args()
24
+
25
+ space_id = args.space_id
26
+ file_path = args.file
27
+
28
+ url = f"https://{space_info(space_id).subdomain}.hf.space"
29
+ result = upload_file_to_huggingface(file_path, url)
30
+
31
+ print(result)