Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,4 +1,3 @@
|
|
| 1 |
-
# HF Spaces
|
| 2 |
import gradio as gr
|
| 3 |
import asyncio
|
| 4 |
import fal_client
|
|
@@ -9,6 +8,9 @@ import time
|
|
| 9 |
import base64
|
| 10 |
import json
|
| 11 |
|
|
|
|
|
|
|
|
|
|
| 12 |
# Local Dev
|
| 13 |
import os
|
| 14 |
from dotenv import load_dotenv
|
|
@@ -16,11 +18,18 @@ from dotenv import load_dotenv
|
|
| 16 |
load_dotenv()
|
| 17 |
FAL_KEY = os.getenv("FAL_KEY")
|
| 18 |
|
|
|
|
|
|
|
|
|
|
| 19 |
with open("examples/examples.json") as f:
|
| 20 |
examples = json.load(f)
|
| 21 |
|
| 22 |
# IC Light, Replace Background
|
| 23 |
async def submit_ic_light_bria(image_data, positive_prompt, negative_prompt, lightsource_start_color, lightsource_end_color):
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
if not lightsource_start_color.startswith("#"):
|
| 25 |
lightsource_start_color = f"#{lightsource_start_color}"
|
| 26 |
if not lightsource_end_color.startswith("#"):
|
|
@@ -68,6 +77,12 @@ async def submit_ic_light_bria(image_data, positive_prompt, negative_prompt, lig
|
|
| 68 |
else:
|
| 69 |
return [f"Error: {str(e)}"], None
|
| 70 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
# SDXL, Depth Anything, Replace Background
|
| 72 |
async def submit_sdxl_rembg(image_data, positive_prompt, negative_prompt):
|
| 73 |
retries = 3
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import asyncio
|
| 3 |
import fal_client
|
|
|
|
| 8 |
import base64
|
| 9 |
import json
|
| 10 |
|
| 11 |
+
# 번역 모델 임포트
|
| 12 |
+
from transformers import pipeline as translation_pipeline
|
| 13 |
+
|
| 14 |
# Local Dev
|
| 15 |
import os
|
| 16 |
from dotenv import load_dotenv
|
|
|
|
| 18 |
load_dotenv()
|
| 19 |
FAL_KEY = os.getenv("FAL_KEY")
|
| 20 |
|
| 21 |
+
# 번역 모델 초기화
|
| 22 |
+
translator = translation_pipeline("translation", model="Helsinki-NLP/opus-mt-ko-en")
|
| 23 |
+
|
| 24 |
with open("examples/examples.json") as f:
|
| 25 |
examples = json.load(f)
|
| 26 |
|
| 27 |
# IC Light, Replace Background
|
| 28 |
async def submit_ic_light_bria(image_data, positive_prompt, negative_prompt, lightsource_start_color, lightsource_end_color):
|
| 29 |
+
# 프롬프트 번역
|
| 30 |
+
positive_prompt = translate_to_english(positive_prompt)
|
| 31 |
+
negative_prompt = translate_to_english(negative_prompt)
|
| 32 |
+
|
| 33 |
if not lightsource_start_color.startswith("#"):
|
| 34 |
lightsource_start_color = f"#{lightsource_start_color}"
|
| 35 |
if not lightsource_end_color.startswith("#"):
|
|
|
|
| 77 |
else:
|
| 78 |
return [f"Error: {str(e)}"], None
|
| 79 |
|
| 80 |
+
def translate_to_english(text):
|
| 81 |
+
# 입력된 텍스트가 한글일 경우 번역 수행
|
| 82 |
+
if any('가' <= c <= '힣' for c in text):
|
| 83 |
+
return translator(text, max_length=512)[0]['translation_text']
|
| 84 |
+
return text
|
| 85 |
+
|
| 86 |
# SDXL, Depth Anything, Replace Background
|
| 87 |
async def submit_sdxl_rembg(image_data, positive_prompt, negative_prompt):
|
| 88 |
retries = 3
|