Robledo Gularte Gonçalves commited on
Commit
48e0ad9
·
1 Parent(s): be29abd

fix front: models placement

Browse files
Files changed (1) hide show
  1. app.py +49 -129
app.py CHANGED
@@ -933,7 +933,6 @@ h3.card-title {{
933
  }}
934
  """
935
 
936
- # interface
937
  with gr.Blocks(
938
  title="Nestlé 3D Generator",
939
  css=ADVANCED_CSS,
@@ -950,79 +949,37 @@ with gr.Blocks(
950
  gr.HTML(create_header())
951
 
952
  with gr.Row():
 
953
  with gr.Column(scale=1):
954
- with gr.Group():
955
- gr.HTML("""
956
- <div class="card-header">
957
- <h3 class="card-title">📤 Product Image Upload</h3>
958
- <p class="card-description">Upload a clear image of your Nestlé product</p>
959
- </div>
960
- """)
961
-
962
- image_prompts = gr.Image(
963
- label="",
964
- type="filepath",
965
- show_label=False,
966
- height=350,
967
- elem_classes=["upload-area"]
968
- )
969
 
970
- # Settings Card
971
- with gr.Group():
972
- gr.HTML("""
973
- <div class="card-header">
974
- <h3 class="card-title">⚙️ Generation Settings</h3>
975
- <p class="card-description">Configure your 3D model generation</p>
976
- </div>
977
- """)
978
-
979
- text_prompt = gr.Textbox(label="Prompt", placeholder="Enter your prompt", value="high quality")
980
-
981
- with gr.Row():
982
- randomize_seed = gr.Checkbox(
983
- label="🎲 Randomize Seed",
984
- value=True
985
- )
986
- seed = gr.Slider(
987
- label="Seed Value",
988
- minimum=0,
989
- maximum=MAX_SEED,
990
- step=1,
991
- value=0
992
- )
993
-
994
- num_inference_steps = gr.Slider(
995
- label="🔄 Inference Steps",
996
- minimum=8,
997
- maximum=50,
998
- step=1,
999
- value=50,
1000
- info="Higher values = better quality, slower generation"
1001
- )
1002
-
1003
- guidance_scale = gr.Slider(
1004
- label="🎯 Guidance Scale",
1005
- minimum=0.0,
1006
- maximum=20.0,
1007
- step=0.1,
1008
- value=7.0,
1009
- info="Controls how closely the model follows the input"
1010
- )
1011
-
1012
- with gr.Row():
1013
- reduce_face = gr.Checkbox(
1014
- label="🔧 Optimize Mesh",
1015
- value=True,
1016
- info="Reduce polygon count for better performance"
1017
- )
1018
- target_face_num = gr.Slider(
1019
- label="Target Faces",
1020
- maximum=1_000_000,
1021
- minimum=10_000,
1022
- value=DEFAULT_FACE_NUMBER,
1023
- step=1000
1024
- )
1025
-
1026
  with gr.Column(scale=2):
1027
  gr.HTML("""
1028
  <div class="card-header">
