ssboost commited on
Commit
809e3e8
ยท
verified ยท
1 Parent(s): 7b339a1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +45 -39
app.py CHANGED
@@ -114,34 +114,49 @@ class GradioClientController:
114
  def _parse_dropdown_result(self, result):
115
  """API ์‘๋‹ต์—์„œ ์‹ค์ œ ์„ ํƒ์ง€ ๋ฐ์ดํ„ฐ๋งŒ ์ถ”์ถœ"""
116
  try:
 
 
117
  if isinstance(result, (list, tuple)):
118
  parsed_choices = []
119
- for item in result:
 
 
120
  if isinstance(item, dict):
121
  # Gradio ์‘๋‹ต์—์„œ choices ์ถ”์ถœ
122
  if 'choices' in item:
123
  choices = item['choices']
124
- elif '__type__' in item and 'choices' in str(item):
125
- # __type__ ๊ตฌ์กฐ์—์„œ choices ์ฐพ๊ธฐ
126
- choices = item.get('choices', [])
 
 
 
127
  else:
128
- # ์ง์ ‘ ๋ฆฌ์ŠคํŠธ์ธ ๊ฒฝ์šฐ
129
- choices = item if isinstance(item, list) else []
 
 
 
 
130
  elif isinstance(item, list):
131
  # ์ด๋ฏธ ๋ฆฌ์ŠคํŠธ์ธ ๊ฒฝ์šฐ
132
  choices = item
 
133
  else:
134
  # ๋ฌธ์ž์—ด์ด๊ฑฐ๋‚˜ ๊ธฐํƒ€ ํƒ€์ž…
135
  choices = [str(item)] if item else []
 
136
 
137
  parsed_choices.append(choices)
138
 
 
139
  return parsed_choices
140
  else:
141
  logger.warning(f"์˜ˆ์ƒํ•˜์ง€ ๋ชปํ•œ ์‘๋‹ต ํ˜•์‹: {type(result)}")
142
  return [[] for _ in range(7)]
143
  except Exception as e:
144
  logger.error(f"๋“œ๋กญ๋‹ค์šด ๊ฒฐ๊ณผ ํŒŒ์‹ฑ ์˜ค๋ฅ˜: {str(e)}")
 
145
  return [[] for _ in range(7)]
146
 
147
  def get_initial_simple_choices(self) -> list:
@@ -194,7 +209,7 @@ class GradioClientController:
194
  result = self.background_options[bg_type]
195
  logger.info(f"์บ์‹œ๋œ ๋“œ๋กญ๋‹ค์šด ๋ฐ์ดํ„ฐ ์‚ฌ์šฉ: {bg_type}")
196
  else:
197
- return tuple([gr.update() for _ in range(7)])
198
  else:
199
  # ์‹ค์‹œ๊ฐ„์œผ๋กœ API ํ˜ธ์ถœ
200
  result = self.client.predict(bg_type, api_name="/update_dropdowns")
@@ -214,45 +229,35 @@ class GradioClientController:
214
 
215
  for i, choices in enumerate(result[:7]):
216
  is_visible = (bg_type == visibility_map[i])
217
- first_choice = choices[0] if choices and len(choices) > 0 else None
218
-
219
- logger.info(f"๋“œ๋กญ๋‹ค์šด {i} ({visibility_map[i]}): visible={is_visible}, choices_count={len(choices) if choices else 0}, first_choice={first_choice}")
220
 
221
- updates.append(gr.update(
222
- visible=is_visible,
223
- choices=choices if choices else [],
224
- value=first_choice
225
- ))
 
 
 
 
 
 
 
 
 
 
 
 
 
226
 
227
  return tuple(updates)
228
  else:
229
  logger.warning(f"API์—์„œ ์˜ˆ์ƒ๊ณผ ๋‹ค๋ฅธ ํ˜•์‹์˜ ๊ฒฐ๊ณผ๋ฅผ ๋ฐ˜ํ™˜ํ–ˆ์Šต๋‹ˆ๋‹ค: {type(result)}, length={len(result) if hasattr(result, '__len__') else 'N/A'}")
230
- return tuple([gr.update() for _ in range(7)])
231
 
232
  except Exception as e:
233
  logger.error(f"๋“œ๋กญ๋‹ค์šด ์—…๋ฐ์ดํŠธ ์˜ค๋ฅ˜: {str(e)}")
234
  logger.error(traceback.format_exc())
