Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
| 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) | |