Update app.py
Browse files
app.py
CHANGED
@@ -1,2 +1,386 @@
|
|
1 |
import os
|
2 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import os
|
2 |
+
import sys
|
3 |
+
import logging
|
4 |
+
import tempfile
|
5 |
+
import traceback
|
6 |
+
from typing import List, Tuple, Optional, Any
|
7 |
+
import gradio as gr
|
8 |
+
from gradio_client import Client, handle_file
|
9 |
+
from dotenv import load_dotenv
|
10 |
+
|
11 |
+
# .env ํ์ผ ๋ก๋
|
12 |
+
load_dotenv()
|
13 |
+
|
14 |
+
# ๋ก๊น
์ค์ (API ์๋ํฌ์ธํธ ์ ๋ณด๋ ๋ก๊ทธ์ ๋จ๊ธฐ์ง ์์)
|
15 |
+
logging.basicConfig(
|
16 |
+
level=logging.INFO,
|
17 |
+
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
|
18 |
+
handlers=[
|
19 |
+
logging.FileHandler("app.log"),
|
20 |
+
logging.StreamHandler(sys.stdout)
|
21 |
+
]
|
22 |
+
)
|
23 |
+
logger = logging.getLogger("image-enhancer-control-tower")
|
24 |
+
|
25 |
+
class GradioClientController:
|
26 |
+
"""ํ๊น
ํ์ด์ค ๊ทธ๋ผ๋์ค API ํด๋ผ์ด์ธํธ ์ปจํธ๋กค๋ฌ"""
|
27 |
+
|
28 |
+
def __init__(self):
|
29 |
+
self.client = None
|
30 |
+
self._initialize_client()
|
31 |
+
|
32 |
+
def _initialize_client(self):
|
33 |
+
"""ํด๋ผ์ด์ธํธ ์ด๊ธฐํ (์๋ํฌ์ธํธ ์ ๋ณด๋ ๋ก๊ทธ์ ๋จ๊ธฐ์ง ์์)"""
|
34 |
+
try:
|
35 |
+
api_endpoint = os.environ.get("API_ENDPOINT")
|
36 |
+
if not api_endpoint:
|
37 |
+
logger.error("API_ENDPOINT ํ๊ฒฝ ๋ณ์๊ฐ ์ค์ ๋์ง ์์์ต๋๋ค.")
|
38 |
+
raise ValueError("API_ENDPOINT ํ๊ฒฝ ๋ณ์๊ฐ ํ์ํฉ๋๋ค.")
|
39 |
+
|
40 |
+
self.client = Client(api_endpoint)
|
41 |
+
logger.info("API ํด๋ผ์ด์ธํธ๊ฐ ์ฑ๊ณต์ ์ผ๋ก ์ด๊ธฐํ๋์์ต๋๋ค.")
|
42 |
+
|
43 |
+
except Exception as e:
|
44 |
+
logger.error(f"ํด๋ผ์ด์ธํธ ์ด๊ธฐํ ์คํจ: {e}")
|
45 |
+
self.client = None
|
46 |
+
|
47 |
+
def update_dropdowns(self, bg_type: str) -> Tuple:
|
48 |
+
"""๋ฐฐ๊ฒฝ ์ ํ์ ๋ฐ๋ฅธ ๋๋กญ๋ค์ด ์
๋ฐ์ดํธ"""
|
49 |
+
try:
|
50 |
+
if not self.client:
|
51 |
+
logger.error("ํด๋ผ์ด์ธํธ๊ฐ ์ด๊ธฐํ๋์ง ์์์ต๋๋ค.")
|
52 |
+
return tuple([gr.update() for _ in range(7)])
|
53 |
+
|
54 |
+
result = self.client.predict(
|
55 |
+
bg_type=bg_type,
|
56 |
+
api_name="/update_dropdowns"
|
57 |
+
)
|
58 |
+
|
59 |
+
logger.info(f"๋๋กญ๋ค์ด ์
๋ฐ์ดํธ ์๋ฃ: {bg_type}")
|
60 |
+
|
61 |
+
# ๊ฒฐ๊ณผ๋ฅผ Gradio ์
๋ฐ์ดํธ ํ์์ผ๋ก ๋ณํ
|
62 |
+
updates = []
|
63 |
+
for i, choices in enumerate(result):
|
64 |
+
if i == 0: # ์ฌํ ๋ฐฐ๊ฒฝ
|
65 |
+
updates.append(gr.update(visible=(bg_type == "์ฌํ ๋ฐฐ๊ฒฝ"), choices=choices, value=choices[0] if choices else None))
|
66 |
+
elif i == 1: # ์คํ๋์ค ๋ฐฐ๊ฒฝ
|
67 |
+
updates.append(gr.update(visible=(bg_type == "์คํ๋์ค ๋ฐฐ๊ฒฝ"), choices=choices, value=choices[0] if choices else None))
|
68 |
+
elif i == 2: # ์์ฐ ํ๊ฒฝ
|
69 |
+
updates.append(gr.update(visible=(bg_type == "์์ฐ ํ๊ฒฝ"), choices=choices, value=choices[0] if choices else None))
|
70 |
+
elif i == 3: # ์ค๋ด ํ๊ฒฝ
|
71 |
+
updates.append(gr.update(visible=(bg_type == "์ค๋ด ํ๊ฒฝ"), choices=choices, value=choices[0] if choices else None))
|
72 |
+
elif i == 4: # ํน์๋ฐฐ๊ฒฝ
|
73 |
+
updates.append(gr.update(visible=(bg_type == "ํน์๋ฐฐ๊ฒฝ"), choices=choices, value=choices[0] if choices else None))
|
74 |
+
elif i == 5: # ์ฃผ์ผ๋ฆฌ
|
75 |
+
updates.append(gr.update(visible=(bg_type == "์ฃผ์ผ๋ฆฌ"), choices=choices, value=choices[0] if choices else None))
|
76 |
+
elif i == 6: # ํน์ํจ๊ณผ
|
77 |
+
updates.append(gr.update(visible=(bg_type == "ํน์ํจ๊ณผ"), choices=choices, value=choices[0] if choices else None))
|
78 |
+
|
79 |
+
return tuple(updates)
|
80 |
+
|
81 |
+
except Exception as e:
|
82 |
+
logger.error(f"๋๋กญ๋ค์ด ์
๋ฐ์ดํธ ์ค๋ฅ: {e}")
|
83 |
+
return tuple([gr.update() for _ in range(7)])
|
84 |
+
|
85 |
+
def generate_prompt_only(self, password: str, bg_type: str, simple: str, studio: str,
|
86 |
+
nature: str, indoor: str, special: str, jewelry: str,
|
87 |
+
special_effects: str, request_text: str, aspect_ratio: str) -> str:
|
88 |
+
"""ํ๋กฌํํธ๋ง ์์ฑ"""
|
89 |
+
try:
|
90 |
+
if not self.client:
|
91 |
+
logger.error("ํด๋ผ์ด์ธํธ๊ฐ ์ด๊ธฐํ๋์ง ์์์ต๋๋ค.")
|
92 |
+
return "ํด๋ผ์ด์ธํธ ์ฐ๊ฒฐ ์ค๋ฅ"
|
93 |
+
|
94 |
+
result = self.client.predict(
|
95 |
+
password=password,
|
96 |
+
bg_type=bg_type,
|
97 |
+
simple=simple,
|
98 |
+
studio=studio,
|
99 |
+
nature=nature,
|
100 |
+
indoor=indoor,
|
101 |
+
special=special,
|
102 |
+
jewelry=jewelry,
|
103 |
+
special_effects=special_effects,
|
104 |
+
request_text=request_text,
|
105 |
+
aspect_ratio=aspect_ratio,
|
106 |
+
api_name="/generate_prompt_with_password_check"
|
107 |
+
)
|
108 |
+
|
109 |
+
logger.info("ํ๋กฌํํธ ์์ฑ ์๋ฃ")
|
110 |
+
return result
|
111 |
+
|
112 |
+
except Exception as e:
|
113 |
+
logger.error(f"ํ๋กฌํํธ ์์ฑ ์ค๋ฅ: {e}")
|
114 |
+
return f"ํ๋กฌํํธ ์์ฑ ์ค๋ฅ: {str(e)}"
|
115 |
+
|
116 |
+
def process_image(self, password: str, image, bg_type: str, simple: str, studio: str,
|
117 |
+
nature: str, indoor: str, special: str, jewelry: str, special_effects: str,
|
118 |
+
request_text: str, quality_level: str, aspect_ratio: str,
|
119 |
+
output_format: str, enable_enhancement: bool) -> Tuple:
|
120 |
+
"""์ด๋ฏธ์ง ์ฒ๋ฆฌ (ํธ์ง ๋ฐ ํ์ง ๊ฐ์ )"""
|
121 |
+
try:
|
122 |
+
if not self.client:
|
123 |
+
logger.error("ํด๋ผ์ด์ธํธ๊ฐ ์ด๊ธฐํ๋์ง ์์์ต๋๋ค.")
|
124 |
+
return ([], None, [], None, "", "", "ํด๋ผ์ด์ธํธ ์ฐ๊ฒฐ ์ค๋ฅ")
|
125 |
+
|
126 |
+
# ์ด๋ฏธ์ง๋ฅผ ์์ ํ์ผ๋ก ์ ์ฅ
|
127 |
+
temp_path = None
|
128 |
+
if image is not None:
|
129 |
+
temp_path = tempfile.mktemp(suffix='.png')
|
130 |
+
image.save(temp_path)
|
131 |
+
|
132 |
+
# API ํธ์ถ
|
133 |
+
result = self.client.predict(
|
134 |
+
password=password,
|
135 |
+
param_1=handle_file(temp_path) if temp_path else None,
|
136 |
+
param_2=bg_type,
|
137 |
+
param_3=simple,
|
138 |
+
param_4=studio,
|
139 |
+
param_5=nature,
|
140 |
+
param_6=indoor,
|
141 |
+
param_7=special,
|
142 |
+
param_8=jewelry,
|
143 |
+
param_9=special_effects,
|
144 |
+
param_10=request_text,
|
145 |
+
param_11=quality_level,
|
146 |
+
param_12=aspect_ratio,
|
147 |
+
param_13=output_format,
|
148 |
+
param_14=enable_enhancement,
|
149 |
+
api_name="/check_password"
|
150 |
+
)
|
151 |
+
|
152 |
+
# ์์ ํ์ผ ์ ๋ฆฌ
|
153 |
+
if temp_path and os.path.exists(temp_path):
|
154 |
+
try:
|
155 |
+
os.remove(temp_path)
|
156 |
+
except:
|
157 |
+
pass
|
158 |
+
|
159 |
+
logger.info("์ด๋ฏธ์ง ์ฒ๋ฆฌ ์๋ฃ")
|
160 |
+
|
161 |
+
# ๊ฒฐ๊ณผ ๋ฐํ: (original_output, original_download, enhanced_output, enhanced_download, prompt_output, info, error)
|
162 |
+
return result
|
163 |
+
|
164 |
+
except Exception as e:
|
165 |
+
logger.error(f"์ด๋ฏธ์ง ์ฒ๋ฆฌ ์ค๋ฅ: {e}")
|
166 |
+
# ์์ ํ์ผ ์ ๋ฆฌ
|
167 |
+
if 'temp_path' in locals() and temp_path and os.path.exists(temp_path):
|
168 |
+
try:
|
169 |
+
os.remove(temp_path)
|
170 |
+
except:
|
171 |
+
pass
|
172 |
+
return ([], None, [], None, "", "", f"์ด๋ฏธ์ง ์ฒ๋ฆฌ ์ค๋ฅ: {str(e)}")
|
173 |
+
|
174 |
+
# ์ ์ญ ํด๋ผ์ด์ธํธ ์ปจํธ๋กค๋ฌ ์ธ์คํด์ค
|
175 |
+
controller = GradioClientController()
|
176 |
+
|
177 |
+
def create_gradio_interface():
|
178 |
+
"""Gradio ์ธํฐํ์ด์ค ์์ฑ"""
|
179 |
+
try:
|
180 |
+
logger.info("Gradio ์ธํฐํ์ด์ค ์์ฑ ์์")
|
181 |
+
|
182 |
+
# ๋ฐฐ๊ฒฝ ์ ํ ์ ํ์ง (ํ๋์ฝ๋ฉ)
|
183 |
+
background_types = ["์ฌํ ๋ฐฐ๊ฒฝ", "์คํ๋์ค ๋ฐฐ๊ฒฝ", "์์ฐ ํ๊ฒฝ", "์ค๋ด ํ๊ฒฝ", "ํน์๋ฐฐ๊ฒฝ", "์ฃผ์ผ๋ฆฌ", "ํน์ํจ๊ณผ"]
|
184 |
+
|
185 |
+
with gr.Blocks(title="AI ์ด๋ฏธ์ง ํธ์ง ๋ฐ ํ์ง ๊ฐ์ ") as app:
|
186 |
+
gr.Markdown("# AI ์ด๋ฏธ์ง ํธ์ง ๋ฐ ํ์ง ๊ฐ์ ๋๊ตฌ")
|
187 |
+
|
188 |
+
# ๋น๋ฐ๋ฒํธ ์
๋ ฅ ํ๋
|
189 |
+
password_box = gr.Textbox(
|
190 |
+
label="๋น๋ฐ๋ฒํธ",
|
191 |
+
type="password",
|
192 |
+
placeholder="์ฌ์ฉํ๋ ค๋ฉด ๋น๋ฐ๋ฒํธ๋ฅผ ์
๋ ฅํ์ธ์",
|
193 |
+
interactive=True
|
194 |
+
)
|
195 |
+
|
196 |
+
# ์ด๋ฏธ์ง ํธ์ง ๋ฐ ํ์ง ๊ฐ์ ์ธํฐํ์ด์ค
|
197 |
+
with gr.Row():
|
198 |
+
with gr.Column():
|
199 |
+
# ์ํ ์ด๋ฏธ์ง ์
๋ก๋
|
200 |
+
image = gr.Image(label="์ํ ์ด๋ฏธ์ง ์
๋ก๋", type="pil")
|
201 |
+
|
202 |
+
with gr.Row():
|
203 |
+
with gr.Column():
|
204 |
+
background_type = gr.Radio(
|
205 |
+
choices=background_types,
|
206 |
+
label="๋ฐฐ๊ฒฝ ์ ํ",
|
207 |
+
value="์ฌํ ๋ฐฐ๊ฒฝ"
|
208 |
+
)
|
209 |
+
|
210 |
+
# ๋๋กญ๋ค์ด ์ปดํฌ๋ํธ๋ค (์ด๊ธฐ์๋ ๋น ์ํ)
|
211 |
+
simple_dropdown = gr.Dropdown(
|
212 |
+
choices=[],
|
213 |
+
label="์ฌํ ๋ฐฐ๊ฒฝ ์ ํ",
|
214 |
+
visible=True,
|
215 |
+
interactive=True
|
216 |
+
)
|
217 |
+
|
218 |
+
studio_dropdown = gr.Dropdown(
|
219 |
+
choices=[],
|
220 |
+
label="์คํ๋์ค ๋ฐฐ๊ฒฝ ์ ํ",
|
221 |
+
visible=False,
|
222 |
+
interactive=True
|
223 |
+
)
|
224 |
+
|
225 |
+
nature_dropdown = gr.Dropdown(
|
226 |
+
choices=[],
|
227 |
+
label="์์ฐ ํ๊ฒฝ ์ ํ",
|
228 |
+
visible=False,
|
229 |
+
interactive=True
|
230 |
+
)
|
231 |
+
|
232 |
+
indoor_dropdown = gr.Dropdown(
|
233 |
+
choices=[],
|
234 |
+
label="์ค๋ด ํ๊ฒฝ ์ ํ",
|
235 |
+
visible=False,
|
236 |
+
interactive=True
|
237 |
+
)
|
238 |
+
|
239 |
+
special_dropdown = gr.Dropdown(
|
240 |
+
choices=[],
|
241 |
+
label="ํน์๋ฐฐ๊ฒฝ ์ ํ",
|
242 |
+
visible=False,
|
243 |
+
interactive=True
|
244 |
+
)
|
245 |
+
|
246 |
+
jewelry_dropdown = gr.Dropdown(
|
247 |
+
choices=[],
|
248 |
+
label="์ฃผ์ผ๋ฆฌ ๋ฐฐ๊ฒฝ ์ ํ",
|
249 |
+
visible=False,
|
250 |
+
interactive=True
|
251 |
+
)
|
252 |
+
|
253 |
+
special_effects_dropdown = gr.Dropdown(
|
254 |
+
choices=[],
|
255 |
+
label="ํน์ํจ๊ณผ ๋ฐฐ๊ฒฝ ์ ํ",
|
256 |
+
visible=False,
|
257 |
+
interactive=True
|
258 |
+
)
|
259 |
+
|
260 |
+
# ๋๋กญ๋ค์ด ๋ณ๊ฒฝ ์ด๋ฒคํธ
|
261 |
+
background_type.change(
|
262 |
+
fn=controller.update_dropdowns,
|
263 |
+
inputs=[background_type],
|
264 |
+
outputs=[simple_dropdown, studio_dropdown, nature_dropdown,
|
265 |
+
indoor_dropdown, special_dropdown, jewelry_dropdown, special_effects_dropdown]
|
266 |
+
)
|
267 |
+
|
268 |
+
# ์์ฒญ์ฌํญ ์
๋ ฅ
|
269 |
+
request_text = gr.Textbox(
|
270 |
+
label="์์ฒญ์ฌํญ",
|
271 |
+
placeholder="์ํ ์ด๋ฏธ์ง์ ์ ์ฉํ ์คํ์ผ, ๋ถ์๊ธฐ, ํน๋ณ ์์ฒญ์ฌํญ ๋ฑ์ ์
๋ ฅํ์ธ์.",
|
272 |
+
lines=3
|
273 |
+
)
|
274 |
+
|
275 |
+
# ์๋ก์ด ์ต์
๋ค
|
276 |
+
quality_level = gr.Radio(
|
277 |
+
label="ํ์ง ๋ ๋ฒจ",
|
278 |
+
choices=["gpt", "flux"],
|
279 |
+
value="flux",
|
280 |
+
info="GPT: GPT ๋ชจ๋ธ (๊ณ ํ์ง), ์ผ๋ฐ: Flux ๋ชจ๋ธ (๋น ๋ฅธ ์ฒ๋ฆฌ + ๊ธฐ๋ณธ ํ์ง๊ฐ์ )"
|
281 |
+
)
|
282 |
+
|
283 |
+
aspect_ratio = gr.Dropdown(
|
284 |
+
label="์ข
ํก๋น",
|
285 |
+
choices=["1:1", "3:2", "2:3"],
|
286 |
+
value="1:1"
|
287 |
+
)
|
288 |
+
|
289 |
+
output_format = gr.Dropdown(
|
290 |
+
label="์ด๋ฏธ์ง ํ์",
|
291 |
+
choices=["jpg", "png"],
|
292 |
+
value="jpg"
|
293 |
+
)
|
294 |
+
|
295 |
+
# ํ์ง ๊ฐ์ ์ต์
|
296 |
+
enable_enhancement = gr.Checkbox(
|
297 |
+
label="์ถ๊ฐ ํ์ง ๊ฐ์ ",
|
298 |
+
value=False,
|
299 |
+
info="GPT: 1ํ ํ์ง๊ฐ์ , Flux: 2์ฐจ ํ์ง๊ฐ์ (๊ธฐ๋ณธ 1ํ + ์ถ๊ฐ 1ํ)"
|
300 |
+
)
|
301 |
+
|
302 |
+
# ํ๋กฌํํธ ์์ฑ ๋ฒํผ
|
303 |
+
generate_prompt_btn = gr.Button("ํ๋กฌํํธ๋ง ์์ฑ")
|
304 |
+
|
305 |
+
# ํธ์ง ๋ฒํผ
|
306 |
+
edit_btn = gr.Button("์ด๋ฏธ์ง ํธ์ง ๋ฐ ํ์ง ๊ฐ์ ")
|
307 |
+
|
308 |
+
with gr.Column():
|
309 |
+
with gr.Row():
|
310 |
+
with gr.Column():
|
311 |
+
gr.Markdown("## ํธ์ง๋ ์ด๋ฏธ์ง")
|
312 |
+
original_output = gr.Gallery(label="ํธ์ง ๊ฒฐ๊ณผ", preview=True)
|
313 |
+
original_download = gr.File(label="ํธ์ง ์ด๋ฏธ์ง ๋ค์ด๋ก๋", interactive=False)
|
314 |
+
|
315 |
+
with gr.Column():
|
316 |
+
gr.Markdown("## ํ์ง ๊ฐ์ ๋ ์ด๋ฏธ์ง")
|
317 |
+
enhanced_output = gr.Gallery(label="ํ์ง ๊ฐ์ ๊ฒฐ๊ณผ", preview=True)
|
318 |
+
enhanced_download = gr.File(label="๊ฐ์ ์ด๋ฏธ์ง ๋ค์ด๋ก๋", interactive=False)
|
319 |
+
|
320 |
+
# ํ๋กฌํํธ ์ถ๋ ฅ
|
321 |
+
prompt_output = gr.Textbox(label="์์ฑ๋ ํ๋กฌํํธ", lines=10, interactive=False)
|
322 |
+
info = gr.Textbox(label="์ฒ๋ฆฌ ์ ๋ณด", interactive=False)
|
323 |
+
error = gr.Textbox(label="์ค๋ฅ ๋ฉ์์ง", interactive=False, visible=True)
|
324 |
+
|
325 |
+
# ํ๋กฌํํธ ์์ฑ ๋ฒํผ ํด๋ฆญ ์ด๋ฒคํธ
|
326 |
+
generate_prompt_btn.click(
|
327 |
+
fn=controller.generate_prompt_only,
|
328 |
+
inputs=[
|
329 |
+
password_box,
|
330 |
+
background_type,
|
331 |
+
simple_dropdown, studio_dropdown, nature_dropdown, indoor_dropdown, special_dropdown,
|
332 |
+
jewelry_dropdown, special_effects_dropdown,
|
333 |
+
request_text, aspect_ratio
|
334 |
+
],
|
335 |
+
outputs=[prompt_output]
|
336 |
+
)
|
337 |
+
|
338 |
+
# ํธ์ง ๋ฒํผ ํด๋ฆญ ์ด๋ฒคํธ
|
339 |
+
edit_btn.click(
|
340 |
+
fn=controller.process_image,
|
341 |
+
inputs=[
|
342 |
+
password_box,
|
343 |
+
image, background_type,
|
344 |
+
simple_dropdown, studio_dropdown, nature_dropdown, indoor_dropdown, special_dropdown,
|
345 |
+
jewelry_dropdown, special_effects_dropdown,
|
346 |
+
request_text, quality_level, aspect_ratio, output_format, enable_enhancement
|
347 |
+
],
|
348 |
+
outputs=[
|
349 |
+
original_output, original_download,
|
350 |
+
enhanced_output, enhanced_download,
|
351 |
+
prompt_output, info, error
|
352 |
+
]
|
353 |
+
)
|
354 |
+
|
355 |
+
# ์ด๊ธฐ ๋๋กญ๋ค์ด ๋ก๋
|
356 |
+
app.load(
|
357 |
+
fn=controller.update_dropdowns,
|
358 |
+
inputs=[background_type],
|
359 |
+
outputs=[simple_dropdown, studio_dropdown, nature_dropdown,
|
360 |
+
indoor_dropdown, special_dropdown, jewelry_dropdown, special_effects_dropdown]
|
361 |
+
)
|
362 |
+
|
363 |
+
logger.info("Gradio ์ธํฐํ์ด์ค ์์ฑ ์๋ฃ")
|
364 |
+
return app
|
365 |
+
|
366 |
+
except Exception as e:
|
367 |
+
logger.error(f"Gradio ์ธํฐํ์ด์ค ์์ฑ ์ค๋ฅ: {e}")
|
368 |
+
logger.error(traceback.format_exc())
|
369 |
+
raise
|
370 |
+
|
371 |
+
# ์ฑ ์คํ
|
372 |
+
if __name__ == "__main__":
|
373 |
+
try:
|
374 |
+
logger.info("์ ํ๋ฆฌ์ผ์ด์
์์")
|
375 |
+
|
376 |
+
# imgs ๋๋ ํ ๋ฆฌ ํ์ธ/์์ฑ
|
377 |
+
os.makedirs("imgs", exist_ok=True)
|
378 |
+
logger.info("์ด๋ฏธ์ง ๋๋ ํ ๋ฆฌ ์ค๋น ์๋ฃ")
|
379 |
+
|
380 |
+
app = create_gradio_interface()
|
381 |
+
logger.info("Gradio ์ฑ ์์")
|
382 |
+
app.launch(share=True)
|
383 |
+
|
384 |
+
except Exception as e:
|
385 |
+
logger.error(f"์ฑ ์คํ ์ค๋ฅ: {e}")
|
386 |
+
logger.error(traceback.format_exc())
|