235
- # ์บ์‹œ๋œ ๋ฐ์ดํ„ฐ ์‹œ๋„
236
- if bg_type in self.background_options:
237
- try:
238
- result = self.background_options[bg_type]
239
- updates = []
240
- visibility_map = ["์‹ฌํ”Œ ๋ฐฐ๊ฒฝ", "์ŠคํŠœ๋””์˜ค ๋ฐฐ๊ฒฝ", "์ž์—ฐ ํ™˜๊ฒฝ", "์‹ค๋‚ด ํ™˜๊ฒฝ", "ํŠน์ˆ˜๋ฐฐ๊ฒฝ", "์ฃผ์–ผ๋ฆฌ", "ํŠน์ˆ˜ํšจ๊ณผ"]
241
-
242
- for i, choices in enumerate(result[:7]):
243
- is_visible = (bg_type == visibility_map[i])
244
- updates.append(gr.update(
245
- visible=is_visible,
246
- choices=choices if choices else [],
247
- value=choices[0] if choices and len(choices) > 0 else None
248
- ))
249
-
250
- logger.info(f"์บ์‹œ๋œ ๋ฐ์ดํ„ฐ๋กœ ๋“œ๋กญ๋‹ค์šด ์—…๋ฐ์ดํŠธ: {bg_type}")
251
- return tuple(updates)
252
- except:
253
- pass
254
-
255
- return tuple([gr.update() for _ in range(7)])
256
 
