Spaces:
Sleeping
Sleeping
Update medication_agent.py
Browse files- medication_agent.py +11 -30
medication_agent.py
CHANGED
@@ -1,30 +1,11 @@
|
|
1 |
-
import
|
2 |
-
import
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
medications[reminder_id] = {"medicine": medicine, "time": time, "status": "Pending"}
|
13 |
-
return f"Reminder set for {medicine} at {time}. Reminder ID: {reminder_id}"
|
14 |
-
|
15 |
-
def mark_medication_taken(reminder_id: str):
|
16 |
-
"""Mark a medication as taken."""
|
17 |
-
if reminder_id in medications:
|
18 |
-
medications[reminder_id]["status"] = "Taken"
|
19 |
-
return f"Medication {medications[reminder_id]['medicine']} marked as taken."
|
20 |
-
return "Reminder not found."
|
21 |
-
|
22 |
-
def suggest_medications(symptom: str):
|
23 |
-
"""Suggest medications based on symptoms."""
|
24 |
-
# Query OpenAI GPT for suggestions based on symptom
|
25 |
-
response = openai.Completion.create(
|
26 |
-
model="gpt-3.5-turbo",
|
27 |
-
prompt=f"Suggest medications for a patient with the symptom {symptom}.",
|
28 |
-
max_tokens=150
|
29 |
-
)
|
30 |
-
return response.choices[0].text.strip().split("\n")
|
|
|
1 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
2 |
+
import torch
|
3 |
+
|
4 |
+
def get_medication_suggestions(symptom):
|
5 |
+
model_name = "m42-health/med42-70b"
|
6 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
7 |
+
model = AutoModelForCausalLM.from_pretrained(model_name)
|
8 |
+
prompt = f"Suggest medications for a patient with the symptom: {symptom}."
|
9 |
+
inputs = tokenizer(prompt, return_tensors="pt")
|
10 |
+
outputs = model.generate(**inputs, max_new_tokens=150)
|
11 |
+
return tokenizer.decode(outputs[0], skip_special_tokens=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|