Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,4 +1,8 @@
|
|
1 |
import os
|
|
|
|
|
|
|
|
|
2 |
import gradio as gr
|
3 |
import json
|
4 |
import logging
|
@@ -20,12 +24,16 @@ import numpy as np
|
|
20 |
import warnings
|
21 |
|
22 |
|
23 |
-
huggingface_token = os.getenv("HF_TOKEN")
|
24 |
-
|
25 |
|
26 |
-
translator = pipeline("translation", model="Helsinki-NLP/opus-mt-ko-en", device="cpu")
|
27 |
|
28 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
29 |
|
30 |
#Load prompts for randomization
|
31 |
df = pd.read_csv('prompts.csv', header=None)
|
@@ -366,12 +374,18 @@ def generate_image_to_image(prompt_mash, image_input_path, image_strength, steps
|
|
366 |
|
367 |
def run_lora(prompt, image_input, image_strength, cfg_scale, steps, selected_indices, lora_scale_1, lora_scale_2, lora_scale_3, randomize_seed, seed, width, height, loras_state, progress=gr.Progress(track_tqdm=True)):
|
368 |
try:
|
369 |
-
# 한글 감지 및 번역
|
370 |
if any('\u3131' <= char <= '\u318E' or '\uAC00' <= char <= '\uD7A3' for char in prompt):
|
371 |
-
|
372 |
-
|
373 |
-
|
374 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
375 |
|
376 |
if not selected_indices:
|
377 |
raise gr.Error("You must select at least one LoRA before proceeding.")
|
|
|
1 |
import os
|
2 |
+
huggingface_token = os.getenv("HF_TOKEN")
|
3 |
+
if not huggingface_token:
|
4 |
+
print("경고: Hugging Face 토큰이 설정되지 않았습니다.")
|
5 |
+
|
6 |
import gradio as gr
|
7 |
import json
|
8 |
import logging
|
|
|
24 |
import warnings
|
25 |
|
26 |
|
|
|
|
|
27 |
|
|
|
28 |
|
29 |
|
30 |
+
try:
|
31 |
+
translator = pipeline("translation", model="Helsinki-NLP/opus-mt-ko-en", device="cpu", token=huggingface_token)
|
32 |
+
except Exception as e:
|
33 |
+
print(f"번역기 로드 실패: {str(e)}")
|
34 |
+
# 번역 실패시 원본 텍스트를 그대로 반환하는 대체 함수
|
35 |
+
def translator(text, max_length=512):
|
36 |
+
return [{'translation_text': text}]
|
37 |
|
38 |
#Load prompts for randomization
|
39 |
df = pd.read_csv('prompts.csv', header=None)
|
|
|
374 |
|
375 |
def run_lora(prompt, image_input, image_strength, cfg_scale, steps, selected_indices, lora_scale_1, lora_scale_2, lora_scale_3, randomize_seed, seed, width, height, loras_state, progress=gr.Progress(track_tqdm=True)):
|
376 |
try:
|
377 |
+
# 한글 감지 및 번역 부분
|
378 |
if any('\u3131' <= char <= '\u318E' or '\uAC00' <= char <= '\uD7A3' for char in prompt):
|
379 |
+
try:
|
380 |
+
translated = translator(prompt, max_length=512)[0]['translation_text']
|
381 |
+
print(f"원본 프롬프트: {prompt}")
|
382 |
+
print(f"번역된 프롬프트: {translated}")
|
383 |
+
prompt = translated
|
384 |
+
except Exception as e:
|
385 |
+
print(f"번역 실패: {str(e)}")
|
386 |
+
# 번역 실패시 원본 프롬프트 사용
|
387 |
+
|
388 |
+
|
389 |
|
390 |
if not selected_indices:
|
391 |
raise gr.Error("You must select at least one LoRA before proceeding.")
|