music-mcp / upload_file.py
frascuchon's picture
frascuchon HF Staff
using a custom script to upload files to the HF space
386c48c
raw
history blame contribute delete
978 Bytes
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)