Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
mariesig
commited on
Commit
·
2a7675b
1
Parent(s):
05d83db
API response -> UI warning
Browse files- aic_api.py +8 -10
aic_api.py
CHANGED
|
@@ -51,10 +51,7 @@ async def upload_and_enhance_v2(
|
|
| 51 |
async with aiohttp.ClientSession(headers={"X-API-Key": api_key}) as session:
|
| 52 |
async with session.post(url, data=form_data) as response:
|
| 53 |
if response.status != 201:
|
| 54 |
-
|
| 55 |
-
print(f"Error occured: {response_text}")
|
| 56 |
-
return None
|
| 57 |
-
|
| 58 |
response_json = await response.json()
|
| 59 |
uid = response_json["uid"]
|
| 60 |
print(f"Uploaded file's uid: {uid}")
|
|
@@ -79,7 +76,7 @@ async def download_enhanced_media_v2(
|
|
| 79 |
|
| 80 |
def process_file_v2(input_file_path: str, output_file_path: str, params: ApiParamsV2) -> None:
|
| 81 |
api_key = params.api_key
|
| 82 |
-
arguments = {
|
| 83 |
"enhancement_level": params.enhancement_level,
|
| 84 |
"enhancement_model": params.enhancement_model,
|
| 85 |
"loudness_target": params.loudness_target,
|
|
@@ -88,11 +85,12 @@ def process_file_v2(input_file_path: str, output_file_path: str, params: ApiPara
|
|
| 88 |
}
|
| 89 |
url = f"{API_V2_URL}/medias"
|
| 90 |
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
|
|
|
| 96 |
response = 412
|
| 97 |
file_size_bytes = os.path.getsize(input_file_path)
|
| 98 |
file_size_mb = file_size_bytes / (1024 * 1024)
|
|
|
|
| 51 |
async with aiohttp.ClientSession(headers={"X-API-Key": api_key}) as session:
|
| 52 |
async with session.post(url, data=form_data) as response:
|
| 53 |
if response.status != 201:
|
| 54 |
+
raise Exception(await response.text())
|
|
|
|
|
|
|
|
|
|
| 55 |
response_json = await response.json()
|
| 56 |
uid = response_json["uid"]
|
| 57 |
print(f"Uploaded file's uid: {uid}")
|
|
|
|
| 76 |
|
| 77 |
def process_file_v2(input_file_path: str, output_file_path: str, params: ApiParamsV2) -> None:
|
| 78 |
api_key = params.api_key
|
| 79 |
+
arguments: dict[str, float | str] = {
|
| 80 |
"enhancement_level": params.enhancement_level,
|
| 81 |
"enhancement_model": params.enhancement_model,
|
| 82 |
"loudness_target": params.loudness_target,
|
|
|
|
| 85 |
}
|
| 86 |
url = f"{API_V2_URL}/medias"
|
| 87 |
|
| 88 |
+
try:
|
| 89 |
+
generated_name = asyncio.run(
|
| 90 |
+
upload_and_enhance_v2(url, input_file_path, api_key, arguments)
|
| 91 |
+
)
|
| 92 |
+
except Exception as e:
|
| 93 |
+
raise RuntimeError(f"Failed to upload file: {e}")
|
| 94 |
response = 412
|
| 95 |
file_size_bytes = os.path.getsize(input_file_path)
|
| 96 |
file_size_mb = file_size_bytes / (1024 * 1024)
|