Razon2006 commited on
Commit
6aafe97
Β·
verified Β·
1 Parent(s): 9024f27

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -6
app.py CHANGED
@@ -13,7 +13,6 @@ from peft import PeftModel
13
  BASE_MODEL = "unsloth/gemma-3-270m-it"
14
  LORA_PATH = "Razon2006/gemma3-tamil-Grapheme-NewChange-r32-lr"
15
 
16
- # Retrieve the Hugging Face token from environment secrets
17
  hf_token = os.environ.get("HF_TOKEN")
18
 
19
  print("Loading tokenizer...")
@@ -27,12 +26,11 @@ base_model = AutoModelForCausalLM.from_pretrained(
27
  )
28
 
29
  print("Loading LoRA adapter...")
30
- # Load the model globally and move to CUDA.
31
- # ZeroGPU safely intercepts standard PyTorch .to("cuda") calls.
32
  model = PeftModel.from_pretrained(base_model, LORA_PATH, token=hf_token)
33
- model.to("cuda")
34
- model.eval()
35
- print("Model ready!")
 
36
 
37
  # ─── Grapheme Tokenizer & Constants ───────────────────────────────────────────
38
  INSTRUCTION = (
@@ -89,6 +87,9 @@ def post_process_grapheme(text):
89
  # ─── Inference Pipeline ───────────────────────────────────────────────────────
90
  @spaces.GPU(duration=60)
91
  def generate_pathaseth(venba, max_new_tokens=256):
 
 
 
92
  venba = venba.strip()
93
  if not venba:
94
  return "Please enter a Venba verse."
 
13
  BASE_MODEL = "unsloth/gemma-3-270m-it"
14
  LORA_PATH = "Razon2006/gemma3-tamil-Grapheme-NewChange-r32-lr"
15
 
 
16
  hf_token = os.environ.get("HF_TOKEN")
17
 
18
  print("Loading tokenizer...")
 
26
  )
27
 
28
  print("Loading LoRA adapter...")
 
 
29
  model = PeftModel.from_pretrained(base_model, LORA_PATH, token=hf_token)
30
+
31
+ # Best practice for ZeroGPU: Keep model in CPU RAM globally.
32
+ # We will move it to the GPU inside the annotated function.
33
+ print("Model loaded into memory!")
34
 
35
  # ─── Grapheme Tokenizer & Constants ───────────────────────────────────────────
36
  INSTRUCTION = (
 
87
  # ─── Inference Pipeline ───────────────────────────────────────────────────────
88
  @spaces.GPU(duration=60)
89
  def generate_pathaseth(venba, max_new_tokens=256):
90
+ # Explicitly move model to GPU here. ZeroGPU safely grants hardware access at this exact moment.
91
+ model.to("cuda")
92
+
93
  venba = venba.strip()
94
  if not venba:
95
  return "Please enter a Venba verse."