deepakdethliya commited on
Commit
f0c2e5f
·
verified ·
1 Parent(s): 67a3fd3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -9
app.py CHANGED
@@ -12,18 +12,16 @@ ADAPTER_MODEL_ID = "vsple/LegalBuddy-Qwen-1.5B"
12
  # Load tokenizer
13
  tokenizer = AutoTokenizer.from_pretrained(BASE_MODEL_ID, trust_remote_code=True)
14
 
15
- # Load base model
16
- print("Loading base model...")
17
- base_model = AutoModelForCausalLM.from_pretrained(
 
18
  BASE_MODEL_ID,
19
- torch_dtype=torch.float16 if torch.cuda.is_available() else torch.float32,
20
- device_map="auto",
21
  trust_remote_code=True
22
- )
23
 
24
- # Load adapter
25
- print("Loading adapter...")
26
- model = PeftModel.from_pretrained(base_model, ADAPTER_MODEL_ID)
27
  model = model.eval()
28
 
29
  def predict(message, history, system_prompt, max_tokens, temperature, top_p):
 
12
  # Load tokenizer
13
  tokenizer = AutoTokenizer.from_pretrained(BASE_MODEL_ID, trust_remote_code=True)
14
 
15
+ # Load model (Fixed loading logic for HF Spaces)
16
+ print("Loading model and adapter...")
17
+ device = "cuda" if torch.cuda.is_available() else "cpu"
18
+ model = AutoModelForCausalLM.from_pretrained(
19
  BASE_MODEL_ID,
20
+ torch_dtype=torch.float32,
 
21
  trust_remote_code=True
22
+ ).to(device)
23
 
24
+ model = PeftModel.from_pretrained(model, ADAPTER_MODEL_ID)
 
 
25
  model = model.eval()
26
 
27
  def predict(message, history, system_prompt, max_tokens, temperature, top_p):