jk12p commited on
Commit
6465fb2
·
verified ·
1 Parent(s): fc90eed
Files changed (1) hide show
  1. app.py +85 -68
app.py CHANGED
@@ -1,7 +1,6 @@
1
  import gradio as gr
2
  from gradio_client import Client, handle_file
3
 
4
- # Gradio Interface Functions
5
  def start_session():
6
  client = Client("JeffreyXiang/TRELLIS")
7
  result = client.predict(api_name="/start_session")
@@ -82,70 +81,88 @@ def lambda_6_function():
82
  result = client.predict(api_name="/lambda_6")
83
  return result
84
 
85
- # Gradio Interface
86
- iface = gr.Interface(
87
- fn={
88
- "start_session": start_session,
89
- "lambda_function": lambda_function,
90
- "lambda_1_function": lambda_1_function,
91
- "preprocess_image": preprocess_image,
92
- "preprocess_images": preprocess_images,
93
- "get_seed": get_seed,
94
- "image_to_3d": image_to_3d,
95
- "lambda_2_function": lambda_2_function,
96
- "lambda_3_function": lambda_3_function,
97
- "extract_glb": extract_glb,
98
- "lambda_4_function": lambda_4_function,
99
- "extract_gaussian": extract_gaussian,
100
- "lambda_5_function": lambda_5_function,
101
- "lambda_6_function": lambda_6_function,
102
- },
103
- inputs={
104
- "start_session": [],
105
- "lambda_function": [],
106
- "lambda_1_function": [],
107
- "preprocess_image": gr.Image(type="filepath"),
108
- "preprocess_images": gr.Gallery(label="Images"),
109
- "get_seed": [gr.Checkbox(value=True, label="Randomize Seed"), gr.Slider(minimum=0, maximum=100, value=0, label="Seed")],
110
- "image_to_3d": [
111
- gr.Image(type="filepath", label="Image"),
112
- gr.Gallery(label="Multi Images"),
113
- gr.Slider(minimum=0, maximum=100, value=0, label="Seed"),
114
- gr.Slider(minimum=0, maximum=10, value=7.5, label="SS Guidance Strength"),
115
- gr.Slider(minimum=0, maximum=20, value=12, label="SS Sampling Steps"),
116
- gr.Slider(minimum=0, maximum=10, value=3, label="SLAT Guidance Strength"),
117
- gr.Slider(minimum=0, maximum=20, value=12, label="SLAT Sampling Steps"),
118
- gr.Radio(choices=["stochastic", "multidiffusion"], value="stochastic", label="Multi-image Algorithm")
119
- ],
120
- "lambda_2_function": [],
121
- "lambda_3_function": [],
122
- "extract_glb": [
123
- gr.Slider(minimum=0, maximum=1, value=0.95, label="Mesh Simplify"),
124
- gr.Slider(minimum=0, maximum=2048, value=1024, label="Texture Size")
125
- ],
126
- "lambda_4_function": [],
127
- "extract_gaussian": [],
128
- "lambda_5_function": [],
129
- "lambda_6_function": []
130
- },
131
- outputs={
132
- "start_session": gr.Textbox(),
133
- "lambda_function": gr.Textbox(),
134
- "lambda_1_function": gr.Textbox(),
135
- "preprocess_image": gr.Image(type="filepath"),
136
- "preprocess_images": gr.Gallery(),
137
- "get_seed": gr.Textbox(),
138
- "image_to_3d": gr.Video(),
139
- "lambda_2_function": gr.Textbox(),
140
- "lambda_3_function": gr.Textbox(),
141
- "extract_glb": gr.Files(),
142
- "lambda_4_function": gr.Textbox(),
143
- "extract_gaussian": gr.Files(),
144
- "lambda_5_function": gr.Files(),
145
- "lambda_6_function": gr.Files()
146
- },
147
- title="TRELLIS API Client",
148
- description="This Gradio app allows you to interact with the TRELLIS API endpoints."
149
- )
150
-
151
- iface.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
  from gradio_client import Client, handle_file
3
 
 
4
  def start_session():
5
  client = Client("JeffreyXiang/TRELLIS")
6
  result = client.predict(api_name="/start_session")
 
81
  result = client.predict(api_name="/lambda_6")
82
  return result
83
 
84
+ with gr.Blocks(title="TRELLIS API Client") as demo:
85
+ gr.Markdown("# TRELLIS API Client")
86
+
87
+ with gr.Tab("Start Session"):
88
+ start_btn = gr.Button("Start Session")
89
+ start_output = gr.Textbox(label="Output")
90
+ start_btn.click(fn=start_session, inputs=[], outputs=start_output)
91
+
92
+ with gr.Tab("Lambda"):
93
+ lambda_btn = gr.Button("Run Lambda")
94
+ lambda_output = gr.Textbox(label="Output")
95
+ lambda_btn.click(fn=lambda_function, inputs=[], outputs=lambda_output)
96
+
97
+ with gr.Tab("Lambda 1"):
98
+ lambda1_btn = gr.Button("Run Lambda 1")
99
+ lambda1_output = gr.Textbox(label="Output")
100
+ lambda1_btn.click(fn=lambda_1_function, inputs=[], outputs=lambda1_output)
101
+
102
+ with gr.Tab("Preprocess Image"):
103
+ image_input = gr.Image(type="filepath", label="Input Image")
104
+ preprocess_btn = gr.Button("Preprocess")
105
+ image_output = gr.Image(type="filepath", label="Processed Image")
106
+ preprocess_btn.click(fn=preprocess_image, inputs=image_input, outputs=image_output)
107
+
108
+ with gr.Tab("Preprocess Images"):
109
+ images_input = gr.Gallery(label="Input Images")
110
+ preprocess_images_btn = gr.Button("Preprocess")
111
+ images_output = gr.Gallery(label="Processed Images")
112
+ preprocess_images_btn.click(fn=preprocess_images, inputs=images_input, outputs=images_output)
113
+
114
+ with gr.Tab("Get Seed"):
115
+ with gr.Row():
116
+ randomize = gr.Checkbox(value=True, label="Randomize Seed")
117
+ seed = gr.Slider(minimum=0, maximum=100, value=0, label="Seed")
118
+ seed_btn = gr.Button("Get Seed")
119
+ seed_output = gr.Textbox(label="Output")
120
+ seed_btn.click(fn=get_seed, inputs=[randomize, seed], outputs=seed_output)
121
+
122
+ with gr.Tab("Image to 3D"):
123
+ img_input = gr.Image(type="filepath", label="Image")
124
+ multi_imgs = gr.Gallery(label="Multi Images")
125
+ with gr.Row():
126
+ img_seed = gr.Slider(minimum=0, maximum=100, value=0, label="Seed")
127
+ ss_guidance = gr.Slider(minimum=0, maximum=10, value=7.5, label="SS Guidance Strength")
128
+ with gr.Row():
129
+ ss_steps = gr.Slider(minimum=0, maximum=20, value=12, label="SS Sampling Steps")
130
+ slat_guidance = gr.Slider(minimum=0, maximum=10, value=3, label="SLAT Guidance Strength")
131
+ with gr.Row():
132
+ slat_steps = gr.Slider(minimum=0, maximum=20, value=12, label="SLAT Sampling Steps")
133
+ algo = gr.Radio(choices=["stochastic", "multidiffusion"], value="stochastic", label="Multi-image Algorithm")
134
+ generate_btn = gr.Button("Generate 3D")
135
+ video_output = gr.Video(label="Generated 3D")
136
+ generate_btn.click(
137
+ fn=image_to_3d,
138
+ inputs=[img_input, multi_imgs, img_seed, ss_guidance, ss_steps, slat_guidance, slat_steps, algo],
139
+ outputs=video_output
140
+ )
141
+
142
+ with gr.Tab("Extract GLB"):
143
+ with gr.Row():
144
+ mesh_simplify = gr.Slider(minimum=0, maximum=1, value=0.95, label="Mesh Simplify")
145
+ texture_size = gr.Slider(minimum=0, maximum=2048, value=1024, label="Texture Size")
146
+ extract_glb_btn = gr.Button("Extract GLB")
147
+ glb_output = gr.File(label="GLB File")
148
+ extract_glb_btn.click(fn=extract_glb, inputs=[mesh_simplify, texture_size], outputs=glb_output)
149
+
150
+ with gr.Tab("Extract Gaussian"):
151
+ extract_gaussian_btn = gr.Button("Extract Gaussian")
152
+ gaussian_output = gr.File(label="Gaussian File")
153
+ extract_gaussian_btn.click(fn=extract_gaussian, inputs=[], outputs=gaussian_output)
154
+
155
+ # Add remaining lambda functions as simple buttons with text output
156
+ for name, func in [
157
+ ("Lambda 2", lambda_2_function),
158
+ ("Lambda 3", lambda_3_function),
159
+ ("Lambda 4", lambda_4_function),
160
+ ("Lambda 5", lambda_5_function),
161
+ ("Lambda 6", lambda_6_function),
162
+ ]:
163
+ with gr.Tab(name):
164
+ btn = gr.Button(f"Run {name}")
165
+ output = gr.Textbox(label="Output")
166
+ btn.click(fn=func, inputs=[], outputs=output)
167
+
168
+ demo.launch()