File size: 1,225 Bytes
ace93f0
 
742be9d
 
 
ace93f0
742be9d
 
ace93f0
 
742be9d
ace93f0
 
742be9d
ace93f0
c02daf6
 
ace93f0
c02daf6
ace93f0
 
 
 
c02daf6
ace93f0
 
 
c02daf6
ace93f0
 
c02daf6
b498278
ace93f0
 
 
 
 
 
 
c02daf6
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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()