Spaces:
Running
on
Zero
Running
on
Zero
seawolf2357
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -51,22 +51,19 @@ def load_gallery_images():
|
|
51 |
|
52 |
return [(os.path.join("gallery", row[2]), f"{row[0]}: {row[1]}") for row in rows]
|
53 |
|
54 |
-
#
|
55 |
-
@spaces.
|
56 |
-
def
|
57 |
-
|
58 |
-
|
59 |
-
# CPU에서 번역 처리
|
60 |
-
@spaces.CPU
|
61 |
-
def translate_text(translator, text):
|
62 |
if any('\u3131' <= char <= '\u3163' or '\uac00' <= char <= '\ud7a3' for char in text):
|
63 |
translated = translator(text)[0]['translation_text']
|
64 |
return text, translated
|
65 |
return text, text
|
66 |
|
67 |
# 프롬프트 처리 함수
|
68 |
-
def process_prompt(
|
69 |
-
return
|
70 |
|
71 |
KEY_JSON = os.getenv("KEY_JSON")
|
72 |
with open(KEY_JSON, 'r') as f:
|
@@ -144,11 +141,11 @@ def generate_image(prompt_mash, steps, seed, cfg_scale, width, height, lora_scal
|
|
144 |
yield img
|
145 |
|
146 |
@spaces.GPU(duration=70)
|
147 |
-
def run_lora(prompt, cfg_scale, steps, selected_index, randomize_seed, seed, width, height, lora_scale,
|
148 |
if selected_index is None:
|
149 |
raise gr.Error("진행하기 전에 LoRA를 선택해야 합니다.")
|
150 |
|
151 |
-
original_prompt, english_prompt = process_prompt(
|
152 |
|
153 |
selected_lora = loras[selected_index]
|
154 |
lora_path = selected_lora["repo"]
|
@@ -285,12 +282,7 @@ if not os.path.exists('gallery'):
|
|
285 |
# 데이터베이스 초기화
|
286 |
init_db()
|
287 |
|
288 |
-
# 번역기 초기화
|
289 |
-
translator = init_translator()
|
290 |
-
|
291 |
with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css) as app:
|
292 |
-
# 번역기를 상태로 추가
|
293 |
-
translator_state = gr.State(translator)
|
294 |
selected_index = gr.State(None)
|
295 |
|
296 |
with gr.Tabs():
|
@@ -368,7 +360,7 @@ with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css) as app:
|
|
368 |
triggers=[generate_button.click, prompt.submit],
|
369 |
fn=run_lora,
|
370 |
inputs=[prompt, cfg_scale, steps, selected_index, randomize_seed,
|
371 |
-
seed, width, height, lora_scale
|
372 |
outputs=[result, seed, progress_bar, original_prompt_display, english_prompt_display]
|
373 |
)
|
374 |
|
|
|
51 |
|
52 |
return [(os.path.join("gallery", row[2]), f"{row[0]}: {row[1]}") for row in rows]
|
53 |
|
54 |
+
# 번역기 초기화를 GPU 함수 내부로 이동
|
55 |
+
@spaces.GPU(duration=70)
|
56 |
+
def translate_text_gpu(text):
|
57 |
+
# 번역기를 함수 내부에서 초기화
|
58 |
+
translator = pipeline("translation", model="Helsinki-NLP/opus-mt-ko-en")
|
|
|
|
|
|
|
59 |
if any('\u3131' <= char <= '\u3163' or '\uac00' <= char <= '\ud7a3' for char in text):
|
60 |
translated = translator(text)[0]['translation_text']
|
61 |
return text, translated
|
62 |
return text, text
|
63 |
|
64 |
# 프롬프트 처리 함수
|
65 |
+
def process_prompt(prompt):
|
66 |
+
return translate_text_gpu(prompt)
|
67 |
|
68 |
KEY_JSON = os.getenv("KEY_JSON")
|
69 |
with open(KEY_JSON, 'r') as f:
|
|
|
141 |
yield img
|
142 |
|
143 |
@spaces.GPU(duration=70)
|
144 |
+
def run_lora(prompt, cfg_scale, steps, selected_index, randomize_seed, seed, width, height, lora_scale, progress=gr.Progress(track_tqdm=True)):
|
145 |
if selected_index is None:
|
146 |
raise gr.Error("진행하기 전에 LoRA를 선택해야 합니다.")
|
147 |
|
148 |
+
original_prompt, english_prompt = process_prompt(prompt)
|
149 |
|
150 |
selected_lora = loras[selected_index]
|
151 |
lora_path = selected_lora["repo"]
|
|
|
282 |
# 데이터베이스 초기화
|
283 |
init_db()
|
284 |
|
|
|
|
|
|
|
285 |
with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css) as app:
|
|
|
|
|
286 |
selected_index = gr.State(None)
|
287 |
|
288 |
with gr.Tabs():
|
|
|
360 |
triggers=[generate_button.click, prompt.submit],
|
361 |
fn=run_lora,
|
362 |
inputs=[prompt, cfg_scale, steps, selected_index, randomize_seed,
|
363 |
+
seed, width, height, lora_scale],
|
364 |
outputs=[result, seed, progress_bar, original_prompt_display, english_prompt_display]
|
365 |
)
|
366 |
|