Zaiiida commited on
Commit
a93cd0b
·
verified ·
1 Parent(s): b17ae2c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -39
app.py CHANGED
@@ -13,25 +13,19 @@ from functools import partial
13
  from tsr.system import TSR
14
  from tsr.utils import remove_background, resize_foreground, to_gradio_3d_orientation
15
 
16
- # HF_TOKEN = os.getenv("HF_TOKEN")
17
-
18
- HEADER = """
19
- """
20
-
21
  if torch.cuda.is_available():
22
  device = "cuda:0"
23
  else:
24
  device = "cpu"
25
 
26
  d = os.environ.get("DEVICE", None)
27
- if d!= None:
28
  device = d
29
 
30
  model = TSR.from_pretrained(
31
  "stabilityai/TripoSR",
32
  config_name="config.yaml",
33
  weight_name="model.ckpt",
34
- # token=HF_TOKEN
35
  )
36
  model.renderer.set_chunk_size(131072)
37
  model.to(device)
@@ -74,28 +68,21 @@ def generate(image):
74
  return mesh_path.name, mesh_path2.name
75
 
76
 
77
- def run_example(image_pil):
78
- preprocessed = preprocess(image_pil, False, 0.9)
79
- mesh_name, mesn_name2 = generate(preprocessed)
80
- return preprocessed, mesh_name, mesn_name2
81
-
82
-
83
  class CustomTheme(gr.themes.Base):
84
  def __init__(self):
85
  super().__init__()
86
  self.primary_hue = "#191a1e"
87
- self.background_fill_primary = "#191a1e"
88
- self.background_fill_secondary = "#191a1e"
89
- self.background_fill_tertiary = "#191a1e"
90
  self.text_color_primary = "#FFFFFF"
91
  self.text_color_secondary = "#FFFFFF"
92
  self.text_color_tertiary = "#FFFFFF"
93
- self.input_background_fill = "#191a1e"
94
  self.input_text_color = "#FFFFFF"
95
 
96
 
97
  css = """
98
- /* Скрываем нижний колонтитул */
99
  footer {
100
  visibility: hidden;
101
  height: 0;
@@ -104,29 +91,24 @@ footer {
104
  overflow: hidden;
105
  }
106
 
107
- /* Применяем шрифты */
108
- @import url('https://fonts.googleapis.com/css2?family=Poppins:wght@400;500;700&display=swap');
109
  body, input, button, textarea, select, .gr-button {
110
  font-family: 'Poppins', sans-serif;
111
- background-color: #191a1e !important;
112
  color: #FFFFFF;
113
  }
114
 
115
- /* Настройки заголовков */
116
  h1, h2, h3, h4, h5, h6 {
117
  font-family: 'Poppins', sans-serif;
118
  font-weight: 700;
119
  color: #FFFFFF;
120
  }
121
 
122
- /* Стиль для текстовых полей и кнопок */
123
  input[type="text"], textarea {
124
- background-color: #191a1e !important;
125
  color: #FFFFFF;
126
  border: 1px solid #FFFFFF;
127
  }
128
 
129
- /* Цвет кнопки Generate */
130
  .generate-button {
131
  background-color: #5271FF !important;
132
  color: #FFFFFF !important;
@@ -135,18 +117,18 @@ input[type="text"], textarea {
135
  }
136
 
137
  .generate-button:hover {
138
- background-color: #405BBF !important; /* Цвет при наведении */
139
  }
140
 
141
  gr-image-upload {
142
- background-color: transparent !important; /* Прозрачный фон */
143
- border: 1px dashed #FFFFFF !important; /* Белая пунктирная рамка */
144
- position: relative; /* Для позиционирования текста */
145
  }
146
 
147
  .gr-image-upload .dropzone::before {
148
  content: 'Drop Image Here';
149
- color: #FFFFFF; /* Белый цвет текста */
150
  font-size: 1rem;
151
  font-weight: bold;
152
  text-align: center;
@@ -155,12 +137,11 @@ gr-image-upload {
155
  left: 50%;
156
  transform: translate(-50%, -50%);
157
  }
158
- /* Скрытие стандартной иконки загрузки */
159
  .gr-image-upload .dropzone .file-upload {
160
  display: none !important;
161
  }
162
 
163
- /* Выравнивание элементов */
164
  .drop-image-container {
165
  display: flex;
166
  flex-direction: column;
@@ -182,12 +163,11 @@ gr-image-upload {
182
  margin-right: auto;
183
  }
184
  """
 
185
  with gr.Blocks(theme=CustomTheme(), css=css) as demo:
186
  with gr.Column(elem_id="main-container"):
187
- # Заголовок
188
  gr.Markdown("**Upload and Process Your Image**", elem_classes="prompt-text")
189
 
190
- # Размещение изображений
191
  with gr.Row(elem_id="image-row"):
