Update app.py
Browse files
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 |
-
|
125 |
-
|
126 |
-
|
|
|
|
|
|
|
127 |
else:
|
128 |
-
#
|
129 |
-
choices =
|
|
|
|
|
|
|
|
|
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 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
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 |
# ํ๋กฌํํธ ์์ฑ ๋ฒํผ ํด๋ฆญ ์ด๋ฒคํธ
|