@@ -1031,67 +988,43 @@ with gr.Blocks(
1031
  </div>
1032
  """)
1033
 
1034
- # CT React-like
1035
- gr.HTML(create_tabs())
1036
-
1037
- # PB
1038
- gr.HTML(create_progress_bar())
1039
-
1040
- # Hidden Gradio components for actual functionality
1041
- with gr.Row(visible=True):
1042
- seg_image = gr.Image(type="pil", format="png", interactive=False)
1043
- model_output = gr.Model3D(interactive=False)
1044
- textured_model_output = gr.Model3D(interactive=False)
1045
-
1046
- # Action Buttons
1047
  with gr.Row():
1048
- gen_button = gr.Button(
1049
- "🚀 Generate 3D Model",
1050
- variant="primary",
1051
- size="lg",
1052
- elem_classes=["btn", "btn-primary"]
1053
- )
1054
- gen_texture_button = gr.Button(
1055
- "🎨 Apply Texture",
1056
- variant="secondary",
1057
- size="lg",
1058
- interactive=False,
1059
- elem_classes=["btn", "btn-secondary"]
1060
- )
1061
- download_button = gr.Button(
1062
- "💾 Download Model",
1063
- variant="secondary",
1064
- size="lg",
1065
- elem_classes=["btn", "btn-secondary"]
1066
- )
1067
 
1068
  status_display = gr.HTML(
1069
  """<div style='text-align: center; padding: 1rem; color: #1e293b;'>
1070
- <span style='display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: #10b981; margin-right: 8px;'></span>
1071
- Ready to generate your 3D model
 
1072
  </div>"""
1073
  )
1074
 
1075
- # Event Handlers with JavaScript integration
1076
  gen_button.click(
1077
  fn=run_segmentation,
1078
  inputs=[image_prompts],
1079
  outputs=[seg_image],
1080
- # js="() => { simulateProgress(); document.getElementById('progress-container').style.display = 'block'; }",
1081
  ).then(
1082
  get_random_seed,
1083
  inputs=[randomize_seed, seed],
1084
  outputs=[seed],
1085
  ).then(
1086
  image_to_3d,
1087
- inputs=[
1088
- seg_image,
1089
- seed,
1090
- num_inference_steps,
1091
- guidance_scale,
1092
- reduce_face,
1093
- target_face_num
1094
- ],
1095
  outputs=[model_output]
1096
  ).then(
1097
  fn=lambda: gr.Button(interactive=True),
@@ -1103,22 +1036,9 @@ with gr.Blocks(
1103
  inputs=[image_prompts, model_output, seed, text_prompt],
1104
  outputs=[textured_model_output]
1105
  )
1106
-
1107
- # with gr.Row():
1108
- # examples = gr.Examples(
1109
- # examples=[
1110
- # f"./examples/{image}"
1111
- # for image in os.listdir(f"./examples/")
1112
- # ],
1113
- # fn=run_full,
1114
- # inputs=[image_prompts],
1115
- # outputs=[seg_image, model_output, textured_model_output],
1116
- # cache_examples=False,
1117
- # )
1118
 
1119
  demo.load(start_session)
1120
  demo.unload(end_session)
1121
 
1122
-
1123
  if __name__ == "__main__":
1124
  demo.launch(share=False, show_error=True)
 
933
  }}
934
  """
935
 
 
936
  with gr.Blocks(
937
  title="Nestlé 3D Generator",
938
  css=ADVANCED_CSS,
 
949
  gr.HTML(create_header())
950
 
951
  with gr.Row():
952
+ # Coluna de inputs
953
  with gr.Column(scale=1):
954
+ gr.HTML("""
955
+ <div class="card-header">
956
+ <h3 class="card-title">📤 Product Image Upload</h3>
957
+ <p class="card-description">Upload a clear image of your Nestlé product</p>
958
+ </div>
959
+ """)
960
+ image_prompts = gr.Image(label="", type="filepath", show_label=False, height=350, elem_classes=["upload-area"])
 
 
 
 
 
 
 
 
961
 
962
+ gr.HTML("""
963
+ <div class="card-header">
964
+ <h3 class="card-title">⚙️ Generation Settings</h3>
965
+ <p class="card-description">Configure your 3D model generation</p>
966
+ </div>
967
+ """)
968
+ text_prompt = gr.Textbox(label="Prompt", placeholder="Enter your prompt", value="high quality")
969
+ with gr.Row():
970
+ randomize_seed = gr.Checkbox(label="🎲 Randomize Seed", value=True)
971
+ seed = gr.Slider(label="Seed Value", minimum=0, maximum=MAX_SEED, step=1, value=0)
972
+ num_inference_steps = gr.Slider(label="🔄 Inference Steps", minimum=8, maximum=50, step=1, value=50,
973
+ info="Higher values = better quality, slower generation")
974
+ guidance_scale = gr.Slider(label="🎯 Guidance Scale", minimum=0.0, maximum=20.0, step=0.1, value=7.0,
975
+ info="Controls how closely the model follows the input")
976
+ with gr.Row():
977
+ reduce_face = gr.Checkbox(label="🔧 Optimize Mesh", value=True,
978
+ info="Reduce polygon count for better performance")
979
+ target_face_num = gr.Slider(label="Target Faces", minimum=10_000, maximum=1_000_000,
980
+ value=DEFAULT_FACE_NUMBER, step=1_000)
981
+
982
+ # Coluna de saída com abas nativas Gradio
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
983
  with gr.Column(scale=2):
984
  gr.HTML("""
985
  <div class="card-header">
 
988
  </div>
989
  """)
990
 
991
+ with gr.Tabs():
992
+ with gr.TabItem("🔍 Segmentation"):
993
+ seg_image = gr.Image(type="pil", format="png", interactive=False)
994
+ with gr.TabItem("🎨 3D Model"):
995
+ model_output = gr.Model3D(interactive=False)
996
+ with gr.TabItem("✨ Textured Model"):
997
+ textured_model_output = gr.Model3D(interactive=False)
998
+
999
+ # Botões de ação
 
 
 
 
1000
  with gr.Row():
1001
+ gen_button = gr.Button("🚀 Generate 3D Model", variant="primary", size="lg",
1002
+ elem_classes=["btn", "btn-primary"])
1003
+ gen_texture_button = gr.Button("🎨 Apply Texture", variant="secondary", size="lg",
1004
+ interactive=False, elem_classes=["btn", "btn-secondary"])
1005
+ download_button = gr.Button("💾 Download Model", variant="secondary", size="lg",
1006
+ elem_classes=["btn", "btn-secondary"])
 
 
 
 
 
 
 
 
 
 
 
 
 
1007
 
1008
  status_display = gr.HTML(
1009
  """<div style='text-align: center; padding: 1rem; color: #1e293b;'>
1010
+ <span style='display: inline-block; width: 8px; height: 8px; border-radius: 50%;
1011
+ background: #10b981; margin-right: 8px;'></span>
1012
+ Ready to generate your 3D model
1013
  </div>"""
1014
  )
1015
 
1016
+ # Event handlers continuam iguais, apenas apontando para os objetos seg_image, model_output e textured_model_output
1017
  gen_button.click(
1018
  fn=run_segmentation,
1019
  inputs=[image_prompts],
1020
  outputs=[seg_image],
 
1021
  ).then(
1022
  get_random_seed,
1023
  inputs=[randomize_seed, seed],
1024
  outputs=[seed],
1025
  ).then(
1026
  image_to_3d,
1027
+ inputs=[seg_image, seed, num_inference_steps, guidance_scale, reduce_face, target_face_num],
 
 
 
 
 
 
 
1028
  outputs=[model_output]
1029
  ).then(
1030
  fn=lambda: gr.Button(interactive=True),
 
1036
  inputs=[image_prompts, model_output, seed, text_prompt],
1037
  outputs=[textured_model_output]
1038
  )
 
 
 
 
 
 
 
 
 
 
 
 
1039
 
1040
  demo.load(start_session)
1041
  demo.unload(end_session)
1042
 
 
1043
  if __name__ == "__main__":
1044
  demo.launch(share=False, show_error=True)