rootxhacker commited on
Commit
a04d31e
1 Parent(s): a93c076

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -14
app.py CHANGED
@@ -4,28 +4,23 @@ from transformers import AutoModelForCausalLM, AutoTokenizer
4
  import gradio as gr
5
  import spaces
6
 
7
- # Load the model and tokenizer
8
- peft_model_id = "rootxhacker/CodeAstra-7B"
9
- config = PeftConfig.from_pretrained(peft_model_id)
10
 
11
- # Determine the device
12
- device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
13
 
14
- # Load the model on the appropriate device
15
- model = AutoModelForCausalLM.from_pretrained(
 
 
 
 
16
  config.base_model_name_or_path,
17
  return_dict=True,
18
  load_in_4bit=True,
19
  device_map="auto" # This will automatically handle device placement
20
- )
21
 
22
- tokenizer = AutoTokenizer.from_pretrained(config.base_model_name_or_path)
23
 
24
- # Load the Lora model
25
- model = PeftModel.from_pretrained(model, peft_model_id)
26
-
27
- @spaces.GPU(duration=200)
28
- def get_completion(query, model, tokenizer):
29
  inputs = tokenizer(query, return_tensors="pt").to(device) # Move inputs to the same device as the model
30
  outputs = model.generate(**inputs, max_new_tokens=512, do_sample=True, temperature=0.7)
31
  return tokenizer.decode(outputs[0], skip_special_tokens=True)
 
4
  import gradio as gr
5
  import spaces
6
 
 
 
 
7
 
 
 
8
 
9
+ @spaces.GPU(duration=200)
10
+ def get_completion(query, model, tokenizer):
11
+ peft_model_id = "rootxhacker/CodeAstra-7B"
12
+ config = PeftConfig.from_pretrained(peft_model_id)
13
+ device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
14
+ model = AutoModelForCausalLM.from_pretrained(
15
  config.base_model_name_or_path,
16
  return_dict=True,
17
  load_in_4bit=True,
18
  device_map="auto" # This will automatically handle device placement
19
+ )
20
 
21
+ tokenizer = AutoTokenizer.from_pretrained(config.base_model_name_or_path)
22
 
23
+ model = PeftModel.from_pretrained(model, peft_model_id)
 
 
 
 
24
  inputs = tokenizer(query, return_tensors="pt").to(device) # Move inputs to the same device as the model
25
  outputs = model.generate(**inputs, max_new_tokens=512, do_sample=True, temperature=0.7)
26
  return tokenizer.decode(outputs[0], skip_special_tokens=True)