Zaiiida commited on
Commit
b3b3c92
·
verified ·
1 Parent(s): 8f92845

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -51
app.py CHANGED
@@ -19,7 +19,7 @@ else:
19
  device = "cpu"
20
 
21
  d = os.environ.get("DEVICE", None)
22
- if d != None:
23
  device = d
24
 
25
  model = TSR.from_pretrained(
@@ -61,24 +61,22 @@ def generate(image):
61
  scene_codes = model(image, device=device)
62
  mesh = model.extract_mesh(scene_codes)[0]
63
  mesh = to_gradio_3d_orientation(mesh)
64
- mesh_path = tempfile.NamedTemporaryFile(suffix=".obj", delete=False)
65
  mesh_path2 = tempfile.NamedTemporaryFile(suffix=".glb", delete=False)
66
- mesh.export(mesh_path.name)
67
  mesh.export(mesh_path2.name)
68
- return mesh_path.name, mesh_path2.name
69
 
70
 
71
  class CustomTheme(gr.themes.Base):
72
  def __init__(self):
73
  super().__init__()
74
  self.primary_hue = "#191a1e"
75
- self.background_fill_primary = "#1a1a1a"
76
- self.background_fill_secondary = "#1a1a1a"
77
- self.background_fill_tertiary = "#1a1a1a"
78
  self.text_color_primary = "#FFFFFF"
79
  self.text_color_secondary = "#FFFFFF"
80
  self.text_color_tertiary = "#FFFFFF"
81
- self.input_background_fill = "#1a1a1a"
82
  self.input_text_color = "#FFFFFF"
83
 
84
 
@@ -93,7 +91,7 @@ footer {
93
 
94
  body, input, button, textarea, select, .gr-button {
95
  font-family: 'Poppins', sans-serif;
96
- background-color: #1a1a1a !important;
97
  color: #FFFFFF;
98
  }
99
 
@@ -104,7 +102,7 @@ h1, h2, h3, h4, h5, h6 {
104
  }
105
 
106
  input[type="text"], textarea {
107
- background-color: #1a1a1a !important;
108
  color: #FFFFFF;
109
  border: 1px solid #FFFFFF;
110
  }
@@ -121,7 +119,7 @@ input[type="text"], textarea {
121
  }
122
 
123
  gr-image-upload {
124
- background-color: #1a1a1a !important;
125
  border: 1px dashed #FFFFFF !important;
126
  position: relative;
127
  }
@@ -157,27 +155,7 @@ gr-image-upload {
157
  margin-bottom: 20px;
158
  }
159
 
160
- /* Кнопка сброса возле слайдера */
161
- .slider-reset-button {
162
- width: 25px;
163
- height: 25px;
164
- margin-left: 10px; /* Отступ от значения слайдера */
165
- background-color: #5271FF; /* Цвет кнопки */
166
- color: #FFFFFF;
167
- border: none;
168
- border-radius: 50%; /* Скругление для круглой кнопки */
169
- font-size: 14px;
170
- display: flex;
171
- align-items: center;
172
- justify-content: center;
173
- cursor: pointer;
174
- }
175
-
176
- .slider-reset-button:hover {
177
- background-color: #405BBF; /* Цвет при наведении */
178
- }
179
-
180
- /* Вкладки OBJ/GLB Model */
181
  .gr-tab {
182
  background-color: #252525; /* Чуть светлее общий фон */
183
  border: 1px solid #FFFFFF; /* Белая рамка для структуры */
@@ -189,7 +167,6 @@ gr-image-upload {
189
  color: #FFFFFF; /* Цвет текста */
190
  font-weight: bold;
191
  }
192
-
193
  """
194
 
195
  with gr.Blocks(theme=CustomTheme(), css=css) as demo:
@@ -222,17 +199,7 @@ with gr.Blocks(theme=CustomTheme(), css=css) as demo:
222
  value=0.85,
223
  step=0.05,
224
  )
225
- reset_button = gr.Button(
226
- "↺", # Символ кнопки сброса
227
- elem_classes="slider-reset-button",
228
- interactive=True,
229
- )
230
-
231
- reset_button.click(
232
- fn=lambda: 0.85, # Значение по умолчанию
233
- inputs=[],
234
- outputs=[foreground_ratio],
235
- )
236
 
237
  with gr.Row(elem_id="settings-row"):
238
  do_remove_background = gr.Checkbox(
@@ -247,11 +214,6 @@ with gr.Blocks(theme=CustomTheme(), css=css) as demo:
247
  )
248
 
249
  with gr.Row(elem_id="output-model-container"):
250
- with gr.Tab("OBJ Model"):
251
- output_model = gr.Model3D(
252
- label="Generated OBJ Model",
253
- interactive=False,
254
- )
255
  with gr.Tab("GLB Model"):
256
  output_model2 = gr.Model3D(
257
  label="Generated GLB Model",
@@ -269,9 +231,8 @@ with gr.Blocks(theme=CustomTheme(), css=css) as demo:
269
  ).then(
270
  fn=generate,
271
  inputs=[processed_image],
272
- outputs=[output_model, output_model2]
273
  )
274
 
275
-
276
  demo.queue(max_size=10)
277
  demo.launch()
 
19
  device = "cpu"
20
 
21
  d = os.environ.get("DEVICE", None)
22
+ if d is not None:
23
  device = d
24
 
25
  model = TSR.from_pretrained(
 
61
  scene_codes = model(image, device=device)
62
  mesh = model.extract_mesh(scene_codes)[0]
63
  mesh = to_gradio_3d_orientation(mesh)
 
64
  mesh_path2 = tempfile.NamedTemporaryFile(suffix=".glb", delete=False)
 
65
  mesh.export(mesh_path2.name)
66
+ return mesh_path2.name
67
 
68
 
69
  class CustomTheme(gr.themes.Base):
70
  def __init__(self):
71
  super().__init__()
72
  self.primary_hue = "#191a1e"
73
+ self.background_fill_primary = "#191a1e"
74
+ self.background_fill_secondary = "#191a1e"
75
+ self.background_fill_tertiary = "#191a1e"
76
  self.text_color_primary = "#FFFFFF"
77
  self.text_color_secondary = "#FFFFFF"
78
  self.text_color_tertiary = "#FFFFFF"
79
+ self.input_background_fill = "#191a1e"
80
  self.input_text_color = "#FFFFFF"
81
 
82
 
 
91
 
92
  body, input, button, textarea, select, .gr-button {
93
  font-family: 'Poppins', sans-serif;
94
+ background-color: #191a1e !important;
95
  color: #FFFFFF;
96
  }
97
 
 
102
  }
103
 
104
  input[type="text"], textarea {
105
+ background-color: #191a1e !important;
106
  color: #FFFFFF;
107
  border: 1px solid #FFFFFF;
108
  }
 
119
  }
120
 
121
  gr-image-upload {
122
+ background-color: #191a1e !important;
123
  border: 1px dashed #FFFFFF !important;
124
  position: relative;
125
  }
 
155
  margin-bottom: 20px;
156
  }
157
 
158
+ /* Вкладки GLB Model */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
159
  .gr-tab {
160
  background-color: #252525; /* Чуть светлее общий фон */
161
  border: 1px solid #FFFFFF; /* Белая рамка для структуры */
 
167
  color: #FFFFFF; /* Цвет текста */
168
  font-weight: bold;
169
  }
 
170
  """
171
 
172
  with gr.Blocks(theme=CustomTheme(), css=css) as demo:
 
199
  value=0.85,
200
  step=0.05,
201
  )
202
+ # Кнопка Reset удалена
 
 
 
 
 
 
 
 
 
 
203
 
204
  with gr.Row(elem_id="settings-row"):
205
  do_remove_background = gr.Checkbox(
 
214
  )
215
 
216
  with gr.Row(elem_id="output-model-container"):
 
 
 
 
 
217
  with gr.Tab("GLB Model"):
218
  output_model2 = gr.Model3D(
219
  label="Generated GLB Model",
 
231
  ).then(
232
  fn=generate,
233
  inputs=[processed_image],
234
+ outputs=[output_model2]
235
  )
236
 
 
237
  demo.queue(max_size=10)
238
  demo.launch()