File size: 2,244 Bytes
4d5296b
 
 
 
82e1020
ff13300
82e1020
 
 
8a600c4
82e1020
4d5296b
d6394b6
 
8a600c4
1ca0068
82e1020
 
 
 
 
8a600c4
005b6c9
4d5296b
 
82e1020
 
 
 
4d5296b
 
 
5bf4118
4d5296b
 
1ca0068
8a600c4
0369fd2
8a600c4
ff13300
8a600c4
 
a66310f
8a600c4
 
 
 
ff13300
8a600c4
 
 
 
 
 
80ea7a7
82e1020
 
 
 
8c2c796
82e1020
c75b82b
 
82e1020
8e9fc47
 
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/env python

import gradio as gr
import PIL.Image
import os
from gradio_client import Client, file

lgm_mini_client = Client("dylanebert/LGM-mini")
triposr_client = Client("stabilityai/TripoSR")
crm_client = Client("Zhengyi/CRM")

def run(image, model_name):
    file_path = "temp.png"
    image.save(file_path)
    
    if model_name=='lgm-mini':
      result = lgm_mini_client.predict(
      file_path,	# filepath  in 'image' Image component
      api_name="/run"
      )
      output = result
    
    elif model_name=='triposr':
        
        process_result = triposr_client.predict(
      file_path,	# filepath  in 'Input Image' Image component
      True,	# bool  in 'Remove Background' Checkbox component
      0.85,	# float (numeric value between 0.5 and 1.0) in 'Foreground Ratio' Slider component
      api_name="/preprocess")
        
        result = triposr_client.predict(
		process_result,	# filepath  in 'Processed Image' Image component
		256,	# float (numeric value between 32 and 320) in 'Marching Cubes Resolution' Slider component
		api_name="/generate")

        output = result[0]

    elif model_name=='crm':
        preprocess_result = crm_client.predict(
		file(file_path),	# filepath in 'Image input' Image component
		"Auto Remove background",	# Literal['Alpha as mask', 'Auto Remove background'] in 'backgroud choice' Radio component
		1,	# float (numeric value between 0.5 and 1.0) in 'Foreground Ratio' Slider component
		"#7F7F7F",	# str in 'Background Color' Colorpicker component
		api_name="/preprocess_image"
        )

        result = crm_client.predict(
    		file(preprocess_result), # filepath in 'Processed Image' Image component
    		1234,	# float in 'seed' Number component
    		5.5,	# float in 'guidance_scale' Number component
    		30,	# float in 'sample steps' Number component
    		api_name="/gen_image"
        )
        output = result[2]
    return output


demo = gr.Interface(
    fn=run,
    inputs=[gr.Image(type="pil"),gr.Textbox(label="Model Name")],
    outputs=gr.Model3D(label="3D Model"),
    api_name="synthesize",
    description="Router for the [3D Arena space](https://huggingface.co/spaces/RamAnanth1/3D-Arena) that does most of the generation"
)

demo.launch()