Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -63,8 +63,6 @@ def generate_medical_response(message, history):
|
|
| 63 |
|
| 64 |
prompt = f"<|system|>\nYou are a highly accurate and helpful medical assistant.</s>\n<|user|>\n{message}</s>\n<|assistant|>\n"
|
| 65 |
inputs = tokenizer(prompt, return_tensors="pt")
|
| 66 |
-
|
| 67 |
-
input_length = inputs.input_ids.shape[1]
|
| 68 |
|
| 69 |
with torch.no_grad():
|
| 70 |
outputs = model.generate(
|
|
@@ -78,13 +76,9 @@ def generate_medical_response(message, history):
|
|
| 78 |
pad_token_id=tokenizer.eos_token_id
|
| 79 |
)
|
| 80 |
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
final_answer = tokenizer.decode(generated_tokens, skip_special_tokens=True).strip()
|
| 84 |
|
| 85 |
-
|
| 86 |
-
final_answer = final_answer.split("user:")[0].strip()
|
| 87 |
-
final_answer = final_answer.split("User:")[0].strip()
|
| 88 |
|
| 89 |
if not final_answer:
|
| 90 |
final_answer = "I apologize, but I am unable to generate a confident medical response to that exact phrasing. Could you please rephrase your question?"
|
|
|
|
| 63 |
|
| 64 |
prompt = f"<|system|>\nYou are a highly accurate and helpful medical assistant.</s>\n<|user|>\n{message}</s>\n<|assistant|>\n"
|
| 65 |
inputs = tokenizer(prompt, return_tensors="pt")
|
|
|
|
|
|
|
| 66 |
|
| 67 |
with torch.no_grad():
|
| 68 |
outputs = model.generate(
|
|
|
|
| 76 |
pad_token_id=tokenizer.eos_token_id
|
| 77 |
)
|
| 78 |
|
| 79 |
+
generated_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
|
|
|
|
|
|
| 80 |
|
| 81 |
+
final_answer = generated_text.split("<|assistant|>\n")[-1].strip()
|
|
|
|
|
|
|
| 82 |
|
| 83 |
if not final_answer:
|
| 84 |
final_answer = "I apologize, but I am unable to generate a confident medical response to that exact phrasing. Could you please rephrase your question?"
|