File size: 1,076 Bytes
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
import os, sys, subprocess

# Clone CADFusion repo if not already cloned
if not os.path.exists("CADFusion"):
    subprocess.check_call(["git", "clone", "https://github.com/microsoft/CADFusion.git"])

# Add CADFusion repo to Python path
sys.path.append("CADFusion")

# Now import from repo
from models import CADFusionModel  # repo folder has `models.py`

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()