Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,690 +1,2 @@
|
|
| 1 |
import os
|
| 2 |
-
|
| 3 |
-
import time
|
| 4 |
-
import logging
|
| 5 |
-
import random
|
| 6 |
-
import uuid
|
| 7 |
-
from datetime import datetime
|
| 8 |
-
from langdetect import detect, DetectorFactory
|
| 9 |
-
import google.generativeai as genai
|
| 10 |
-
|
| 11 |
-
DetectorFactory.seed = 0
|
| 12 |
-
|
| 13 |
-
logging.basicConfig(
|
| 14 |
-
level=logging.INFO,
|
| 15 |
-
format='%(asctime)s - %(levelname)s - %(message)s'
|
| 16 |
-
)
|
| 17 |
-
logger = logging.getLogger(__name__)
|
| 18 |
-
|
| 19 |
-
# API 키 설정 (환경 변수에서 자동으로 가져옴)
|
| 20 |
-
GEMINI_API_KEY = os.getenv("GEMINI_API_KEY", "여기에_기본_API_키_입력")
|
| 21 |
-
genai.configure(api_key=GEMINI_API_KEY)
|
| 22 |
-
|
| 23 |
-
# 한국어 자연스럽게 조건 (한-영 번역용)
|
| 24 |
-
KO_EN_CONDITIONS = """
|
| 25 |
-
추가 조건 (한국어 자연스럽게 하기):
|
| 26 |
-
- 번역체가 아닌 자연스럽고 매끄러운 한국어를 최우선적으로 작성
|
| 27 |
-
- 아래 조건을 따라주세요:
|
| 28 |
-
1. 문법적 정확성
|
| 29 |
-
- 피동문보다 능동문 우선
|
| 30 |
-
- 대명사 최소화
|
| 31 |
-
- 명사형보다 동사/형용사 우선
|
| 32 |
-
- 현재진행형보다 단순현재나 완료형 우선
|
| 33 |
-
- 주어-목적어-서술어 순서 유지
|
| 34 |
-
- "~었어요" 표현 지양
|
| 35 |
-
2. 주제 문맥에 맞는 자연스러운 흐름
|
| 36 |
-
3. 주제와 상황에 어울리는 어휘 선택
|
| 37 |
-
4. 문화적 적합성 고려
|
| 38 |
-
5. 정서적 뉘앙스 반영 (공감 이끄는 표현)
|
| 39 |
-
6. 직역/의역 균형 유지
|
| 40 |
-
7. 주제 키워드 반복 언급 금지
|
| 41 |
-
8. AI가 쓴 글처럼 보이지 않도록 주의
|
| 42 |
-
"""
|
| 43 |
-
|
| 44 |
-
# 시스템 메시지 (한-중 번역용)
|
| 45 |
-
KO_ZH_SYSTEM_MESSAGE = """당신은 한국어-중국어 양방향 번역 어시스턴트입니다.
|
| 46 |
-
아래 조건을 충실히 따르세요.
|
| 47 |
-
[목적 및 상황]
|
| 48 |
-
- 사용자 목적: 1688 소싱, 도매, 유통 관련된 상황에서 언어 장벽 없이 원활한 소통을 돕는다.
|
| 49 |
-
- 사용자 입력이 한국어일 경우 자연스럽고 맥락에 맞게 중국어로 번역한다.
|
| 50 |
-
- 사용자 입력이 중국어일 경우 자연스럽고 맥락에 맞게 한국어로 번역한다.
|
| 51 |
-
[한국어 자연스럽게 조건정리]
|
| 52 |
-
1. 문법적 정확성
|
| 53 |
-
- 피동문 대신 능동문
|
| 54 |
-
- 대명사 최소화
|
| 55 |
-
- 명사형보다 동사 및 형용사 우선
|
| 56 |
-
- 단순현재형이나 완료형 우선
|
| 57 |
-
- 문장 구조는 주어-목적어-동사
|
| 58 |
-
- "~었어요" 형태 사용 지양
|
| 59 |
-
2. 주제 맥락에 맞는 자연스러운 표현
|
| 60 |
-
3. 적절한 어휘 선택(소싱, 도매, 유통 상황 고려)
|
| 61 |
-
4. 문화적, 상황적 적합성
|
| 62 |
-
5. 정서적 뉘앙스 조화
|
| 63 |
-
6. 직역과 의역의 균형
|
| 64 |
-
7. 주제 키워드 반복 금지
|
| 65 |
-
8. 생성 AI 티 나지 않도록 주의
|
| 66 |
-
[추가사항]
|
| 67 |
-
- 번역 시 어색한 번역체를 피하고 자연스러운 표현을 사용한다.
|
| 68 |
-
- 출력은 번역된 결과문만 제시한다.
|
| 69 |
-
"""
|
| 70 |
-
|
| 71 |
-
# 1차 카테고리 및 2차 질문 목록 정의
|
| 72 |
-
categories = {
|
| 73 |
-
"기본 인사 및 거래 시작": [
|
| 74 |
-
"안녕하세요, 귀사의 제품이 마음에 듭니다. 자세히 설명 부탁드립니다.",
|
| 75 |
-
"제품이 현재 재고가 있나요?",
|
| 76 |
-
"도매 거래를 하고 싶습니다. 가능한가요?",
|
| 77 |
-
"새로운 고객인데 거래를 시작할 수 있을까요?",
|
| 78 |
-
"혹시 한국 고객들과도 거래를 하고 계신가요?",
|
| 79 |
-
"제품에 대한 자세한 설명서나 브로슈어가 있나요?",
|
| 80 |
-
"제품이 인기 상품인가요? 판매 데이터를 공유할 수 있나요?",
|
| 81 |
-
"판매 지역이나 제한이 있나요?",
|
| 82 |
-
"이 제품의 현재 시장 트렌드는 어떤가요?",
|
| 83 |
-
"판매 기록이 있는 제품인지 확인할 수 있나요?"
|
| 84 |
-
],
|
| 85 |
-
"제품 상세 및 품질 관련 질문": [
|
| 86 |
-
"이 제품의 주요 기능은 무엇인가요?",
|
| 87 |
-
"품질 테스트를 통과한 제품인가요?",
|
| 88 |
-
"제품의 원재료는 무엇인가요?",
|
| 89 |
-
"원산지는 어디인가요?",
|
| 90 |
-
"제품은 사용하기에 안전한가요?",
|
| 91 |
-
"친환경 인증을 받은 제품인가요?",
|
| 92 |
-
"제품 사용 기간(내구성)은 어느 정도인가요?",
|
| 93 |
-
"보증 기간은 어떻게 되나요?",
|
| 94 |
-
"사용 중 문제가 발생하면 어떻게 처리해야 하나요?",
|
| 95 |
-
"사용 설명서가 포함되어 있나요?"
|
| 96 |
-
],
|
| 97 |
-
"가격 및 결제 관련 질문": [
|
| 98 |
-
"도매 가격은 얼마인가요?",
|
| 99 |
-
"대량 구매 시 할인이 가능한가요?",
|
| 100 |
-
"첫 거래 고객을 위한 특별 혜택이 있나요?",
|
| 101 |
-
"결제 조건을 알려주세요.",
|
| 102 |
-
"부분 결제 후 잔금 결제가 가능한가요?",
|
| 103 |
-
"대량 주문 시 초기 보증금을 요구하시나요?",
|
| 104 |
-
"배송료 포함 가격인가요?",
|
| 105 |
-
"추가 비용이 발생할 수 있나요?",
|
| 106 |
-
"할인 쿠폰이나 프로모션 코드는 없나요?",
|
| 107 |
-
"정기 구매 고객을 위한 할인 정책이 있나요?"
|
| 108 |
-
],
|
| 109 |
-
"배송 및 물류 관련 질문": [
|
| 110 |
-
"배송은 어느 택배사를 통해 진행되나요?",
|
| 111 |
-
"예상 배송 기간은 얼마나 되나요?",
|
| 112 |
-
"한국까지 ��송이 가능한가요?",
|
| 113 |
-
"국제 배송료는 어떻게 계산되나요?",
|
| 114 |
-
"대량 주문 시 배송비 할인 혜택이 있나요?",
|
| 115 |
-
"배송 중 파손이 발생하면 어떻게 처리하나요?",
|
| 116 |
-
"주문 후 몇 일 내에 배송이 시작되나요?",
|
| 117 |
-
"배송 추적 번호를 제공하시나요?",
|
| 118 |
-
"주문 상태를 어떻게 확인할 수 있나요?",
|
| 119 |
-
"배송료를 직접 부담해야 하나요?"
|
| 120 |
-
]
|
| 121 |
-
}
|
| 122 |
-
|
| 123 |
-
def guess_lang(text: str) -> str:
|
| 124 |
-
text = text.strip()
|
| 125 |
-
if not text:
|
| 126 |
-
return ""
|
| 127 |
-
try:
|
| 128 |
-
lang = detect(text)
|
| 129 |
-
if lang in ['ko', 'en', 'zh-cn', 'zh-tw']:
|
| 130 |
-
if lang.startswith('zh'):
|
| 131 |
-
return 'zh'
|
| 132 |
-
return lang
|
| 133 |
-
else:
|
| 134 |
-
# langdetect 결과가 ko, en, zh가 아닐 경우 휴리스틱 적용
|
| 135 |
-
if all('a' <= c.lower() <= 'z' for c in text if c.isalpha()):
|
| 136 |
-
return 'en'
|
| 137 |
-
# 한글 음절 범위 판단
|
| 138 |
-
elif any('\uac00' <= c <= '\ud7a3' for c in text):
|
| 139 |
-
return 'ko'
|
| 140 |
-
# 중국어 범위 판단
|
| 141 |
-
elif any('\u4e00' <= c <= '\u9fff' for c in text):
|
| 142 |
-
return 'zh'
|
| 143 |
-
else:
|
| 144 |
-
# 디폴트 영어 처리
|
| 145 |
-
return 'en'
|
| 146 |
-
except:
|
| 147 |
-
# langdetect 실패 시 휴리스틱 적용
|
| 148 |
-
if all('a' <= c.lower() <= 'z' for c in text if c.isalpha()):
|
| 149 |
-
return 'en'
|
| 150 |
-
elif any('\uac00' <= c <= '\ud7a3' for c in text):
|
| 151 |
-
return 'ko'
|
| 152 |
-
elif any('\u4e00' <= c <= '\u9fff' for c in text):
|
| 153 |
-
return 'zh'
|
| 154 |
-
else:
|
| 155 |
-
return 'en'
|
| 156 |
-
|
| 157 |
-
def validate_input(text: str, target_langs: list) -> bool:
|
| 158 |
-
lang = guess_lang(text)
|
| 159 |
-
logger.info(f"감지된(추정) 언어: {lang}")
|
| 160 |
-
return lang in target_langs
|
| 161 |
-
|
| 162 |
-
def translate_ko_en(input_text: str):
|
| 163 |
-
logger.info("한-영 번역 시작")
|
| 164 |
-
|
| 165 |
-
if not validate_input(input_text, ['ko', 'en']):
|
| 166 |
-
return "유효하지 않은 입력입니다. 한국어 또는 영어 텍스트를 입력해주세요."
|
| 167 |
-
|
| 168 |
-
try:
|
| 169 |
-
detected_lang = guess_lang(input_text)
|
| 170 |
-
logger.info(f"감지된(추정) 언어: {detected_lang}")
|
| 171 |
-
|
| 172 |
-
if detected_lang == 'ko':
|
| 173 |
-
direction = "Korean to English"
|
| 174 |
-
input_lang = "Korean"
|
| 175 |
-
output_lang = "English"
|
| 176 |
-
else:
|
| 177 |
-
direction = "English to Korean"
|
| 178 |
-
input_lang = "English"
|
| 179 |
-
output_lang = "Korean"
|
| 180 |
-
|
| 181 |
-
logger.info(f"번역 방향: {direction}")
|
| 182 |
-
|
| 183 |
-
current_time = int(time.time() * 1000)
|
| 184 |
-
random.seed(current_time)
|
| 185 |
-
temperature = random.uniform(0.4, 0.85)
|
| 186 |
-
top_p = random.uniform(0.9, 0.98)
|
| 187 |
-
|
| 188 |
-
request_id = str(uuid.uuid4())[:8]
|
| 189 |
-
timestamp_micro = int(time.time() * 1000000) % 1000
|
| 190 |
-
|
| 191 |
-
current_hour = datetime.now().hour
|
| 192 |
-
time_context = f"Consider the current time is {current_hour}:00."
|
| 193 |
-
|
| 194 |
-
# 한국어 출력 시 자연스러운 한국어 조건 추가
|
| 195 |
-
korean_conditions = ""
|
| 196 |
-
if output_lang == "Korean":
|
| 197 |
-
korean_conditions = KO_EN_CONDITIONS
|
| 198 |
-
|
| 199 |
-
system_prompt = "You are a helpful translator."
|
| 200 |
-
|
| 201 |
-
prompt = f"""
|
| 202 |
-
Translate the following {input_lang} text into {output_lang}:
|
| 203 |
-
|
| 204 |
-
{input_text}
|
| 205 |
-
|
| 206 |
-
Rules:
|
| 207 |
-
1. Output ONLY the {output_lang} translation without additional labels or formatting.
|
| 208 |
-
2. Preserve the original meaning and intent.
|
| 209 |
-
3. No explanations or meta-commentary.
|
| 210 |
-
4. No formatting beyond basic text.
|
| 211 |
-
5. {time_context}
|
| 212 |
-
[Seed: {current_time}]
|
| 213 |
-
|
| 214 |
-
{korean_conditions}
|
| 215 |
-
"""
|
| 216 |
-
|
| 217 |
-
logger.debug(f"프롬프트:\n{prompt}")
|
| 218 |
-
|
| 219 |
-
# Gemini 모델 설정
|
| 220 |
-
generation_config = {
|
| 221 |
-
"max_output_tokens": 200,
|
| 222 |
-
"temperature": temperature,
|
| 223 |
-
"top_p": top_p,
|
| 224 |
-
}
|
| 225 |
-
|
| 226 |
-
# Gemini 모델 불러오기
|
| 227 |
-
model = genai.GenerativeModel(
|
| 228 |
-
model_name="gemini-2.0-flash",
|
| 229 |
-
generation_config=generation_config,
|
| 230 |
-
)
|
| 231 |
-
|
| 232 |
-
# 번역 실행
|
| 233 |
-
full_prompt = f"{system_prompt}\n\n{prompt}"
|
| 234 |
-
response = model.generate_content(full_prompt)
|
| 235 |
-
|
| 236 |
-
translated = response.text.strip()
|
| 237 |
-
logger.info("Gemini 번역 완료")
|
| 238 |
-
logger.debug(f"번역 결과:\n{translated}")
|
| 239 |
-
return translated
|
| 240 |
-
|
| 241 |
-
except Exception as e:
|
| 242 |
-
logger.error(f"번역 중 예상치 못한 오류 발생: {str(e)}")
|
| 243 |
-
return f"번역 중 예상치 못한 오류가 발생했습니다: {str(e)}"
|
| 244 |
-
|
| 245 |
-
def translate_ko_zh(input_text: str):
|
| 246 |
-
logger.info("한-중 번역 시작")
|
| 247 |
-
|
| 248 |
-
if not validate_input(input_text, ['ko', 'zh']):
|
| 249 |
-
return "유효하지 않은 입력입니다. 한국어 또는 중국어 텍스트를 입력해주세요."
|
| 250 |
-
|
| 251 |
-
try:
|
| 252 |
-
detected_lang = guess_lang(input_text)
|
| 253 |
-
logger.info(f"감지된(추정) 언어: {detected_lang}")
|
| 254 |
-
|
| 255 |
-
if detected_lang == 'ko':
|
| 256 |
-
direction = "Korean to Chinese"
|
| 257 |
-
input_lang = "Korean"
|
| 258 |
-
output_lang = "Chinese"
|
| 259 |
-
else:
|
| 260 |
-
direction = "Chinese to Korean"
|
| 261 |
-
input_lang = "Chinese"
|
| 262 |
-
output_lang = "Korean"
|
| 263 |
-
|
| 264 |
-
logger.info(f"번역 방향: {direction}")
|
| 265 |
-
|
| 266 |
-
current_time = int(time.time() * 1000)
|
| 267 |
-
random.seed(current_time)
|
| 268 |
-
temperature = random.uniform(0.5, 0.8)
|
| 269 |
-
top_p = random.uniform(0.9, 0.98)
|
| 270 |
-
|
| 271 |
-
# Gemini 모델 설정
|
| 272 |
-
generation_config = {
|
| 273 |
-
"max_output_tokens": 1024,
|
| 274 |
-
"temperature": temperature,
|
| 275 |
-
"top_p": top_p,
|
| 276 |
-
}
|
| 277 |
-
|
| 278 |
-
# Gemini 모델 불러오기
|
| 279 |
-
model = genai.GenerativeModel(
|
| 280 |
-
model_name="gemini-2.0-flash",
|
| 281 |
-
generation_config=generation_config,
|
| 282 |
-
)
|
| 283 |
-
|
| 284 |
-
# 프롬프트 준비
|
| 285 |
-
prompt = f"{KO_ZH_SYSTEM_MESSAGE}\n\n{input_text}"
|
| 286 |
-
|
| 287 |
-
# 번역 실행
|
| 288 |
-
response = model.generate_content(prompt)
|
| 289 |
-
translated = response.text.strip()
|
| 290 |
-
|
| 291 |
-
logger.info("Gemini 번역 완료")
|
| 292 |
-
logger.debug(f"번역 결과:\n{translated}")
|
| 293 |
-
return translated
|
| 294 |
-
|
| 295 |
-
except Exception as e:
|
| 296 |
-
logger.error(f"번역 중 예상치 못한 오류 발생: {str(e)}")
|
| 297 |
-
return f"번역 중 예상치 못한 오류가 발생했습니다: {str(e)}"
|
| 298 |
-
|
| 299 |
-
def update_subcategories(category):
|
| 300 |
-
if category in categories:
|
| 301 |
-
return gr.update(choices=categories[category], value=None)
|
| 302 |
-
else:
|
| 303 |
-
return gr.update(choices=[], value=None)
|
| 304 |
-
|
| 305 |
-
def set_input_text(selected_text):
|
| 306 |
-
return selected_text
|
| 307 |
-
|
| 308 |
-
# 커스텀 CSS 스타일
|
| 309 |
-
custom_css = """
|
| 310 |
-
:root {
|
| 311 |
-
--primary-color: #FB7F0D;
|
| 312 |
-
--secondary-color: #ff9a8b;
|
| 313 |
-
--accent-color: #FF6B6B;
|
| 314 |
-
--background-color: #FFF3E9;
|
| 315 |
-
--card-bg: #ffffff;
|
| 316 |
-
--text-color: #334155;
|
| 317 |
-
--border-radius: 18px;
|
| 318 |
-
--shadow: 0 8px 30px rgba(251, 127, 13, 0.08);
|
| 319 |
-
}
|
| 320 |
-
|
| 321 |
-
body {
|
| 322 |
-
font-family: 'Pretendard', 'Noto Sans KR', -apple-system, BlinkMacSystemFont, sans-serif;
|
| 323 |
-
background-color: var(--background-color);
|
| 324 |
-
color: var(--text-color);
|
| 325 |
-
line-height: 1.6;
|
| 326 |
-
margin: 0;
|
| 327 |
-
padding: 0;
|
| 328 |
-
}
|
| 329 |
-
|
| 330 |
-
.gradio-container {
|
| 331 |
-
width: 100%;
|
| 332 |
-
margin: 0 auto;
|
| 333 |
-
padding: 20px;
|
| 334 |
-
background-color: var(--background-color);
|
| 335 |
-
}
|
| 336 |
-
|
| 337 |
-
.custom-header {
|
| 338 |
-
background: #FF7F00;
|
| 339 |
-
padding: 2rem;
|
| 340 |
-
border-radius: 15px;
|
| 341 |
-
margin-bottom: 20px;
|
| 342 |
-
box-shadow: var(--shadow);
|
| 343 |
-
text-align: center;
|
| 344 |
-
}
|
| 345 |
-
|
| 346 |
-
.custom-header h1 {
|
| 347 |
-
margin: 0;
|
| 348 |
-
font-size: 2.5rem;
|
| 349 |
-
font-weight: 700;
|
| 350 |
-
color: black;
|
| 351 |
-
}
|
| 352 |
-
|
| 353 |
-
.custom-header p {
|
| 354 |
-
margin: 10px 0 0;
|
| 355 |
-
font-size: 1.2rem;
|
| 356 |
-
color: black;
|
| 357 |
-
}
|
| 358 |
-
|
| 359 |
-
.custom-frame {
|
| 360 |
-
background-color: var(--card-bg);
|
| 361 |
-
border: 1px solid rgba(0, 0, 0, 0.04);
|
| 362 |
-
border-radius: var(--border-radius);
|
| 363 |
-
padding: 20px;
|
| 364 |
-
margin: 10px 0;
|
| 365 |
-
box-shadow: var(--shadow);
|
| 366 |
-
}
|
| 367 |
-
|
| 368 |
-
.custom-section-group {
|
| 369 |
-
margin-top: 20px;
|
| 370 |
-
padding: 0;
|
| 371 |
-
border: none;
|
| 372 |
-
border-radius: 0;
|
| 373 |
-
background-color: var(--background-color);
|
| 374 |
-
box-shadow: none !important;
|
| 375 |
-
}
|
| 376 |
-
|
| 377 |
-
.custom-button {
|
| 378 |
-
border-radius: 30px !important;
|
| 379 |
-
background: linear-gradient(135deg, var(--primary-color), var(--secondary-color)) !important;
|
| 380 |
-
color: white !important;
|
| 381 |
-
font-size: 18px !important;
|
| 382 |
-
padding: 10px 20px !important;
|
| 383 |
-
border: none;
|
| 384 |
-
box-shadow: 0 4px 8px rgba(251, 127, 13, 0.25);
|
| 385 |
-
transition: transform 0.3s ease;
|
| 386 |
-
}
|
| 387 |
-
|
| 388 |
-
.custom-button:hover {
|
| 389 |
-
transform: translateY(-2px);
|
| 390 |
-
box-shadow: 0 6px 12px rgba(251, 127, 13, 0.3);
|
| 391 |
-
}
|
| 392 |
-
|
| 393 |
-
.custom-title {
|
| 394 |
-
font-size: 28px;
|
| 395 |
-
font-weight: bold;
|
| 396 |
-
margin-bottom: 10px;
|
| 397 |
-
color: var(--text-color);
|
| 398 |
-
border-bottom: 2px solid var(--primary-color);
|
| 399 |
-
padding-bottom: 5px;
|
| 400 |
-
}
|
| 401 |
-
|
| 402 |
-
.image-container {
|
| 403 |
-
border-radius: var(--border-radius);
|
| 404 |
-
overflow: hidden;
|
| 405 |
-
border: 1px solid rgba(0, 0, 0, 0.08);
|
| 406 |
-
transition: all 0.3s ease;
|
| 407 |
-
background-color: white;
|
| 408 |
-
}
|
| 409 |
-
|
| 410 |
-
.image-container:hover {
|
| 411 |
-
box-shadow: 0 10px 20px rgba(0, 0, 0, 0.1);
|
| 412 |
-
}
|
| 413 |
-
|
| 414 |
-
.gr-input, .gr-text-input, .gr-sample-inputs {
|
| 415 |
-
border-radius: var(--border-radius) !important;
|
| 416 |
-
border: 1px solid #dddddd !important;
|
| 417 |
-
padding: 12px !important;
|
| 418 |
-
box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.05) !important;
|
| 419 |
-
transition: all 0.3s ease !important;
|
| 420 |
-
}
|
| 421 |
-
|
| 422 |
-
.gr-input:focus, .gr-text-input:focus {
|
| 423 |
-
border-color: var(--primary-color) !important;
|
| 424 |
-
outline: none !important;
|
| 425 |
-
box-shadow: 0 0 0 2px rgba(251, 127, 13, 0.2) !important;
|
| 426 |
-
}
|
| 427 |
-
|
| 428 |
-
::-webkit-scrollbar {
|
| 429 |
-
width: 8px;
|
| 430 |
-
height: 8px;
|
| 431 |
-
}
|
| 432 |
-
|
| 433 |
-
::-webkit-scrollbar-track {
|
| 434 |
-
background: rgba(0, 0, 0, 0.05);
|
| 435 |
-
border-radius: 10px;
|
| 436 |
-
}
|
| 437 |
-
|
| 438 |
-
::-webkit-scrollbar-thumb {
|
| 439 |
-
background: var(--primary-color);
|
| 440 |
-
border-radius: 10px;
|
| 441 |
-
}
|
| 442 |
-
|
| 443 |
-
@keyframes fadeIn {
|
| 444 |
-
from { opacity: 0; transform: translateY(10px); }
|
| 445 |
-
to { opacity: 1; transform: translateY(0); }
|
| 446 |
-
}
|
| 447 |
-
|
| 448 |
-
.fade-in {
|
| 449 |
-
animation: fadeIn 0.5s ease-out;
|
| 450 |
-
}
|
| 451 |
-
|
| 452 |
-
@media (max-width: 768px) {
|
| 453 |
-
.button-grid {
|
| 454 |
-
grid-template-columns: repeat(2, 1fr);
|
| 455 |
-
}
|
| 456 |
-
}
|
| 457 |
-
|
| 458 |
-
.section-title {
|
| 459 |
-
display: flex;
|
| 460 |
-
align-items: center;
|
| 461 |
-
font-size: 20px;
|
| 462 |
-
font-weight: 700;
|
| 463 |
-
color: #333333;
|
| 464 |
-
margin-bottom: 10px;
|
| 465 |
-
padding-bottom: 5px;
|
| 466 |
-
border-bottom: 2px solid #FB7F0D;
|
| 467 |
-
font-family: 'Pretendard', 'Noto Sans KR', -apple-system, BlinkMacSystemFont, sans-serif;
|
| 468 |
-
}
|
| 469 |
-
|
| 470 |
-
.section-title img {
|
| 471 |
-
margin-right: 10px;
|
| 472 |
-
width: 24px;
|
| 473 |
-
height: 24px;
|
| 474 |
-
}
|
| 475 |
-
|
| 476 |
-
.guide-container {
|
| 477 |
-
background-color: var(--card-bg);
|
| 478 |
-
border-radius: var(--border-radius);
|
| 479 |
-
box-shadow: var(--shadow);
|
| 480 |
-
padding: 1.5rem;
|
| 481 |
-
margin-bottom: 1.5rem;
|
| 482 |
-
border: 1px solid rgba(0, 0, 0, 0.04);
|
| 483 |
-
}
|
| 484 |
-
|
| 485 |
-
.guide-title {
|
| 486 |
-
font-size: 1.5rem;
|
| 487 |
-
font-weight: 700;
|
| 488 |
-
color: var(--primary-color);
|
| 489 |
-
margin-bottom: 1.5rem;
|
| 490 |
-
padding-bottom: 0.5rem;
|
| 491 |
-
border-bottom: 2px solid var(--primary-color);
|
| 492 |
-
display: flex;
|
| 493 |
-
align-items: center;
|
| 494 |
-
}
|
| 495 |
-
|
| 496 |
-
.guide-title i {
|
| 497 |
-
margin-right: 0.8rem;
|
| 498 |
-
font-size: 1.5rem;
|
| 499 |
-
}
|
| 500 |
-
|
| 501 |
-
.guide-item {
|
| 502 |
-
display: flex;
|
| 503 |
-
margin-bottom: 1rem;
|
| 504 |
-
align-items: flex-start;
|
| 505 |
-
}
|
| 506 |
-
|
| 507 |
-
.guide-number {
|
| 508 |
-
background-color: var(--primary-color);
|
| 509 |
-
color: white;
|
| 510 |
-
width: 25px;
|
| 511 |
-
height: 25px;
|
| 512 |
-
border-radius: 50%;
|
| 513 |
-
display: flex;
|
| 514 |
-
align-items: center;
|
| 515 |
-
justify-content: center;
|
| 516 |
-
font-weight: bold;
|
| 517 |
-
margin-right: 10px;
|
| 518 |
-
flex-shrink: 0;
|
| 519 |
-
}
|
| 520 |
-
|
| 521 |
-
.guide-text {
|
| 522 |
-
flex: 1;
|
| 523 |
-
line-height: 1.6;
|
| 524 |
-
}
|
| 525 |
-
|
| 526 |
-
.guide-text a {
|
| 527 |
-
color: var(--primary-color);
|
| 528 |
-
text-decoration: underline;
|
| 529 |
-
font-weight: 600;
|
| 530 |
-
}
|
| 531 |
-
|
| 532 |
-
.guide-text a:hover {
|
| 533 |
-
color: var(--accent-color);
|
| 534 |
-
}
|
| 535 |
-
|
| 536 |
-
.guide-highlight {
|
| 537 |
-
background-color: rgba(251, 127, 13, 0.1);
|
| 538 |
-
padding: 2px 5px;
|
| 539 |
-
border-radius: 4px;
|
| 540 |
-
font-weight: 500;
|
| 541 |
-
}
|
| 542 |
-
"""
|
| 543 |
-
|
| 544 |
-
# FontAwesome 아이콘 포함
|
| 545 |
-
fontawesome_link = """
|
| 546 |
-
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" crossorigin="anonymous" referrerpolicy="no-referrer" />
|
| 547 |
-
"""
|
| 548 |
-
|
| 549 |
-
# 앱 헤더 HTML
|
| 550 |
-
header_html = """
|
| 551 |
-
<div class="custom-header">
|
| 552 |
-
<h1>셀러 자동 번역기</h1>
|
| 553 |
-
<p style="font-size:18px; margin-top:10px;">
|
| 554 |
-
한-중, 한-영 자동 번역으로 글로벌 비즈니스 소통을 도와드립니다.
|
| 555 |
-
</p>
|
| 556 |
-
</div>
|
| 557 |
-
"""
|
| 558 |
-
|
| 559 |
-
# 사용 가이드 HTML
|
| 560 |
-
guide_html = """
|
| 561 |
-
<div class="guide-container">
|
| 562 |
-
<div class="guide-title"><i class="fas fa-book"></i> 사용 가이드</div>
|
| 563 |
-
<div class="guide-item">
|
| 564 |
-
<div class="guide-number">1</div>
|
| 565 |
-
<div class="guide-text">
|
| 566 |
-
입력한 언어를 자동으로 감자하여 한국어 ↔ 중국어, 한국어 ↔ 중국어로 번역됩니다.
|
| 567 |
-
</div>
|
| 568 |
-
</div>
|
| 569 |
-
<div class="guide-item">
|
| 570 |
-
<div class="guide-number">2</div>
|
| 571 |
-
<div class="guide-text">
|
| 572 |
-
한-중 번역에서는 자주 사용하는 표현을 카테고리별로 선택할 수 있습니다.
|
| 573 |
-
</div>
|
| 574 |
-
</div>
|
| 575 |
-
</div>
|
| 576 |
-
"""
|
| 577 |
-
|
| 578 |
-
def create_interface():
|
| 579 |
-
with gr.Blocks(css=custom_css, theme=gr.themes.Soft(
|
| 580 |
-
primary_hue=gr.themes.Color(
|
| 581 |
-
c50="#FFF7ED",
|
| 582 |
-
c100="#FFEDD5",
|
| 583 |
-
c200="#FED7AA",
|
| 584 |
-
c300="#FDBA74",
|
| 585 |
-
c400="#FB923C",
|
| 586 |
-
c500="#F97316",
|
| 587 |
-
c600="#EA580C",
|
| 588 |
-
c700="#C2410C",
|
| 589 |
-
c800="#9A3412",
|
| 590 |
-
c900="#7C2D12",
|
| 591 |
-
c950="#431407",
|
| 592 |
-
),
|
| 593 |
-
secondary_hue="zinc",
|
| 594 |
-
neutral_hue="zinc",
|
| 595 |
-
font=("Pretendard", "sans-serif")
|
| 596 |
-
)) as demo:
|
| 597 |
-
|
| 598 |
-
gr.HTML(fontawesome_link)
|
| 599 |
-
gr.HTML(header_html)
|
| 600 |
-
gr.HTML(guide_html)
|
| 601 |
-
|
| 602 |
-
with gr.Tabs() as tabs:
|
| 603 |
-
with gr.TabItem("한국어-중국어 번역"):
|
| 604 |
-
with gr.Column(elem_classes="custom-frame"):
|
| 605 |
-
gr.HTML('<div class="section-title"><img src="https://cdn-icons-png.flaticon.com/512/3097/3097412.png"> 카테고리 선택</div>')
|
| 606 |
-
with gr.Row():
|
| 607 |
-
category_dropdown = gr.Dropdown(
|
| 608 |
-
label="1차 카테고리 선택",
|
| 609 |
-
choices=list(categories.keys()),
|
| 610 |
-
value=None
|
| 611 |
-
)
|
| 612 |
-
subcategory_dropdown = gr.Dropdown(
|
| 613 |
-
label="2차 질문 선택",
|
| 614 |
-
choices=[],
|
| 615 |
-
value=None
|
| 616 |
-
)
|
| 617 |
-
|
| 618 |
-
with gr.Column(elem_classes="custom-frame"):
|
| 619 |
-
gr.HTML('<div class="section-title"><img src="https://cdn-icons-png.flaticon.com/512/4297/4297825.png"> 번역</div>')
|
| 620 |
-
with gr.Row():
|
| 621 |
-
with gr.Column(scale=1):
|
| 622 |
-
kz_input_box = gr.Textbox(
|
| 623 |
-
label="입력 (한국어 또는 중국어)",
|
| 624 |
-
lines=8,
|
| 625 |
-
placeholder="번역할 텍스트를 입력하세요..."
|
| 626 |
-
)
|
| 627 |
-
with gr.Column(scale=1):
|
| 628 |
-
kz_output_box = gr.Textbox(
|
| 629 |
-
label="번역 결과",
|
| 630 |
-
lines=8
|
| 631 |
-
)
|
| 632 |
-
|
| 633 |
-
with gr.Column(elem_classes="custom-frame"):
|
| 634 |
-
gr.HTML('<div class="section-title"><img src="https://cdn-icons-png.flaticon.com/512/1022/1022293.png"> 번역 실행</div>')
|
| 635 |
-
kz_translate_button = gr.Button("번역하기", elem_classes="custom-button")
|
| 636 |
-
|
| 637 |
-
# 1차 선택 시 2차 항목 업데이트
|
| 638 |
-
category_dropdown.change(
|
| 639 |
-
fn=update_subcategories,
|
| 640 |
-
inputs=category_dropdown,
|
| 641 |
-
outputs=subcategory_dropdown
|
| 642 |
-
)
|
| 643 |
-
|
| 644 |
-
# 2차 선택 시 입력란에 해당 값 자동 입력
|
| 645 |
-
subcategory_dropdown.change(
|
| 646 |
-
fn=set_input_text,
|
| 647 |
-
inputs=subcategory_dropdown,
|
| 648 |
-
outputs=kz_input_box
|
| 649 |
-
)
|
| 650 |
-
|
| 651 |
-
# 번역 함수
|
| 652 |
-
kz_translate_button.click(
|
| 653 |
-
fn=translate_ko_zh,
|
| 654 |
-
inputs=kz_input_box,
|
| 655 |
-
outputs=kz_output_box
|
| 656 |
-
)
|
| 657 |
-
|
| 658 |
-
with gr.TabItem("한국어-영어 번역"):
|
| 659 |
-
with gr.Column(elem_classes="custom-frame"):
|
| 660 |
-
gr.HTML('<div class="section-title"><img src="https://cdn-icons-png.flaticon.com/512/4297/4297825.png"> 번역</div>')
|
| 661 |
-
with gr.Row():
|
| 662 |
-
with gr.Column(scale=1):
|
| 663 |
-
ke_input_box = gr.Textbox(
|
| 664 |
-
label="입력 텍스트 (한국어 또는 영어)",
|
| 665 |
-
placeholder="번역할 텍스트를 입력하세요...",
|
| 666 |
-
lines=8
|
| 667 |
-
)
|
| 668 |
-
with gr.Column(scale=1):
|
| 669 |
-
ke_output_box = gr.Textbox(
|
| 670 |
-
label="번역 결과",
|
| 671 |
-
lines=8,
|
| 672 |
-
interactive=False
|
| 673 |
-
)
|
| 674 |
-
|
| 675 |
-
with gr.Column(elem_classes="custom-frame"):
|
| 676 |
-
gr.HTML('<div class="section-title"><img src="https://cdn-icons-png.flaticon.com/512/1022/1022293.png"> 번역 실행</div>')
|
| 677 |
-
ke_translate_button = gr.Button("번역하기", elem_classes="custom-button")
|
| 678 |
-
|
| 679 |
-
# 번역 함수
|
| 680 |
-
ke_translate_button.click(
|
| 681 |
-
fn=translate_ko_en,
|
| 682 |
-
inputs=ke_input_box,
|
| 683 |
-
outputs=ke_output_box
|
| 684 |
-
)
|
| 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