ginipick commited on
Commit
248ebfb
·
verified ·
1 Parent(s): e24d56e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +75 -13
app.py CHANGED
@@ -1,7 +1,6 @@
1
  import shlex
2
  import subprocess
3
 
4
-
5
  subprocess.run(shlex.split("pip install pip==24.0"), check=True)
6
  subprocess.run(
7
  shlex.split(
@@ -14,7 +13,7 @@ subprocess.run(
14
  ), check=True
15
  )
16
 
17
-
18
  if __name__ == "__main__":
19
  from huggingface_hub import snapshot_download
20
 
@@ -33,24 +32,87 @@ import gradio as gr
33
  from gradio_app.gradio_3dgen import create_ui as create_3d_ui
34
  from gradio_app.all_models import model_zoo
35
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
36
 
37
- _TITLE = '''Text to 3D'''
 
 
 
 
 
 
 
 
 
 
 
 
38
  _DESCRIPTION = '''
39
- Text to 3D'''
 
 
40
 
41
  def launch():
 
42
  model_zoo.init_models()
43
-
44
- with gr.Blocks(
45
- title=_TITLE,
46
- # theme=gr.themes.Monochrome(),
47
- ) as demo:
48
  with gr.Row():
49
- with gr.Column(scale=1):
50
- gr.Markdown('# ' + _TITLE)
51
  gr.Markdown(_DESCRIPTION)
52
- create_3d_ui("wkl")
53
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
54
  demo.queue().launch(share=True)
55
 
56
  if __name__ == '__main__':
 
1
  import shlex
2
  import subprocess
3
 
 
4
  subprocess.run(shlex.split("pip install pip==24.0"), check=True)
5
  subprocess.run(
6
  shlex.split(
 
13
  ), check=True
14
  )
15
 
16
+ # 모델 체크포인트 다운로드 및 torch 설정
17
  if __name__ == "__main__":
18
  from huggingface_hub import snapshot_download
19
 
 
32
  from gradio_app.gradio_3dgen import create_ui as create_3d_ui
33
  from gradio_app.all_models import model_zoo
34
 
35
+ # ===============================
36
+ # Text-to-IMAGE 관련 API 함수 정의
37
+ # ===============================
38
+ def text_to_image(height, width, steps, scales, prompt, seed):
39
+ """
40
+ 주어진 파라미터를 이용해 외부 API (http://211.233.58.201:7971/)의
41
+ /process_and_save_image 엔드포인트를 호출하여 이미지를 생성한다.
42
+ """
43
+ from gradio_client import Client
44
+ client = Client("http://211.233.58.201:7971/")
45
+ result = client.predict(
46
+ height,
47
+ width,
48
+ steps,
49
+ scales,
50
+ prompt,
51
+ seed,
52
+ api_name="/process_and_save_image"
53
+ )
54
+ # API 응답은 dict 형태이며, "url" 혹은 "path"에 생성된 이미지 정보가 있다.
55
+ # 여기서는 "url" 값을 반환하도록 한다.
56
+ return result.get("url", None)
57
 
58
+ def update_random_seed():
59
+ """
60
+ 외부 API의 /update_random_seed 엔드포인트를 호출하여
61
+ 새로운 랜덤 시드 값을 가져온다.
62
+ """
63
+ from gradio_client import Client
64
+ client = Client("http://211.233.58.201:7971/")
65
+ return client.predict(api_name="/update_random_seed")
66
+
67
+ # ===============================
68
+ # UI 타이틀 및 설명
69
+ # ===============================
70
+ _TITLE = '''Text to 3D & Image Generation'''
71
  _DESCRIPTION = '''
72
+ Text 이용하여 3D 모델과 이미지를 생성할 수 있습니다.
73
+ 왼쪽 탭은 3D 모델 생성을, 오른쪽 탭은 이미지 생성을 담당합니다.
74
+ '''
75
 
76
  def launch():
77
+ # 3D 모델 초기화
78
  model_zoo.init_models()
79
+
80
+ # Gradio Blocks 생성 (두 탭 포함)
81
+ with gr.Blocks(title=_TITLE) as demo:
 
 
82
  with gr.Row():
83
+ gr.Markdown('# ' + _TITLE)
 
84
  gr.Markdown(_DESCRIPTION)
85
+
86
+ # 탭 생성: 기존의 Text-to-3D와 새로 추가한 Text-to-IMAGE
87
+ with gr.Tabs():
88
+ with gr.Tab("Text to 3D"):
89
+ create_3d_ui("wkl")
90
+
91
+ with gr.Tab("Text to IMAGE"):
92
+ # 이미지 생성을 위한 파라미터 입력 컴포넌트 구성
93
+ with gr.Row():
94
+ height_slider = gr.Slider(label="Height", minimum=256, maximum=2048, step=1, value=1024)
95
+ width_slider = gr.Slider(label="Width", minimum=256, maximum=2048, step=1, value=1024)
96
+ with gr.Row():
97
+ steps_slider = gr.Slider(label="Inference Steps", minimum=1, maximum=100, step=1, value=8)
98
+ scales_slider = gr.Slider(label="Guidance Scale", minimum=1.0, maximum=10.0, step=0.1, value=3.5)
99
+ prompt_text = gr.Textbox(label="Image Description", placeholder="Enter prompt here", lines=2)
100
+ seed_number = gr.Number(label="Seed (optional, leave empty for random)", value=None)
101
+
102
+ # 'Update Random Seed' 버튼을 누르면 API를 통해 새로운 시드값을 받아 입력란 업데이트
103
+ update_seed_button = gr.Button("Update Random Seed")
104
+ update_seed_button.click(fn=update_random_seed, inputs=[], outputs=seed_number)
105
+
106
+ generate_button = gr.Button("Generate Image")
107
+ image_output = gr.Image(label="Generated Image")
108
+
109
+ # 'Generate Image' 버튼 클릭 시 text_to_image 함수를 호출하여 결과 이미지를 출력
110
+ generate_button.click(
111
+ fn=text_to_image,
112
+ inputs=[height_slider, width_slider, steps_slider, scales_slider, prompt_text, seed_number],
113
+ outputs=image_output
114
+ )
115
+
116
  demo.queue().launch(share=True)
117
 
118
  if __name__ == '__main__':