ruslanmv commited on
Commit
a87e997
1 Parent(s): b6d2b64

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -0
app.py CHANGED
@@ -17,6 +17,30 @@ tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
17
  tokenizer.pad_token = tokenizer.eos_token
18
  @spaces.GPU
19
  def askme(symptoms, question):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
  custom_template = [
21
  {"role": "system", "content": "You are an AI Medical Assistant trained on a vast dataset of health information. Please be thorough and provide an informative answer. If you don't know the answer to a specific medical inquiry, advise seeking professional help."},
22
  {"role": "user", "content": "Symptoms: {symptoms}\nQuestion: {question}\n"},
 
17
  tokenizer.pad_token = tokenizer.eos_token
18
  @spaces.GPU
19
  def askme(symptoms, question):
20
+ template = [
21
+ {"role": "system", "content": "You are an AI Medical Assistant trained on a vast dataset of health information. Please be thorough and provide an informative answer. If you don't know the answer to a specific medical inquiry, advise seeking professional help."},
22
+ {"role": "user", "content": f"Symptoms: {symptoms}\nQuestion: {question}\n"},
23
+ {"role": "assistant", "content": "{assistant_response}\n"}
24
+ ]
25
+
26
+ prompt = tokenizer.apply_chat_template(template, tokenize=False, add_generation_prompt=True)
27
+ inputs = tokenizer(prompt, return_tensors="pt").to(device)
28
+ outputs = model.generate(**inputs, max_new_tokens=300, use_cache=True)
29
+ response_text = tokenizer.batch_decode(outputs, skip_special_tokens=True)[0].strip()
30
+
31
+ #start_idx = response_text.find("<|im_start|>assistant")
32
+ #end_idx = response_text.find("<|im_end|>", start_idx)
33
+ #assistant_response = response_text[start_idx + len("<|im_start|>assistant"):end_idx]
34
+
35
+ #return assistant_response.split(". ")[0] + "
36
+ return response_text
37
+
38
+
39
+
40
+
41
+
42
+
43
+ def askmeold(symptoms, question):
44
  custom_template = [
45
  {"role": "system", "content": "You are an AI Medical Assistant trained on a vast dataset of health information. Please be thorough and provide an informative answer. If you don't know the answer to a specific medical inquiry, advise seeking professional help."},
46
  {"role": "user", "content": "Symptoms: {symptoms}\nQuestion: {question}\n"},