Spaces:
Running
on
Zero
Running
on
Zero
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.")
|