Create a 3D model from text. Args: prompt: The text prompt. negative_prompt: The negative text prompt. output_dir: The directory to save the output files.
(prompt: str, negative_prompt: str = None, output_dir: str = './output')
| 12 | |
| 13 | |
| 14 | async def main(prompt: str, negative_prompt: str = None, output_dir: str = './output'): |
| 15 | """ |
| 16 | Create a 3D model from text. |
| 17 | |
| 18 | Args: |
| 19 | prompt: The text prompt. |
| 20 | negative_prompt: The negative text prompt. |
| 21 | output_dir: The directory to save the output files. |
| 22 | """ |
| 23 | async with TripoClient() as client: |
| 24 | # 创建任务 |
| 25 | task_id = await client.text_to_model( |
| 26 | prompt=prompt, |
| 27 | negative_prompt=negative_prompt |
| 28 | ) |
| 29 | |
| 30 | # 等待任务完成并显示进度 |
| 31 | task = await client.wait_for_task(task_id, verbose=True) |
| 32 | |
| 33 | if task.status == TaskStatus.SUCCESS: |
| 34 | print(f"\nTask completed successfully!") |
| 35 | |
| 36 | # 创建输出目录(如果不存在) |
| 37 | os.makedirs(output_dir, exist_ok=True) |
| 38 | |
| 39 | # 下载模型文件 |
| 40 | try: |
| 41 | print("\nDownloading model files...") |
| 42 | downloaded_files = await client.download_task_models(task, output_dir) |
| 43 | |
| 44 | # 打印下载的文件路径 |
| 45 | for model_type, file_path in downloaded_files.items(): |
| 46 | if file_path: |
| 47 | print(f"Downloaded {model_type}: {file_path}") |
| 48 | |
| 49 | except Exception as e: |
| 50 | print(f"Failed to download models: {str(e)}") |
| 51 | else: |
| 52 | print(f"\nTask failed with status: {task.status}") |
| 53 | |
| 54 | |
| 55 | if __name__ == "__main__": |
no test coverage detected