openfree commited on
Commit
7cea496
·
verified ·
1 Parent(s): 7a00c3b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -1
app.py CHANGED
@@ -14,6 +14,7 @@ import numpy as np
14
  import torch
15
  from PIL import Image, ImageDraw, ImageFont
16
  from diffusers import FluxPipeline
 
17
 
18
  # 메모리 정리 함수
19
  def clear_memory():
@@ -55,6 +56,21 @@ pipe = FluxPipeline.from_pretrained(
55
  )
56
  pipe.enable_attention_slicing(slice_size="auto")
57
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
58
  # Eric cat LoRA 가중치 로드
59
  try:
60
  lora_path = hf_hub_download(
@@ -91,7 +107,7 @@ def save_generated_image(image, prompt):
91
  image.save(filepath)
92
  return filepath
93
 
94
- @spaces.GPU(duration=60) # gr.GPU 대신 spaces.GPU 사용
95
  def generate_image(
96
  prompt: str,
97
  seed: int,
@@ -103,6 +119,9 @@ def generate_image(
103
  progress: gr.Progress = gr.Progress()
104
  ):
105
  try:
 
 
 
106
  if randomize_seed:
107
  seed = random.randint(0, MAX_SEED)
108
 
 
14
  import torch
15
  from PIL import Image, ImageDraw, ImageFont
16
  from diffusers import FluxPipeline
17
+ from transformers import pipeline
18
 
19
  # 메모리 정리 함수
20
  def clear_memory():
 
56
  )
57
  pipe.enable_attention_slicing(slice_size="auto")
58
 
59
+
60
+ translator = pipeline("translation", model="Helsinki-NLP/opus-mt-ko-en", device=-1) # CPU에서 실행
61
+
62
+ def translate_to_english(text: str) -> str:
63
+ """한글 텍스트를 영어로 번역"""
64
+ try:
65
+ if any(ord('가') <= ord(char) <= ord('힣') for char in text):
66
+ translated = translator(text, max_length=128)[0]['translation_text']
67
+ print(f"Translated '{text}' to '{translated}'")
68
+ return translated
69
+ return text
70
+ except Exception as e:
71
+ print(f"Translation error: {str(e)}")
72
+ return text
73
+
74
  # Eric cat LoRA 가중치 로드
75
  try:
76
  lora_path = hf_hub_download(
 
107
  image.save(filepath)
108
  return filepath
109
 
110
+ @spaces.GPU(duration=60)
111
  def generate_image(
112
  prompt: str,
113
  seed: int,
 
119
  progress: gr.Progress = gr.Progress()
120
  ):
121
  try:
122
+ # 프롬프트 번역 추가
123
+ prompt = translate_to_english(prompt)
124
+
125
  if randomize_seed:
126
  seed = random.randint(0, MAX_SEED)
127