192
  input_image = gr.Image(
193
  label="Upload Image",
@@ -206,7 +186,6 @@ with gr.Blocks(theme=CustomTheme(), css=css) as demo:
206
  height=300,
207
  )
208
 
209
- # Слайдер для параметров
210
  with gr.Row(elem_id="slider-row"):
211
  foreground_ratio = gr.Slider(
212
  label="Foreground Ratio",
@@ -216,7 +195,6 @@ with gr.Blocks(theme=CustomTheme(), css=css) as demo:
216
  step=0.05,
217
  )
218
 
219
- # Настройки и кнопка генерации
220
  with gr.Row(elem_id="settings-row"):
221
  do_remove_background = gr.Checkbox(
222
  label="Remove Background",
@@ -229,7 +207,6 @@ with gr.Blocks(theme=CustomTheme(), css=css) as demo:
229
  elem_classes="generate-button",
230
  )
231
 
232
- # Результ��ты генерации
233
  with gr.Row(elem_id="output-model-container"):
234
  with gr.Tab("OBJ Model"):
235
  output_model = gr.Model3D(
@@ -242,7 +219,6 @@ with gr.Blocks(theme=CustomTheme(), css=css) as demo:
242
  interactive=False,
243
  )
244
 
245
- # Привязка событий
246
  submit.click(
247
  fn=check_input_image,
248
  inputs=[input_image],
@@ -257,6 +233,5 @@ with gr.Blocks(theme=CustomTheme(), css=css) as demo:
257
  outputs=[output_model, output_model2]
258
  )
259
 
260
- # Запуск интерфейса
261
  demo.queue(max_size=10)
262
  demo.launch()
 
13
  from tsr.system import TSR
14
  from tsr.utils import remove_background, resize_foreground, to_gradio_3d_orientation
15
 
 
 
 
 
 
16
  if torch.cuda.is_available():
17
  device = "cuda:0"
18
  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(
26
  "stabilityai/TripoSR",
27
  config_name="config.yaml",
28
  weight_name="model.ckpt",
 
29
  )
30
  model.renderer.set_chunk_size(131072)
31
  model.to(device)
 
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
 
85
  css = """
 
86
  footer {
87
  visibility: hidden;
88
  height: 0;
 
91
  overflow: hidden;
92
  }
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
 
 
100
  h1, h2, h3, h4, h5, h6 {
101
  font-family: 'Poppins', sans-serif;
102
  font-weight: 700;
103
  color: #FFFFFF;
104
  }
105
 
 
106
  input[type="text"], textarea {
107
+ background-color: #1a1a1a !important;
108
  color: #FFFFFF;
109
  border: 1px solid #FFFFFF;
110
  }
111
 
 
112
  .generate-button {
113
  background-color: #5271FF !important;
114
  color: #FFFFFF !important;
 
117
  }
118
 
119
  .generate-button:hover {
120
+ background-color: #405BBF !important;
121
  }
122
 
123
  gr-image-upload {
124
+ background-color: #1a1a1a !important;
125
+ border: 1px dashed #FFFFFF !important;
126
+ position: relative;
127
  }
128
 
129
  .gr-image-upload .dropzone::before {
130
  content: 'Drop Image Here';
131
+ color: #FFFFFF;
132
  font-size: 1rem;
133
  font-weight: bold;
134
  text-align: center;
 
137
  left: 50%;
138
  transform: translate(-50%, -50%);
139
  }
140
+
141
  .gr-image-upload .dropzone .file-upload {
142
  display: none !important;
143
  }
144
 
 
145
  .drop-image-container {
146
  display: flex;
147
  flex-direction: column;
 
163
  margin-right: auto;
164
  }
165
  """
166
+
167
  with gr.Blocks(theme=CustomTheme(), css=css) as demo:
168
  with gr.Column(elem_id="main-container"):
 
169
  gr.Markdown("**Upload and Process Your Image**", elem_classes="prompt-text")
170
 
 
171
  with gr.Row(elem_id="image-row"):
172
  input_image = gr.Image(
173
  label="Upload Image",
 
186
  height=300,
187
  )
188
 
 
189
  with gr.Row(elem_id="slider-row"):
190
  foreground_ratio = gr.Slider(
191
  label="Foreground Ratio",
 
195
  step=0.05,
196
  )
197
 
 
198
  with gr.Row(elem_id="settings-row"):
199
  do_remove_background = gr.Checkbox(
200
  label="Remove Background",
 
207
  elem_classes="generate-button",
208
  )
209
 
 
210
  with gr.Row(elem_id="output-model-container"):
211
  with gr.Tab("OBJ Model"):
212
  output_model = gr.Model3D(
 
219
  interactive=False,
220
  )
221
 
 
222
  submit.click(
223
  fn=check_input_image,
224
  inputs=[input_image],
 
233
  outputs=[output_model, output_model2]
234
  )
235
 
 
236
  demo.queue(max_size=10)
237
  demo.launch()