Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
File size: 978 Bytes
386c48c |
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 |
import requests
from huggingface_hub import space_info
def upload_file_to_huggingface(file_path: str, url: str) -> str:
"""Upload a file to Hugging Face gradio API"""
with open(file_path, 'rb') as f:
files = {'files': f}
upload_url = f"{url}/gradio_api/upload"
response = requests.post(upload_url, files=files)
result = response.json()[0]
return f"{url}/gradio_api/file={result}"
if __name__ == "__main__":
import argparse
parser = argparse.ArgumentParser(description="Upload an audio file for processing.")
parser.add_argument("file", type=str, help="Path to the audio file to upload")
parser.add_argument("space_id", type=str, help="Hugging Face Space ID to upload the file to")
args = parser.parse_args()
space_id = args.space_id
file_path = args.file
url = f"https://{space_info(space_id).subdomain}.hf.space"
result = upload_file_to_huggingface(file_path, url)
print(result)
|