nafisneehal commited on
Commit
4154a1a
·
verified ·
1 Parent(s): f3168bc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -14
app.py CHANGED
@@ -24,7 +24,6 @@ Do not give any additional explanations or use any tags or headers, only return
24
  """
25
 
26
  test_input_string = """
27
- ###Question:
28
  <Title:>Vinorelbine in Treating Patients With Advanced Solid Tumors That Have Not Responded to Treatment and Liver Dysfunction <BriefSummary:>RATIONALE: Drugs used in chemotherapy, such as vinorelbine, work in different ways to stop the growth of tumor cells, either by killing the cells or by stopping them from dividing.
29
  PURPOSE: This pilot trial is studying the side effects and best dose of vinorelbine in treating patients with advanced solid tumors that have not responded to treatment and liver dysfunction. <EligibilityCriteria:>DISEASE CHARACTERISTICS:
30
  * Histologically confirmed advanced solid tumor
@@ -65,22 +64,46 @@ def load_model(model_name):
65
  model.to(device)
66
  tokenizer = AutoTokenizer.from_pretrained(model_name)
67
 
 
 
 
 
 
 
 
 
 
 
 
68
  @spaces.GPU
69
  def generate_response(system_instruction, user_input):
70
- # Format the prompt using the messages structure
71
- messages = [
72
- {"role": "system", "content": system_instruction},
73
- {"role": "user", "content": user_input},
74
- ]
75
- encodeds = tokenizer.apply_chat_template(messages, return_tensors="pt").to(device)
76
- model_inputs = encodeds.to(device)
77
-
78
- # Generate model response
79
- with torch.no_grad():
80
- generated_ids = model.generate(model_inputs, max_new_tokens=1000, do_sample=True)
81
- # Find everything after the <|assistant|> tag
 
 
 
 
 
82
  decoded_output = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
83
- assistant_response = decoded_output.split("<|assistant|>")[-1].strip()
 
 
 
 
 
 
 
 
84
 
85
  return assistant_response
86
 
 
24
  """
25
 
26
  test_input_string = """
 
27
  <Title:>Vinorelbine in Treating Patients With Advanced Solid Tumors That Have Not Responded to Treatment and Liver Dysfunction <BriefSummary:>RATIONALE: Drugs used in chemotherapy, such as vinorelbine, work in different ways to stop the growth of tumor cells, either by killing the cells or by stopping them from dividing.
28
  PURPOSE: This pilot trial is studying the side effects and best dose of vinorelbine in treating patients with advanced solid tumors that have not responded to treatment and liver dysfunction. <EligibilityCriteria:>DISEASE CHARACTERISTICS:
29
  * Histologically confirmed advanced solid tumor
 
64
  model.to(device)
65
  tokenizer = AutoTokenizer.from_pretrained(model_name)
66
 
67
+ alpaca_prompt = """Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request.
68
+
69
+ ### Instruction:
70
+ {}
71
+
72
+ ### Input:
73
+ {}
74
+
75
+ ### Response:
76
+ {}"""
77
+
78
  @spaces.GPU
79
  def generate_response(system_instruction, user_input):
80
+ # # Format the prompt using the messages structure
81
+ # messages = [
82
+ # {"role": "system", "content": system_instruction},
83
+ # {"role": "user", "content": user_input},
84
+ # ]
85
+ # encodeds = tokenizer.apply_chat_template(messages, return_tensors="pt").to(device)
86
+ # model_inputs = encodeds.to(device)
87
+
88
+ inputs = tokenizer([
89
+ alpaca_prompt.format(
90
+ test_instruction_string, # instruction
91
+ test_input_string, # input
92
+ "", # output - leave this blank for generation!
93
+ )
94
+ ], return_tensors = "pt").to("cuda")
95
+
96
+ outputs = model.generate(**inputs, max_new_tokens = 1000, use_cache = True)
97
  decoded_output = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
98
+ assistant_response = decoded_output
99
+ # tokenizer.batch_decode(outputs)
100
+
101
+ # # Generate model response
102
+ # with torch.no_grad():
103
+ # generated_ids = model.generate(model_inputs, max_new_tokens=1000, do_sample=True)
104
+ # # Find everything after the <|assistant|> tag
105
+ # decoded_output = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
106
+ # assistant_response = decoded_output.split("<|assistant|>")[-1].strip()
107
 
108
  return assistant_response
109