hamnamughal commited on
Commit
ea31718
·
verified ·
1 Parent(s): edc7c18

Update lifestyle_agent.py

Browse files
Files changed (1) hide show
  1. lifestyle_agent.py +11 -18
lifestyle_agent.py CHANGED
@@ -1,18 +1,11 @@
1
- def recommend_lifestyle(symptom: str, value: str):
2
- if symptom.lower() == "high blood pressure":
3
- return f"Recommended lifestyle for {symptom}: Reduce salt intake, avoid stress, exercise regularly, and monitor your BP."
4
- elif symptom.lower() == "diabetes":
5
- return f"Recommended lifestyle for {symptom}: Maintain a low-carb diet, monitor blood sugar, exercise, and avoid processed foods."
6
- return "No recommendations available."
7
-
8
- def get_fitness_tips():
9
- return "Try to engage in at least 30 minutes of physical activity daily. Regular exercise helps to lower blood pressure and improve overall health."
10
-
11
- def get_sleep_advice():
12
- return "Ensure you get at least 7-8 hours of sleep each night. Avoid caffeine and screen time before bedtime."
13
-
14
- def get_diet_tips():
15
- return "Eat a balanced diet with plenty of vegetables, fruits, and whole grains. Avoid high-sugar and high-fat foods."
16
-
17
- def get_general_suggestions():
18
- return "It is important to maintain a balanced lifestyle: Eat healthy, stay active, and manage stress effectively."
 
1
+ from transformers import AutoTokenizer, AutoModelForCausalLM
2
+ import torch
3
+
4
+ def get_lifestyle_tips(lifestyle_query):
5
+ model_name = "m42-health/med42-70b"
6
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
7
+ model = AutoModelForCausalLM.from_pretrained(model_name)
8
+ prompt = f"Give healthy lifestyle tips based on the query: {lifestyle_query}."
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)