Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
@@ -1,6 +1,7 @@
|
|
1 |
import gradio as gr
|
2 |
import spaces
|
3 |
from gradio_litmodel3d import LitModel3D
|
|
|
4 |
|
5 |
import os
|
6 |
os.environ['SPCONV_ALGO'] = 'native'
|
@@ -78,6 +79,19 @@ def unpack_state(state: dict) -> Tuple[Gaussian, edict, str]:
|
|
78 |
return gs, mesh, state['trial_id']
|
79 |
|
80 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
81 |
@spaces.GPU
|
82 |
def image_to_3d(trial_id: str, seed: int, randomize_seed: bool, ss_guidance_strength: float, ss_sampling_steps: int, slat_guidance_strength: float, slat_sampling_steps: int) -> Tuple[dict, str]:
|
83 |
"""
|
@@ -160,6 +174,10 @@ with gr.Blocks(theme="Yntec/HaleyCH_Theme_Orange", css=css) as demo:
|
|
160 |
|
161 |
with gr.Row():
|
162 |
with gr.Column():
|
|
|
|
|
|
|
|
|
163 |
image_prompt = gr.Image(label="Image Prompt", image_mode="RGBA", type="pil", height=300)
|
164 |
|
165 |
with gr.Accordion(label="Generation Settings", open=False):
|
@@ -205,6 +223,16 @@ with gr.Blocks(theme="Yntec/HaleyCH_Theme_Orange", css=css) as demo:
|
|
205 |
)
|
206 |
|
207 |
# Handlers
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
208 |
image_prompt.upload(
|
209 |
preprocess_image,
|
210 |
inputs=[image_prompt],
|
@@ -248,6 +276,11 @@ with gr.Blocks(theme="Yntec/HaleyCH_Theme_Orange", css=css) as demo:
|
|
248 |
if __name__ == "__main__":
|
249 |
pipeline = TrellisImageTo3DPipeline.from_pretrained("JeffreyXiang/TRELLIS-image-large")
|
250 |
pipeline.cuda()
|
|
|
|
|
|
|
|
|
|
|
251 |
try:
|
252 |
pipeline.preprocess_image(Image.fromarray(np.zeros((512, 512, 3), dtype=np.uint8))) # Preload rembg
|
253 |
except:
|
|
|
1 |
import gradio as gr
|
2 |
import spaces
|
3 |
from gradio_litmodel3d import LitModel3D
|
4 |
+
from diffusers import StableDiffusionPipeline
|
5 |
|
6 |
import os
|
7 |
os.environ['SPCONV_ALGO'] = 'native'
|
|
|
79 |
return gs, mesh, state['trial_id']
|
80 |
|
81 |
|
82 |
+
@spaces.GPU
|
83 |
+
def text_to_image(prompt: str, seed: int, randomize_seed: bool) -> Image.Image:
|
84 |
+
"""
|
85 |
+
Generate image from text prompt using Stable Diffusion.
|
86 |
+
"""
|
87 |
+
if randomize_seed:
|
88 |
+
seed = np.random.randint(0, MAX_SEED)
|
89 |
+
|
90 |
+
generator = torch.Generator(device="cuda").manual_seed(seed)
|
91 |
+
image = text2img_pipeline(prompt, generator=generator).images[0]
|
92 |
+
return image
|
93 |
+
|
94 |
+
|
95 |
@spaces.GPU
|
96 |
def image_to_3d(trial_id: str, seed: int, randomize_seed: bool, ss_guidance_strength: float, ss_sampling_steps: int, slat_guidance_strength: float, slat_sampling_steps: int) -> Tuple[dict, str]:
|
97 |
"""
|
|
|
174 |
|
175 |
with gr.Row():
|
176 |
with gr.Column():
|
177 |
+
# Text to Image 부분 추가
|
178 |
+
text_prompt = gr.Textbox(label="Text Prompt", placeholder="Enter your text prompt here...")
|
179 |
+
generate_image_btn = gr.Button("Generate Image")
|
180 |
+
|
181 |
image_prompt = gr.Image(label="Image Prompt", image_mode="RGBA", type="pil", height=300)
|
182 |
|
183 |
with gr.Accordion(label="Generation Settings", open=False):
|
|
|
223 |
)
|
224 |
|
225 |
# Handlers
|
226 |
+
generate_image_btn.click(
|
227 |
+
text_to_image,
|
228 |
+
inputs=[text_prompt, seed, randomize_seed],
|
229 |
+
outputs=[image_prompt],
|
230 |
+
).then(
|
231 |
+
preprocess_image,
|
232 |
+
inputs=[image_prompt],
|
233 |
+
outputs=[trial_id, image_prompt],
|
234 |
+
)
|
235 |
+
|
236 |
image_prompt.upload(
|
237 |
preprocess_image,
|
238 |
inputs=[image_prompt],
|
|
|
276 |
if __name__ == "__main__":
|
277 |
pipeline = TrellisImageTo3DPipeline.from_pretrained("JeffreyXiang/TRELLIS-image-large")
|
278 |
pipeline.cuda()
|
279 |
+
|
280 |
+
# Stable Diffusion pipeline 추가
|
281 |
+
text2img_pipeline = StableDiffusionPipeline.from_pretrained("runwayml/stable-diffusion-v1-5")
|
282 |
+
text2img_pipeline.to("cuda")
|
283 |
+
|
284 |
try:
|
285 |
pipeline.preprocess_image(Image.fromarray(np.zeros((512, 512, 3), dtype=np.uint8))) # Preload rembg
|
286 |
except:
|