Spaces:
Runtime error
Runtime error
| #!/usr/bin/python3 | |
| # -*- coding: utf-8 -*- | |
| import argparse | |
| from urllib.parse import urlparse | |
| import json | |
| from pathlib import Path | |
| from gradio_client import Client, handle_file | |
| import pandas as pd | |
| from tqdm import tqdm | |
| from project_settings import project_path, environment | |
| def get_args(): | |
| parser = argparse.ArgumentParser() | |
| parser.add_argument( | |
| "--audio_file", | |
| default="audio.xlsx", | |
| type=str, | |
| ) | |
| parser.add_argument( | |
| "--audio_dir", | |
| default=(project_path / "temp/audio_trim/trimmed").as_posix(), | |
| type=str, | |
| ) | |
| parser.add_argument( | |
| "--obs_secret_id", | |
| default=environment.get("obs_secret_id"), | |
| type=str, | |
| ) | |
| parser.add_argument( | |
| "--obs_secret_key", | |
| default=environment.get("obs_secret_key"), | |
| type=str, | |
| ) | |
| args = parser.parse_args() | |
| return args | |
| client = Client("http://127.0.0.1:7861/") | |
| def main(): | |
| args = get_args() | |
| obs_kwargs = { | |
| "obs_supplier": "tencent", | |
| "url_prefix": "https://nxai-hk-1259196162.cos.ap-hongkong.myqcloud.com", | |
| "endpoint_url": "https://cos.ap-hongkong.myqcloud.com", | |
| "region": "ap-hongkong", | |
| "secret_id": args.obs_secret_id, | |
| "secret_key": args.obs_secret_key, | |
| "bucket": "nxai-hk-1259196162", | |
| # "debug": True | |
| } | |
| obs_kwargs = json.dumps(obs_kwargs, ensure_ascii=False, indent=4) | |
| print(obs_kwargs) | |
| audio_dir = Path(args.audio_dir) | |
| audio_dir.mkdir(parents=True, exist_ok=True) | |
| df = pd.read_excel(args.audio_file) | |
| for i, row in tqdm(df.iterrows(), total=len(df)): | |
| name = row["name"] | |
| scene_id = row["scene_id"] | |
| audio_id = row["audio_id"] | |
| audio_url = row["audio_url"] | |
| schema = urlparse(audio_url) | |
| url_path = schema.path | |
| filename = audio_dir / url_path[1:] | |
| file_url, message = client.predict( | |
| filename=handle_file(filename.as_posix()), | |
| url_path=url_path[1:], | |
| obs_kwargs=obs_kwargs, | |
| api_name="/when_click_upload_to_obs" | |
| ) | |
| print(filename.as_posix()) | |
| print(f"file_url1: {audio_url}") | |
| print(f"file_url2: {file_url}") | |
| print(f"message: {message}") | |
| print("-" * 150) | |
| return | |
| if __name__ == "__main__": | |
| main() | |