paddle12 commited on
Commit
237037e
·
verified ·
1 Parent(s): 2eaf83b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -11
app.py CHANGED
@@ -14,20 +14,20 @@ from openpyxl import load_workbook
14
  from typing import List, Dict, Any, Tuple
15
  from utils import *
16
 
17
- # === [1] Model and Tokenizer Loading ===
18
- base_model_id = "NousResearch/Nous-Hermes-2-Mistral-7B-DPO"
19
- lora_path = "tat-llm-final-e4"
20
 
21
- # Load base model and LoRA adapter
22
- base_model = AutoModelForCausalLM.from_pretrained(base_model_id, torch_dtype=torch.float16)
23
- model = PeftModel.from_pretrained(base_model, lora_path)
24
 
25
- device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
26
- model = model.to(device)
27
- model.eval()
28
 
29
- # Load tokenizer
30
- tokenizer = AutoTokenizer.from_pretrained(lora_path)
31
 
32
  # === Updated Generate Answer Function ===
33
  @spaces.GPU(duration=60)
@@ -35,6 +35,19 @@ def generate_answer(json_data: Dict[str, Any], question: str) -> str:
35
  """
36
  Generate answer using the fine-tuned model.
37
  """
 
 
 
 
 
 
 
 
 
 
 
 
 
38
  prompt = create_prompt(json_data, question)
39
  inputs = tokenizer(prompt, return_tensors="pt", truncation=True, max_length=1024)
40
 
 
14
  from typing import List, Dict, Any, Tuple
15
  from utils import *
16
 
17
+ # # === [1] Model and Tokenizer Loading ===
18
+ # base_model_id = "NousResearch/Nous-Hermes-2-Mistral-7B-DPO"
19
+ # lora_path = "tat-llm-final-e4"
20
 
21
+ # # Load base model and LoRA adapter
22
+ # base_model = AutoModelForCausalLM.from_pretrained(base_model_id, torch_dtype=torch.float16)
23
+ # model = PeftModel.from_pretrained(base_model, lora_path)
24
 
25
+ # device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
26
+ # model = model.to(device)
27
+ # model.eval()
28
 
29
+ # # Load tokenizer
30
+ # tokenizer = AutoTokenizer.from_pretrained(lora_path)
31
 
32
  # === Updated Generate Answer Function ===
33
  @spaces.GPU(duration=60)
 
35
  """
36
  Generate answer using the fine-tuned model.
37
  """
38
+ # === [1] Model and Tokenizer Loading ===
39
+ base_model_id = "NousResearch/Nous-Hermes-2-Mistral-7B-DPO"
40
+ lora_path = "tat-llm-final-e4"
41
+
42
+ # Load base model and LoRA adapter
43
+ base_model = AutoModelForCausalLM.from_pretrained(base_model_id, torch_dtype=torch.float16)
44
+ model = PeftModel.from_pretrained(base_model, lora_path)
45
+ # Load tokenizer
46
+ tokenizer = AutoTokenizer.from_pretrained(lora_path)
47
+ device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
48
+ model = model.to(device)
49
+ model.eval()
50
+
51
  prompt = create_prompt(json_data, question)
52
  inputs = tokenizer(prompt, return_tensors="pt", truncation=True, max_length=1024)
53