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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -41
app.py CHANGED
@@ -27,44 +27,16 @@ def askme(symptoms, question):
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"},
47
- {"role": "assistant", "content": "{assistant_response}\n"}
48
- ]
49
-
50
- sys_message = custom_template[0]["content"]
51
- content = custom_template[1]["content"].format(symptoms=symptoms, question=question)
52
- messages = [{"role": "system", "content": sys_message}, {"role": "user", "content": content}]
53
-
54
- prompt = tokenizer.apply_chat_template(messages, template=custom_template, tokenize=False, add_generation_prompt=True)
55
- inputs = tokenizer(prompt, return_tensors="pt").to(device) # Ensure inputs are on CUDA device
56
- outputs = model.generate(**inputs, max_new_tokens=300, use_cache=True)
57
- response_text = tokenizer.batch_decode(outputs, skip_special_tokens=True)[0].strip()
58
-
59
- # Extract only the assistant's response
60
- start_idx = response_text.find("<|im_start|>assistant")
61
- end_idx = response_text.find("<|im_end|>", start_idx)
62
- assistant_response = response_text[start_idx + len("<|im_start|>assistant"):end_idx]
63
-
64
- # Return only one answer
65
- answers = assistant_response.split(". ")
66
- return answers[0] + "."
67
-
68
 
69
  # Example usage
70
  symptoms = '''\
@@ -128,12 +100,7 @@ Developed by Ruslan Magana. Visit [https://ruslanmv.com/](https://ruslanmv.com/)
128
 
129
 
130
 
131
- examples = [
132
- ["headache", "What are the possible causes of a headache?"],
133
- ["fever", "How can I treat a fever at home?"],
134
- ["cough", "What are the symptoms of a cough?"],
135
- ["chest pain", "What are the possible causes of chest pain?"],
136
- ]
137
 
138
 
139
  symptoms_input = gr.Textbox(label="Symptoms")
 
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
  return response_text
31
 
32
 
33
+ examples = [
34
+ ["headache", "What are the possible causes of a headache?"],
35
+ ["fever", "How can I treat a fever at home?"],
36
+ ["cough", "What are the symptoms of a cough?"],
37
+ ["chest pain", "What are the possible causes of chest pain?"],
38
+ ]
39
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
40
 
41
  # Example usage
42
  symptoms = '''\
 
100
 
101
 
102
 
103
+
 
 
 
 
 
104
 
105
 
106
  symptoms_input = gr.Textbox(label="Symptoms")