ginipick commited on
Commit
ea314c5
·
verified ·
1 Parent(s): 7351ce8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -3
app.py CHANGED
@@ -1,7 +1,11 @@
 
1
  import shlex
2
  import subprocess
3
  import os
4
 
 
 
 
5
  subprocess.run(shlex.split("pip install pip==24.0"), check=True)
6
  subprocess.run(
7
  shlex.split(
@@ -36,12 +40,16 @@ from gradio_app.all_models import model_zoo
36
  # ===============================
37
  # Text-to-IMAGE 관련 API 함수 정의
38
  # ===============================
 
39
  def text_to_image(height, width, steps, scales, prompt, seed):
40
  """
41
  주어진 파라미터를 이용해 외부 API의 /process_and_save_image 엔드포인트를 호출하여 이미지를 생성한다.
42
  """
 
 
 
43
  from gradio_client import Client
44
- client = Client(os.getenv("CLIENT_API")) # 기본값 설정
45
  result = client.predict(
46
  height,
47
  width,
@@ -61,9 +69,17 @@ def update_random_seed():
61
  외부 API의 /update_random_seed 엔드포인트를 호출하여 새로운 랜덤 시드 값을 가져온다.
62
  """
63
  from gradio_client import Client
64
- client = Client(os.getenv("CLIENT_API")) # 기본값 설정
65
  return client.predict(api_name="/update_random_seed")
66
 
 
 
 
 
 
 
 
 
67
 
68
  _TITLE = '''✨ 3D LLAMA Studio'''
69
  _DESCRIPTION = '''
@@ -74,6 +90,8 @@ This platform offers two powerful features:
74
  2. **Text to Styled Image**: Create artistic images that can be used for 3D generation
75
 
76
  *Note: Both English and Korean prompts are supported (영어와 한글 프롬프트 모두 지원됩니다)*
 
 
77
  '''
78
 
79
  # CSS 스타일 밝은 테마로 수정
@@ -129,10 +147,20 @@ custom_css = """
129
  border: 1px solid #e0e0e0 !important;
130
  background-color: #ffffff !important;
131
  }
 
 
 
 
 
 
 
 
132
  """
133
 
134
  # Gradio 테마 설정 수정
135
  def launch():
 
 
136
  model_zoo.init_models()
137
 
138
  with gr.Blocks(
@@ -147,7 +175,10 @@ def launch():
147
  ) as demo:
148
 
149
  with gr.Row():
150
- gr.Markdown('# ' + _TITLE, elem_classes="main-title")
 
 
 
151
  gr.Markdown(_DESCRIPTION)
152
 
153
  with gr.Tabs() as tabs:
 
1
+ import spaces
2
  import shlex
3
  import subprocess
4
  import os
5
 
6
+ # ZeroGPU 환경 설정
7
+ os.environ['CUDA_VISIBLE_DEVICES'] = '' # 초기화 시점에는 GPU 비활성화
8
+
9
  subprocess.run(shlex.split("pip install pip==24.0"), check=True)
10
  subprocess.run(
11
  shlex.split(
 
40
  # ===============================
41
  # Text-to-IMAGE 관련 API 함수 정의
42
  # ===============================
43
+ @spaces.GPU(duration=60) # GPU 사용 시간 60초로 설정
44
  def text_to_image(height, width, steps, scales, prompt, seed):
45
  """
46
  주어진 파라미터를 이용해 외부 API의 /process_and_save_image 엔드포인트를 호출하여 이미지를 생성한다.
47
  """
48
+ # GPU가 할당된 상태에서 실행
49
+ os.environ['CUDA_VISIBLE_DEVICES'] = '0'
50
+
51
  from gradio_client import Client
52
+ client = Client(os.getenv("CLIENT_API"))
53
  result = client.predict(
54
  height,
55
  width,
 
69
  외부 API의 /update_random_seed 엔드포인트를 호출하여 새로운 랜덤 시드 값을 가져온다.
70
  """
71
  from gradio_client import Client
72
+ client = Client(os.getenv("CLIENT_API"))
73
  return client.predict(api_name="/update_random_seed")
74
 
75
+ # 3D 생성 함수를 위한 래퍼 (GPU 데코레이터 적용)
76
+ @spaces.GPU(duration=120) # 3D 생성은 더 많은 시간 필요
77
+ def generate_3d_wrapper(*args, **kwargs):
78
+ """3D 생성 함수를 GPU 환경에서 실행"""
79
+ os.environ['CUDA_VISIBLE_DEVICES'] = '0'
80
+ # 실제 3D 생성 로직이 여기서 실행됨
81
+ # model_zoo의 함수들이 여기서 호출될 것임
82
+ return model_zoo.generate_3d(*args, **kwargs)
83
 
84
  _TITLE = '''✨ 3D LLAMA Studio'''
85
  _DESCRIPTION = '''
 
90
  2. **Text to Styled Image**: Create artistic images that can be used for 3D generation
91
 
92
  *Note: Both English and Korean prompts are supported (영어와 한글 프롬프트 모두 지원됩니다)*
93
+
94
+ **Running on ZeroGPU** 🚀
95
  '''
96
 
97
  # CSS 스타일 밝은 테마로 수정
 
147
  border: 1px solid #e0e0e0 !important;
148
  background-color: #ffffff !important;
149
  }
150
+ .zerogpu-badge {
151
+ background-color: #4CAF50;
152
+ color: white;
153
+ padding: 5px 10px;
154
+ border-radius: 5px;
155
+ font-size: 14px;
156
+ margin-left: 10px;
157
+ }
158
  """
159
 
160
  # Gradio 테마 설정 수정
161
  def launch():
162
+ # CPU 모드로 모델 초기화
163
+ os.environ['CUDA_VISIBLE_DEVICES'] = ''
164
  model_zoo.init_models()
165
 
166
  with gr.Blocks(
 
175
  ) as demo:
176
 
177
  with gr.Row():
178
+ with gr.Column():
179
+ gr.Markdown('# ' + _TITLE, elem_classes="main-title")
180
+ with gr.Column():
181
+ gr.HTML('<span class="zerogpu-badge">ZeroGPU Enabled</span>')
182
  gr.Markdown(_DESCRIPTION)
183
 
184
  with gr.Tabs() as tabs: