Akash Garg commited on
Commit
0964e01
·
1 Parent(s): 76ac4e2

handling zerogpu in prompt handling

Browse files
Files changed (1) hide show
  1. app.py +16 -12
app.py CHANGED
@@ -1,3 +1,4 @@
 
1
  import argparse
2
  import gradio as gr
3
  import os
@@ -19,7 +20,6 @@ from pathlib import Path
19
  import uuid
20
  import shutil
21
  from huggingface_hub import snapshot_download
22
- import spaces
23
 
24
 
25
  GLOBAL_STATE = {}
@@ -40,8 +40,22 @@ def gen_save_folder(max_size=200):
40
 
41
  return new_folder
42
 
 
43
  def handle_text_prompt(input_prompt, variance = 0):
44
  print(f"prompt: {input_prompt}, variance: {variance}")
 
 
 
 
 
 
 
 
 
 
 
 
 
45
  top_p = None if variance == 0 else (100 - variance) / 100.0
46
  mesh_v_f = GLOBAL_STATE["engine_fast"].t2s([input_prompt], use_kv_cache=True, resolution_base=8.0, top_p=top_p)
47
  # save output
@@ -92,18 +106,8 @@ def build_interface():
92
 
93
  return interface
94
 
95
- @spaces.GPU
96
  def generate(args):
97
- config_path = args.config_path
98
- gpt_ckpt_path = "./model_weights/shape_gpt.safetensors"
99
- shape_ckpt_path = "./model_weights/shape_tokenizer.safetensors"
100
- engine_fast = EngineFast(
101
- config_path,
102
- gpt_ckpt_path,
103
- shape_ckpt_path,
104
- device=torch.device("cuda"),
105
- )
106
- GLOBAL_STATE["engine_fast"] = engine_fast
107
  GLOBAL_STATE["SAVE_DIR"] = args.save_dir
108
  os.makedirs(GLOBAL_STATE["SAVE_DIR"], exist_ok=True)
109
 
 
1
+ import spaces
2
  import argparse
3
  import gradio as gr
4
  import os
 
20
  import uuid
21
  import shutil
22
  from huggingface_hub import snapshot_download
 
23
 
24
 
25
  GLOBAL_STATE = {}
 
40
 
41
  return new_folder
42
 
43
+ @spaces.GPU
44
  def handle_text_prompt(input_prompt, variance = 0):
45
  print(f"prompt: {input_prompt}, variance: {variance}")
46
+
47
+ if "engine_fast" not in GLOBAL_STATE:
48
+ config_path = GLOBAL_STATE["config_path"]
49
+ gpt_ckpt_path = "./model_weights/shape_gpt.safetensors"
50
+ shape_ckpt_path = "./model_weights/shape_tokenizer.safetensors"
51
+ engine_fast = EngineFast(
52
+ config_path,
53
+ gpt_ckpt_path,
54
+ shape_ckpt_path,
55
+ device=torch.device("cuda"),
56
+ )
57
+ GLOBAL_STATE["engine_fast"] = engine_fast
58
+
59
  top_p = None if variance == 0 else (100 - variance) / 100.0
60
  mesh_v_f = GLOBAL_STATE["engine_fast"].t2s([input_prompt], use_kv_cache=True, resolution_base=8.0, top_p=top_p)
61
  # save output
 
106
 
107
  return interface
108
 
 
109
  def generate(args):
110
+ GLOBAL_STATE["config_path"] = args.config_path
 
 
 
 
 
 
 
 
 
111
  GLOBAL_STATE["SAVE_DIR"] = args.save_dir
112
  os.makedirs(GLOBAL_STATE["SAVE_DIR"], exist_ok=True)
113