Spaces:
Running
Running
| import gradio as gr | |
| import os | |
| import subprocess | |
| import sys | |
| import shutil | |
| # 1. FORCE PYTHON TO SEE YOUR UPLOADED FOLDERS | |
| # This fixes the 'No module named third_partys' error | |
| current_dir = os.path.dirname(os.path.abspath(__file__)) | |
| sys.path.append(current_dir) | |
| sys.path.append(os.path.join(current_dir, "skeleton")) | |
| sys.path.append(os.path.join(current_dir, "skinning")) | |
| def run_rigging(input_model): | |
| # 2. MANUALLY CREATE MISSING FOLDERS | |
| # This fixes the 'No such file or directory' errors in the .sh script | |
| folders = [ | |
| "results/skel_results", | |
| "results/skin_results/generate", | |
| "results/final_rigging", | |
| "results/rigging", | |
| "temp_input" | |
| ] | |
| for folder in folders: | |
| os.makedirs(folder, exist_ok=True) | |
| # 3. SETUP INPUT | |
| input_path = "temp_input/model.glb" | |
| shutil.copy(input_model.name, input_path) | |
| # 4. RUN THE RIGGING | |
| try: | |
| # We run the bash script you uploaded | |
| subprocess.run(["bash", "demo_rigging.sh"], check=True) | |
| # Check if the file was actually made | |
| output_path = "results/rigging/model_rigged.glb" | |
| if os.path.exists(output_path): | |
| return output_path | |
| else: | |
| return "Error: Rigging script finished but no file was generated. Check logs for 3D math errors." | |
| except Exception as e: | |
| return f"System Error: {str(e)}" | |
| demo = gr.Interface( | |
| fn=run_rigging, | |
| inputs=gr.File(label="Upload GLB"), | |
| outputs=gr.File(label="Rigged Result"), | |
| api_name="rig" | |
| ) | |
| demo.launch() |