Spaces:
Runtime error
Runtime error
File size: 3,050 Bytes
d5a66a4 4806a36 3ceda73 d5a66a4 4806a36 3ceda73 fd6e378 d5a66a4 |
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 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
import requests
import os
from pathlib import Path
# URL of the raw audio file on GitHub
audio_file_urls = [
"https://github.com/raghavdixit99/assets/raw/main/bird_audio.wav",
"https://github.com/raghavdixit99/assets/raw/main/dragon-growl-37570.wav",
"https://github.com/raghavdixit99/assets/raw/main/car_audio.wav",
"https://github.com/raghavdixit99/assets/raw/main/acoustic-guitar.wav",
"https://github.com/raghavdixit99/assets/raw/main/witch.wav",
"https://github.com/raghavdixit99/assets/raw/main/thunder-25689.wav",
]
image_urls = [
"https://github.com/raghavdixit99/assets/assets/34462078/abf47cc4-d979-4aaa-83be-53a2115bf318",
"https://github.com/raghavdixit99/assets/assets/34462078/93be928e-522b-4e37-889d-d4efd54b2112",
"https://github.com/raghavdixit99/assets/assets/34462078/025deaff-632a-4829-a86c-3de6e326402f",
"https://github.com/raghavdixit99/assets/assets/34462078/a20bff32-155c-4bad-acf1-97856c493099",
"https://github.com/raghavdixit99/assets/assets/34462078/4f7dadd8-b38c-4c14-ac8a-5a2e74414f6a",
"https://github.com/raghavdixit99/assets/assets/34462078/ac11eeab-7b2b-4db3-981b-d5fed08d9bc2",
]
base_path = os.path.dirname(os.path.abspath(__file__))
# Local path where you want to save the .wav file
def dowload_and_save_audio():
audio_pths = []
for url in audio_file_urls:
filename = url.split("/")[-1]
local_file_path = Path(f"{base_path}/test_inputs/{filename}")
local_file_path.parent.mkdir(parents=True, exist_ok=True)
# Perform the GET request
response = requests.get(url)
# Check if the request was successful
if response.status_code == 200:
# Write the content of the response to a local file
with open(local_file_path, "wb") as audio_file:
audio_file.write(response.content)
audio_pths.append(str(local_file_path))
print(
f"Audio file downloaded successfully and saved as '{local_file_path}'."
)
else:
print(f"Failed to download file. Status code: {response.status_code}")
return audio_pths
def dowload_and_save_image():
image_paths = []
for url in image_urls:
filename = url.split("/")[-1]
local_file_path = Path(f"{base_path}/test_inputs/{filename}.jpeg")
local_file_path.parent.mkdir(parents=True, exist_ok=True)
# Perform the GET request
response = requests.get(url)
# Check if the request was successful
if response.status_code == 200:
# Write the content of the response to a local file
with open(local_file_path, "wb") as image_file:
image_file.write(response.content)
image_paths.append(str(local_file_path))
print(
f"Image file downloaded successfully and saved as '{local_file_path}'."
)
else:
print(f"Failed to download file. Status code: {response.status_code}")
return image_paths
|