Spaces:
Runtime error
Runtime error
| import os, sys, subprocess | |
| # Path where CADFusion repo should be cloned | |
| cadfusion_repo = os.path.join(os.path.dirname(__file__), "CADFusion") | |
| # Clone CADFusion repo if not already cloned | |
| if not os.path.exists(cadfusion_repo): | |
| subprocess.check_call(["git", "clone", "https://github.com/microsoft/CADFusion.git", cadfusion_repo]) | |
| # Add CADFusion repo to Python path | |
| sys.path.append(cadfusion_repo) | |
| # Now import from repo | |
| from models import CADFusionModel # models.py lives inside the cloned repo | |
| import gradio as gr | |
| import torch | |
| from transformers import AutoTokenizer | |
| # Load HF checkpoint | |
| checkpoint = "microsoft/CADFusion" | |
| tokenizer = AutoTokenizer.from_pretrained(checkpoint) | |
| model = CADFusionModel.from_pretrained(checkpoint) | |
| # Define inference function | |
| def run_cadfusion(prompt: str): | |
| inputs = tokenizer(prompt, return_tensors="pt") | |
| with torch.no_grad(): | |
| output = model.generate(**inputs, max_new_tokens=128) | |
| return tokenizer.decode(output[0], skip_special_tokens=True) | |
| # Gradio UI | |
| demo = gr.Interface( | |
| fn=run_cadfusion, | |
| inputs="text", | |
| outputs="text", | |
| title="CADFusion Demo", | |
| description="Run Microsoft's CADFusion model" | |
| ) | |
| if __name__ == "__main__": | |
| demo.launch() | |