257
  def generate_prompt_only(self, password: str, bg_type: str, simple: str, studio: str,
258
  nature: str, indoor: str, special: str, jewelry: str,
@@ -514,12 +519,13 @@ def create_gradio_interface():
514
  info = gr.Textbox(label="์ฒ˜๋ฆฌ ์ •๋ณด", interactive=False)
515
  error = gr.Textbox(label="์˜ค๋ฅ˜ ๋ฉ”์‹œ์ง€", interactive=False, visible=True)
516
 
517
- # ๋“œ๋กญ๋‹ค์šด ๋ณ€๊ฒฝ ์ด๋ฒคํŠธ
518
  background_type.change(
519
  fn=controller.update_dropdowns,
520
  inputs=[background_type],
521
  outputs=[simple_dropdown, studio_dropdown, nature_dropdown,
522
- indoor_dropdown, special_dropdown, jewelry_dropdown, special_effects_dropdown]
 
523
  )
524
 
525
  # ํ”„๋กฌํ”„ํŠธ ์ƒ์„ฑ ๋ฒ„ํŠผ ํด๋ฆญ ์ด๋ฒคํŠธ
 
114
  def _parse_dropdown_result(self, result):
115
  """API ์‘๋‹ต์—์„œ ์‹ค์ œ ์„ ํƒ์ง€ ๋ฐ์ดํ„ฐ๋งŒ ์ถ”์ถœ"""
116
  try:
117
+ logger.info(f"์‘๋‹ต ํŒŒ์‹ฑ ์‹œ์ž‘, ์‘๋‹ต ํƒ€์ž…: {type(result)}")
118
+
119
  if isinstance(result, (list, tuple)):
120
  parsed_choices = []
121
+ for i, item in enumerate(result):
122
+ logger.info(f"ํ•ญ๋ชฉ {i}: ํƒ€์ž…={type(item)}, ๊ฐ’={item}")
123
+
124
  if isinstance(item, dict):
125
  # Gradio ์‘๋‹ต์—์„œ choices ์ถ”์ถœ
126
  if 'choices' in item:
127
  choices = item['choices']
128
+ logger.info(f"dict์—์„œ choices ์ถ”์ถœ: {choices}")
129
+ elif '__type__' in item:
130
+ # __type__ ๊ตฌ์กฐ ๋ถ„์„
131
+ logger.info(f"__type__ ๊ตฌ์กฐ ๋ฐœ๊ฒฌ: {item}")
132
+ # ์ผ๋ฐ˜์ ์œผ๋กœ Gradio์—์„œ๋Š” choices๊ฐ€ ๋ณ„๋„ ํ•„๋“œ์— ์žˆ์Œ
133
+ choices = []
134
  else:
135
+ # dict์˜ ๋‹ค๋ฅธ ๊ฐ’๋“ค ํ™•์ธ
136
+ choices = []
137
+ for key, value in item.items():
138
+ if isinstance(value, list) and key != '__type__':
139
+ choices = value
140
+ break
141
  elif isinstance(item, list):
142
  # ์ด๋ฏธ ๋ฆฌ์ŠคํŠธ์ธ ๊ฒฝ์šฐ
143
  choices = item
144
+ logger.info(f"๋ฆฌ์ŠคํŠธ ํ˜•ํƒœ choices: {choices}")
145
  else:
146
  # ๋ฌธ์ž์—ด์ด๊ฑฐ๋‚˜ ๊ธฐํƒ€ ํƒ€์ž…
147
  choices = [str(item)] if item else []
148
+ logger.info(f"๊ธฐํƒ€ ํƒ€์ž…์„ ๋ฌธ์ž์—ด๋กœ ๋ณ€ํ™˜: {choices}")
149
 
150
  parsed_choices.append(choices)
151
 
152
+ logger.info(f"ํŒŒ์‹ฑ ์™„๋ฃŒ: {parsed_choices}")
153
  return parsed_choices
154
  else:
155
  logger.warning(f"์˜ˆ์ƒํ•˜์ง€ ๋ชปํ•œ ์‘๋‹ต ํ˜•์‹: {type(result)}")
156
  return [[] for _ in range(7)]
157
  except Exception as e:
158
  logger.error(f"๋“œ๋กญ๋‹ค์šด ๊ฒฐ๊ณผ ํŒŒ์‹ฑ ์˜ค๋ฅ˜: {str(e)}")
159
+ logger.error(traceback.format_exc())
160
  return [[] for _ in range(7)]
161
 
162
  def get_initial_simple_choices(self) -> list:
 
209
  result = self.background_options[bg_type]
210
  logger.info(f"์บ์‹œ๋œ ๋“œ๋กญ๋‹ค์šด ๋ฐ์ดํ„ฐ ์‚ฌ์šฉ: {bg_type}")
211
  else:
212
+ return tuple([gr.update(visible=False) for _ in range(7)])
213
  else:
214
  # ์‹ค์‹œ๊ฐ„์œผ๋กœ API ํ˜ธ์ถœ
215
  result = self.client.predict(bg_type, api_name="/update_dropdowns")
 
229
 
230
  for i, choices in enumerate(result[:7]):
231
  is_visible = (bg_type == visibility_map[i])
 
 
 
232
 
233
+ # ์„ ํƒ์ง€๊ฐ€ ์žˆ์„ ๋•Œ๋งŒ ์ฒซ ๋ฒˆ์งธ ๊ฐ’์„ ๊ธฐ๋ณธ๊ฐ’์œผ๋กœ ์„ค์ •
234
+ if is_visible and choices and len(choices) > 0:
235
+ first_choice = choices[0]
236
+ logger.info(f"๋“œ๋กญ๋‹ค์šด {i} ({visibility_map[i]}): visible=True, choices={len(choices)}๊ฐœ, default='{first_choice}'")
237
+ updates.append(gr.update(
238
+ visible=True,
239
+ choices=choices,
240
+ value=first_choice,
241
+ interactive=True
242
+ ))
243
+ else:
244
+ logger.info(f"๋“œ๋กญ๋‹ค์šด {i} ({visibility_map[i]}): visible=False")
245
+ updates.append(gr.update(
246
+ visible=False,
247
+ choices=[],
248
+ value=None,
249
+ interactive=True
250
+ ))
251
 
252
  return tuple(updates)
253
  else:
254
  logger.warning(f"API์—์„œ ์˜ˆ์ƒ๊ณผ ๋‹ค๋ฅธ ํ˜•์‹์˜ ๊ฒฐ๊ณผ๋ฅผ ๋ฐ˜ํ™˜ํ–ˆ์Šต๋‹ˆ๋‹ค: {type(result)}, length={len(result) if hasattr(result, '__len__') else 'N/A'}")
255
+ return tuple([gr.update(visible=False) for _ in range(7)])
256
 
257
  except Exception as e:
258
  logger.error(f"๋“œ๋กญ๋‹ค์šด ์—…๋ฐ์ดํŠธ ์˜ค๋ฅ˜: {str(e)}")
259
  logger.error(traceback.format_exc())
260
+ return tuple([gr.update(visible=False) for _ in range(7)])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
261
 
262
  def generate_prompt_only(self, password: str, bg_type: str, simple: str, studio: str,
263
  nature: str, indoor: str, special: str, jewelry: str,
 
519
  info = gr.Textbox(label="์ฒ˜๋ฆฌ ์ •๋ณด", interactive=False)
520
  error = gr.Textbox(label="์˜ค๋ฅ˜ ๋ฉ”์‹œ์ง€", interactive=False, visible=True)
521
 
522
+ # ๋“œ๋กญ๋‹ค์šด ๋ณ€๊ฒฝ ์ด๋ฒคํŠธ - ์ฆ‰์‹œ ์—…๋ฐ์ดํŠธ
523
  background_type.change(
524
  fn=controller.update_dropdowns,
525
  inputs=[background_type],
526
  outputs=[simple_dropdown, studio_dropdown, nature_dropdown,
527
+ indoor_dropdown, special_dropdown, jewelry_dropdown, special_effects_dropdown],
528
+ queue=False # ํ๋ฅผ ์‚ฌ์šฉํ•˜์ง€ ์•Š์•„ ๋” ๋น ๋ฅธ ์‘๋‹ต
529
  )
530
 
531
  # ํ”„๋กฌํ”„ํŠธ ์ƒ์„ฑ ๋ฒ„ํŠผ ํด๋ฆญ ์ด๋ฒคํŠธ