Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,3 +1,5 @@
|
|
|
|
|
|
1 |
import os
|
2 |
import gradio as gr
|
3 |
import random
|
@@ -10,21 +12,21 @@ import numpy as np
|
|
10 |
from diffusers import DiffusionPipeline
|
11 |
from transformers import pipeline as hf_pipeline
|
12 |
|
13 |
-
# ---------------------- ZeroGPU 환경에서
|
14 |
-
# Hugging Face Spaces의 ZeroGPU 환경이면 환경 변수 ZERO_GPU가 설정되어 있다고 가정
|
15 |
if os.getenv("ZERO_GPU"):
|
16 |
-
device = "
|
17 |
-
torch.cuda.set_device(0)
|
18 |
else:
|
19 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
20 |
|
21 |
-
dtype = torch.bfloat16 if device == "cuda" else torch.float32
|
22 |
|
23 |
# ---------------------- 이미지 생성 관련 설정 ----------------------
|
24 |
-
|
25 |
-
|
|
|
|
|
|
|
26 |
|
27 |
-
# Diffusion Pipeline 로드 (예: FLUX.1-schnell 모델)
|
28 |
pipe = DiffusionPipeline.from_pretrained(
|
29 |
"black-forest-labs/FLUX.1-schnell",
|
30 |
torch_dtype=dtype
|
@@ -71,7 +73,6 @@ def generate_design_image(prompt, seed=42, randomize_seed=True, width=1024, heig
|
|
71 |
return image
|
72 |
|
73 |
# ---------------------- Gemini API 및 아이디어 생성 관련 기존 코드 ----------------------
|
74 |
-
# 로깅 설정
|
75 |
logging.basicConfig(
|
76 |
level=logging.INFO,
|
77 |
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
|
@@ -82,7 +83,6 @@ logging.basicConfig(
|
|
82 |
)
|
83 |
logger = logging.getLogger("idea_generator")
|
84 |
|
85 |
-
# Gemini API 키는 환경 변수 GEMINI_API_KEY에서 가져옵니다.
|
86 |
GEMINI_API_KEY = os.getenv("GEMINI_API_KEY")
|
87 |
genai.configure(api_key=GEMINI_API_KEY)
|
88 |
|
@@ -107,6 +107,8 @@ def choose_alternative(transformation):
|
|
107 |
else:
|
108 |
return random.choice([left, right])
|
109 |
|
|
|
|
|
110 |
# 창의적인 모델/컨셉/형상 변화 아이디어를 위한 카테고리 (총 15개)
|
111 |
physical_transformation_categories = {
|
112 |
"공간 이동": [
|
@@ -249,6 +251,7 @@ physical_transformation_categories = {
|
|
249 |
]
|
250 |
}
|
251 |
|
|
|
252 |
##############################################################################
|
253 |
# Gemini API 호출 함수 (모델: gemini-2.0-flash-thinking-exp-01-21)
|
254 |
##############################################################################
|
|
|
1 |
+
|
2 |
+
|
3 |
import os
|
4 |
import gradio as gr
|
5 |
import random
|
|
|
12 |
from diffusers import DiffusionPipeline
|
13 |
from transformers import pipeline as hf_pipeline
|
14 |
|
15 |
+
# ---------------------- ZeroGPU 환경에서 CPU 사용 설정 ----------------------
|
|
|
16 |
if os.getenv("ZERO_GPU"):
|
17 |
+
device = "cpu"
|
|
|
18 |
else:
|
19 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
20 |
|
21 |
+
dtype = torch.bfloat16 if (device == "cuda" and torch.cuda.is_available()) else torch.float32
|
22 |
|
23 |
# ---------------------- 이미지 생성 관련 설정 ----------------------
|
24 |
+
translator = hf_pipeline(
|
25 |
+
"translation",
|
26 |
+
model="Helsinki-NLP/opus-mt-ko-en",
|
27 |
+
device=0 if device == "cuda" else -1
|
28 |
+
)
|
29 |
|
|
|
30 |
pipe = DiffusionPipeline.from_pretrained(
|
31 |
"black-forest-labs/FLUX.1-schnell",
|
32 |
torch_dtype=dtype
|
|
|
73 |
return image
|
74 |
|
75 |
# ---------------------- Gemini API 및 아이디어 생성 관련 기존 코드 ----------------------
|
|
|
76 |
logging.basicConfig(
|
77 |
level=logging.INFO,
|
78 |
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
|
|
|
83 |
)
|
84 |
logger = logging.getLogger("idea_generator")
|
85 |
|
|
|
86 |
GEMINI_API_KEY = os.getenv("GEMINI_API_KEY")
|
87 |
genai.configure(api_key=GEMINI_API_KEY)
|
88 |
|
|
|
107 |
else:
|
108 |
return random.choice([left, right])
|
109 |
|
110 |
+
# 창의적인 모델/컨셉/형상 변화 아이디어를 위한 카테고리 (생략된 부분 동일)...
|
111 |
+
|
112 |
# 창의적인 모델/컨셉/형상 변화 아이디어를 위한 카테고리 (총 15개)
|
113 |
physical_transformation_categories = {
|
114 |
"공간 이동": [
|
|
|
251 |
]
|
252 |
}
|
253 |
|
254 |
+
|
255 |
##############################################################################
|
256 |
# Gemini API 호출 함수 (모델: gemini-2.0-flash-thinking-exp-01-21)
|
257 |
##############################################################################
|