Kangheng commited on
Commit
dfc647c
·
verified ·
1 Parent(s): 4af54f6

load model when init

Browse files
Files changed (1) hide show
  1. app.py +15 -0
app.py CHANGED
@@ -61,6 +61,7 @@ _LOADED_MODEL_NAME = None
61
 
62
 
63
 
 
64
  def get_model(model_name: Optional[str] = None):
65
  """Load and cache the Step3-VL-10B model and processor."""
66
  global _MODEL, _PROCESSOR, _LOADED_MODEL_NAME
@@ -100,6 +101,13 @@ def get_model(model_name: Optional[str] = None):
100
  return _MODEL, _PROCESSOR
101
 
102
 
 
 
 
 
 
 
 
103
  def resolve_generation_tokens(processor):
104
  """Resolve eos/pad token ids and stop strings for safer stopping."""
105
  tokenizer = getattr(processor, "tokenizer", processor)
@@ -633,6 +641,7 @@ h3 {
633
 
634
  # Gradio Interface
635
  with gr.Blocks(title="Step3-VL-10B", css=custom_css, theme=gr.themes.Soft()) as demo:
 
636
  # Header
637
  gr.HTML("""
638
  <div class="app-header">
@@ -745,6 +754,12 @@ with gr.Blocks(title="Step3-VL-10B", css=custom_css, theme=gr.themes.Soft()) as
745
  outputs=[chatbot, user_text, image_file]
746
  )
747
 
 
 
 
 
 
 
748
  if __name__ == "__main__":
749
  import argparse
750
  parser = argparse.ArgumentParser()
 
61
 
62
 
63
 
64
+ @spaces.GPU
65
  def get_model(model_name: Optional[str] = None):
66
  """Load and cache the Step3-VL-10B model and processor."""
67
  global _MODEL, _PROCESSOR, _LOADED_MODEL_NAME
 
101
  return _MODEL, _PROCESSOR
102
 
103
 
104
+ @spaces.GPU
105
+ def warmup_model(model_name: Optional[str] = None):
106
+ """Warmup the model once at app startup."""
107
+ get_model(model_name)
108
+ return True
109
+
110
+
111
  def resolve_generation_tokens(processor):
112
  """Resolve eos/pad token ids and stop strings for safer stopping."""
113
  tokenizer = getattr(processor, "tokenizer", processor)
 
641
 
642
  # Gradio Interface
643
  with gr.Blocks(title="Step3-VL-10B", css=custom_css, theme=gr.themes.Soft()) as demo:
644
+ model_ready = gr.State(False)
645
  # Header
646
  gr.HTML("""
647
  <div class="app-header">
 
754
  outputs=[chatbot, user_text, image_file]
755
  )
756
 
757
+ demo.load(
758
+ fn=warmup_model,
759
+ inputs=None,
760
+ outputs=model_ready
761
+ )
762
+
763
  if __name__ == "__main__":
764
  import argparse
765
  parser = argparse.ArgumentParser()