visproj commited on
Commit
622c19c
·
verified ·
1 Parent(s): 234de57

Update app.py

Browse files

add pharmacy tools

Files changed (1) hide show
  1. app.py +42 -1
app.py CHANGED
@@ -9,6 +9,47 @@ from Gradio_UI import GradioUI
9
 
10
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
11
  @tool
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
  def my_cutom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type
13
  #Keep this format for the description / args / args description but feel free to modify the tool
14
  """A tool that does nothing yet
@@ -51,7 +92,7 @@ with open("prompts.yaml", 'r') as stream:
51
 
52
  agent = CodeAgent(
53
  model=model,
54
- tools=[final_answer,get_current_time_in_timezone, image_generation_tool], ## add your tools here (don't remove final answer)
55
  max_steps=6,
56
  verbosity_level=1,
57
  grammar=None,
 
9
 
10
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
11
  @tool
12
+ def drug_interaction_checker(drug_1: str, drug_2: str) -> str:
13
+ """Checks for potential interactions between two medications using the FDA Drug Label API.
14
+
15
+ Args:
16
+ drug_1: The name of the first drug.
17
+ drug_2: The name of the second drug.
18
+ """
19
+ base_url = "https://api.fda.gov/drug/label.json"
20
+ query = f'search=openfda.brand_name:"{drug_1}"+openfda.brand_name:"{drug_2}"'
21
+ response = requests.get(f"{base_url}?{query}")
22
+
23
+ if response.status_code == 200:
24
+ data = response.json()
25
+ if "results" in data and len(data["results"]) > 0:
26
+ interactions = data["results"][0].get("drug_interactions", ["No known interactions found."])
27
+ return f"⚠️ Drug Interaction Warning: {interactions[0]}"
28
+ else:
29
+ return "✅ No interaction data found for these drugs."
30
+ else:
31
+ return f"❌ Error fetching interaction data: {response.status_code}"
32
+
33
+ @tool
34
+ def sig_expander(sig: str) -> str:
35
+ """Expands a prescription SIG shorthand into human-readable patient instructions.
36
+
37
+ Args:
38
+ sig: A prescription instruction in shorthand (e.g., '1 tab po qd').
39
+ """
40
+ sig_map = {
41
+ "1 tab po qd": "Take 1 tablet by mouth once daily.",
42
+ "1 tab po bid": "Take 1 tablet by mouth twice daily.",
43
+ "1 tab po tid": "Take 1 tablet by mouth three times daily.",
44
+ "1 tab po qid": "Take 1 tablet by mouth four times daily.",
45
+ "1 tab po prn": "Take 1 tablet by mouth as needed.",
46
+ "1 tab po q12h": "Take 1 tablet by mouth every 12 hours.",
47
+ "1 tab po q8h": "Take 1 tablet by mouth every 8 hours.",
48
+ "2 tab po qd": "Take 2 tablets by mouth once daily."
49
+ }
50
+
51
+ return sig_map.get(sig.lower(), "❌ No direct match found. Please clarify.")
52
+ @tool
53
  def my_cutom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type
54
  #Keep this format for the description / args / args description but feel free to modify the tool
55
  """A tool that does nothing yet
 
92
 
93
  agent = CodeAgent(
94
  model=model,
95
+ tools=[final_answer,get_current_time_in_timezone, image_generation_tool, drug_interaction_checker, sig_expander], ## add your tools here (don't remove final answer)
96
  max_steps=6,
97
  verbosity_level=1,
98
  grammar=None,