Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -37,29 +37,11 @@ def askme(symptoms, question):
|
|
37 |
end_idx = response_text.find("<|im_end|>", start_idx)
|
38 |
assistant_response = response_text[start_idx + len("<|im_start|>assistant"):end_idx]
|
39 |
# Return only one answer
|
40 |
-
answers = assistant_response.split(". ")
|
41 |
-
return answers[0] + "."
|
|
|
42 |
|
43 |
|
44 |
-
|
45 |
-
def askmeold(symptoms, question):
|
46 |
-
sys_message = '''\
|
47 |
-
You are an AI Medical Assistant trained on a vast dataset of health information. Please be thorough and
|
48 |
-
provide an informative answer. If you don't know the answer to a specific medical inquiry, advise seeking professional help.
|
49 |
-
'''
|
50 |
-
content = "symptoms:"+ symptoms + "question:" + question
|
51 |
-
messages = [{"role": "system", "content": sys_message}, {"role": "user", "content": content}]
|
52 |
-
prompt = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
|
53 |
-
inputs = tokenizer(prompt, return_tensors="pt").to(device) # Ensure inputs are on CUDA device
|
54 |
-
outputs = model.generate(**inputs, max_new_tokens=200, use_cache=True)
|
55 |
-
response_text = tokenizer.batch_decode(outputs, skip_special_tokens=True)[0].strip()
|
56 |
-
# Remove system messages and content
|
57 |
-
# Extract and return the generated text, removing the prompt
|
58 |
-
# Extract only the assistant's response
|
59 |
-
#answer = response_text.split('<|im_start|>assistant')[-1].strip()
|
60 |
-
#answer =response_text.split("assistant")[1].strip().split("user")[0].strip()
|
61 |
-
return response_text
|
62 |
-
|
63 |
# Example usage
|
64 |
symptoms = '''\
|
65 |
I'm a 35-year-old male and for the past few months, I've been experiencing fatigue,
|
|
|
37 |
end_idx = response_text.find("<|im_end|>", start_idx)
|
38 |
assistant_response = response_text[start_idx + len("<|im_start|>assistant"):end_idx]
|
39 |
# Return only one answer
|
40 |
+
#answers = assistant_response.split(". ")
|
41 |
+
#return answers[0] + "."
|
42 |
+
assistant_response
|
43 |
|
44 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
45 |
# Example usage
|
46 |
symptoms = '''\
|
47 |
I'm a 35-year-old male and for the past few months, I've been experiencing fatigue,
|