hysts HF Staff commited on
Commit
5c357b0
Β·
verified Β·
1 Parent(s): a88ceac

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +102 -0
app.py ADDED
@@ -0,0 +1,102 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+
3
+ with gr.Blocks(delete_cache=(600, 600)) as demo:
4
+ gr.Markdown("# 🎨 SeqTex: Generate Mesh Textures in Video Sequence")
5
+
6
+ gr.Markdown("""
7
+ ## πŸš€ Welcome to SeqTex!
8
+ **SeqTex** is a cutting-edge AI system that generates high-quality textures for 3D meshes using image prompts (here we use image generator to get them from textual prompts).
9
+ Choose to either **try our example models** below or **upload your own 3D mesh** to create stunning textures.
10
+ """)
11
+
12
+ gr.Markdown("---")
13
+
14
+ gr.Markdown("## πŸ”§ Step 1: Upload & Process 3D Mesh")
15
+ gr.Markdown("""
16
+ **πŸ“‹ How to prepare your 3D mesh:**
17
+ - Upload your 3D mesh in **.obj** or **.glb** format
18
+ - **πŸ’‘ Pro Tip**:
19
+ - For optimal results, ensure your mesh includes only one part with <span style="color:#e74c3c; font-weight:bold;">UV parameterization</span>
20
+ - Otherwise, we'll combine all parts and generate UV parameterization using *xAtlas* (may take longer for high-poly meshes; may also fail for certain meshes)
21
+ - **⚠️ Important**: We recommend adjusting your model using *Mesh Orientation Adjustments* to be **Z-UP oriented** for best results
22
+ """)
23
+ position_map_tensor_path = gr.State()
24
+ normal_map_tensor_path = gr.State()
25
+ position_images_tensor_path = gr.State()
26
+ normal_images_tensor_path = gr.State()
27
+ mask_images_tensor_path = gr.State()
28
+ w2c_tensor_path = gr.State()
29
+ mesh = gr.State()
30
+ mvp_matrix_tensor_path = gr.State()
31
+
32
+ # fixed_texture_map = Image.open("image.webp").convert("RGB")
33
+ # Step 1
34
+ with gr.Row():
35
+ with gr.Column():
36
+ mesh_upload = gr.File(label="πŸ“ Upload 3D Mesh", file_types=[".obj", ".glb"])
37
+ # uv_tool = gr.Radio(["xAtlas", "UVAtlas"], label="UV parameterizer", value="xAtlas")
38
+
39
+ gr.Markdown("**πŸ”„ Mesh Orientation Adjustments** (if needed):")
40
+ y2z = gr.Checkbox(label="Y β†’ Z Transform", value=False, info="Rotate: Y becomes Z, -Z becomes Y")
41
+ y2x = gr.Checkbox(label="Y β†’ X Transform", value=False, info="Rotate: Y becomes X, -X becomes Y")
42
+ z2x = gr.Checkbox(label="Z β†’ X Transform", value=False, info="Rotate: Z becomes X, -X becomes Z")
43
+ upside_down = gr.Checkbox(label="πŸ”ƒ Flip Vertically", value=False, info="Fix upside-down mesh orientation")
44
+ step1_button = gr.Button("πŸ”„ Process Mesh & Generate Views", variant="primary")
45
+ step1_progress = gr.Textbox(label="πŸ“Š Processing Status", interactive=False)
46
+
47
+ with gr.Column():
48
+ model_input = gr.Model3D(label="πŸ“ Processed 3D Model", height=500)
49
+
50
+ with gr.Row(equal_height=True):
51
+ rgb_views = gr.Image(label="πŸ“· Generated Views", type="pil", scale=3)
52
+ position_map = gr.Image(label="πŸ—ΊοΈ Position Map", type="pil", scale=1)
53
+ normal_map = gr.Image(label="🧭 Normal Map", type="pil", scale=1)
54
+
55
+ # Step 2
56
+ gr.Markdown("---")
57
+ gr.Markdown("## πŸ‘οΈ Step 2: Select View & Generate Image Condition")
58
+ gr.Markdown("""
59
+ **πŸ“‹ How to generate image condition:**
60
+ - Your mesh will be rendered from **four viewpoints** (front, back, left, right)
61
+ - Choose **one view** as your image condition
62
+ - Enter a **descriptive text prompt** for the desired texture
63
+ - Select your preferred AI model:
64
+ - <span style="color:#27ae60; font-weight:bold;">🎯 SDXL</span>: Fast generation with depth + normal control, better details (often suffer from wrong highlights)
65
+ - <span style="color:#3498db; font-weight:bold;">⚑ FLUX</span>: ~~High-quality generation with depth control (slower due to CPU offloading). Better work with **Edge Refinement**~~ (Not supported due to the memory limit of HF Space. You can try it locally)
66
+ """)
67
+ with gr.Row():
68
+ with gr.Column():
69
+ img_condition_seed = gr.Number(label="🎲 Random Seed", minimum=0, maximum=9999, step=1, value=42, info="Change for different results")
70
+ selected_view = gr.Radio(["First View", "Second View", "Third View", "Fourth View"], label="πŸ“ Camera View", value="First View", info="Choose which viewpoint to use as reference")
71
+ with gr.Row():
72
+ # model_choice = gr.Radio(["SDXL", "FLUX"], label="πŸ€– AI Model", value="SDXL", info="SDXL: Fast, depth+normal control | FLUX: High-quality, slower processing")
73
+ model_choice = gr.Radio(["SDXL"], label="πŸ€– AI Model", value="SDXL", info="SDXL: Fast, depth+normal control | FLUX: High-quality, slower processing (Not supported due to the memory limit of HF Space)")
74
+ edge_refinement = gr.Checkbox(label="✨ Edge Refinement", value=True, info="Smooth boundary artifacts (recommended for delightning highlights in the boundary)")
75
+ text_prompt = gr.Textbox(label="πŸ’¬ Texture Description", placeholder="Describe the desired texture appearance (e.g., 'rustic wooden surface with weathered paint')", lines=2)
76
+ step2_button = gr.Button("🎯 Generate Image Condition", variant="primary")
77
+ step2_progress = gr.Textbox(label="πŸ“Š Generation Status", interactive=False)
78
+
79
+ with gr.Column():
80
+ condition_image = gr.Image(label="πŸ–ΌοΈ Generated Image Condition", type="pil") # , interactive=False
81
+
82
+ # Step 3
83
+ gr.Markdown("---")
84
+ gr.Markdown("## 🎨 Step 3: Generate Final Texture")
85
+ gr.Markdown("""
86
+ **πŸ“‹ How to generate final texture:**
87
+ - The **SeqTex pipeline** will create a complete texture map for your model
88
+ - View the results from multiple angles and download your textured 3D model (the viewport is a little bit dark)
89
+ """)
90
+ texture_map_tensor_path = gr.State()
91
+ with gr.Row():
92
+ with gr.Column(scale=1):
93
+ step3_button = gr.Button("🎨 Generate Final Texture", variant="primary")
94
+ step3_progress = gr.Textbox(label="πŸ“Š Texture Generation Status", interactive=False)
95
+ texture_map = gr.Image(label="πŸ† Generated Texture Map", interactive=False)
96
+ with gr.Column(scale=2):
97
+ rendered_imgs = gr.Image(label="πŸ–ΌοΈ Final Rendered Views")
98
+ mv_branch_imgs = gr.Image(label="πŸ–ΌοΈ SeqTex Direct Output")
99
+ with gr.Column(scale=1.5):
100
+ model_display = gr.Model3D(label="πŸ† Final Textured Model", height=500)
101
+
102
+ demo.launch()