hamxaameer commited on
Commit
ebf0eaf
·
verified ·
1 Parent(s): 1d12e3d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -3
app.py CHANGED
@@ -7,10 +7,18 @@ import os
7
  MODEL_NAME = "model.safetensors" # Replace with your actual HF model repo
8
  DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
9
 
10
- # Load model and tokenizer
11
- @gr.utils.cache
 
 
12
  def load_model():
13
- """Load the model and tokenizer with caching"""
 
 
 
 
 
 
14
  print(f"Loading model from: {MODEL_NAME}")
15
  print(f"Using device: {DEVICE}")
16
 
@@ -33,6 +41,11 @@ def load_model():
33
  model = model.to(DEVICE)
34
 
35
  print("✅ Model and tokenizer loaded successfully!")
 
 
 
 
 
36
  return model, tokenizer
37
 
38
  # Initialize model and tokenizer
 
7
  MODEL_NAME = "model.safetensors" # Replace with your actual HF model repo
8
  DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
9
 
10
+ # Global variables for model caching
11
+ _model = None
12
+ _tokenizer = None
13
+
14
  def load_model():
15
+ """Load the model and tokenizer with simple caching"""
16
+ global _model, _tokenizer
17
+
18
+ # Return cached model if already loaded
19
+ if _model is not None and _tokenizer is not None:
20
+ return _model, _tokenizer
21
+
22
  print(f"Loading model from: {MODEL_NAME}")
23
  print(f"Using device: {DEVICE}")
24
 
 
41
  model = model.to(DEVICE)
42
 
43
  print("✅ Model and tokenizer loaded successfully!")
44
+
45
+ # Cache the loaded model and tokenizer
46
+ _model = model
47
+ _tokenizer = tokenizer
48
+
49
  return model, tokenizer
50
 
51
  # Initialize model and tokenizer