SHERVIOR commited on
Commit
293635c
·
verified ·
1 Parent(s): e8d4494

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -28
app.py CHANGED
@@ -1,65 +1,77 @@
1
- from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel,load_tool,tool
2
  import datetime
3
  import requests
4
  import pytz
5
  import yaml
6
  from tools.final_answer import FinalAnswerTool
7
-
8
  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
15
  Args:
16
- arg1: the first argument
17
- arg2: the second argument
18
  """
19
- return "What magic will you build ?"
 
 
 
 
 
20
 
 
21
  @tool
22
  def get_current_time_in_timezone(timezone: str) -> str:
23
- """A tool that fetches the current local time in a specified timezone.
24
  Args:
25
  timezone: A string representing a valid timezone (e.g., 'America/New_York').
26
  """
27
  try:
28
- # Create timezone object
29
  tz = pytz.timezone(timezone)
30
- # Get current time in that timezone
31
  local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
32
  return f"The current local time in {timezone} is: {local_time}"
33
  except Exception as e:
34
  return f"Error fetching time for timezone '{timezone}': {str(e)}"
35
 
36
-
37
- final_answer = FinalAnswerTool()
38
  model = HfApiModel(
39
- max_tokens=2096,
40
- temperature=0.5,
41
- model_id='Qwen/Qwen2.5-Coder-32B-Instruct',
42
- custom_role_conversions=None,
43
  )
44
 
45
-
46
- # Import tool from Hub
47
- image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
48
-
49
  with open("prompts.yaml", 'r') as stream:
50
  prompt_templates = yaml.safe_load(stream)
51
-
 
52
  agent = CodeAgent(
53
  model=model,
54
- tools=[final_answer], ## add your tools here (don't remove final answer)
55
  max_steps=6,
56
  verbosity_level=1,
57
  grammar=None,
58
  planning_interval=None,
59
- name=None,
60
- description=None,
61
  prompt_templates=prompt_templates
62
  )
63
 
64
-
65
- GradioUI(agent).launch()
 
1
+ from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel, load_tool, tool
2
  import datetime
3
  import requests
4
  import pytz
5
  import yaml
6
  from tools.final_answer import FinalAnswerTool
 
7
  from Gradio_UI import GradioUI
8
 
9
+ # Medical tool: Fetch research papers from PubMed
10
+ @tool
11
+ def get_pubmed_articles(query: str) -> str:
12
+ """Fetches the latest research papers from PubMed based on a query.
13
+ Args:
14
+ query: The medical or biological topic to search for.
15
+ """
16
+ url = f"https://api.ncbi.nlm.nih.gov/lit/ctxp/v1/pubmed/?format=summary&term={query}"
17
+ response = requests.get(url)
18
+ if response.status_code == 200:
19
+ return response.json() # Return article summary
20
+ else:
21
+ return "Failed to fetch articles."
22
+
23
+ # Medical tool: Explain medical terminology
24
  @tool
25
+ def explain_medical_term(term: str) -> str:
26
+ """Provides a simple explanation of a medical term.
 
27
  Args:
28
+ term: The medical term to explain.
 
29
  """
30
+ explanations = {
31
+ "hypertension": "Hypertension, or high blood pressure, is a condition where the force of blood against the artery walls is too high.",
32
+ "diabetes": "Diabetes is a chronic disease where the body either doesn't produce enough insulin or can't use it effectively.",
33
+ "anemia": "Anemia is a condition in which the blood lacks enough healthy red blood cells to carry oxygen.",
34
+ }
35
+ return explanations.get(term.lower(), "No definition found. Try a different term.")
36
 
37
+ # Tool for fetching current time in a timezone
38
  @tool
39
  def get_current_time_in_timezone(timezone: str) -> str:
40
+ """Fetches the current local time in a specified timezone.
41
  Args:
42
  timezone: A string representing a valid timezone (e.g., 'America/New_York').
43
  """
44
  try:
 
45
  tz = pytz.timezone(timezone)
 
46
  local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
47
  return f"The current local time in {timezone} is: {local_time}"
48
  except Exception as e:
49
  return f"Error fetching time for timezone '{timezone}': {str(e)}"
50
 
51
+ # Load the medical AI model (BioBERT for medical text processing)
 
52
  model = HfApiModel(
53
+ max_tokens=2096,
54
+ temperature=0.5,
55
+ model_id='dmis-lab/biobert-v1.1', # BioBERT for medical NLP tasks
56
+ custom_role_conversions=None,
57
  )
58
 
59
+ # Load prompt templates
 
 
 
60
  with open("prompts.yaml", 'r') as stream:
61
  prompt_templates = yaml.safe_load(stream)
62
+
63
+ # Define the AI agent with medical expertise
64
  agent = CodeAgent(
65
  model=model,
66
+ tools=[FinalAnswerTool(), get_pubmed_articles, explain_medical_term, get_current_time_in_timezone],
67
  max_steps=6,
68
  verbosity_level=1,
69
  grammar=None,
70
  planning_interval=None,
71
+ name="Medical Bio Expert",
72
+ description="An AI agent specialized in medical biology, capable of answering biomedical questions, retrieving PubMed articles, and explaining medical terms.",
73
  prompt_templates=prompt_templates
74
  )
75
 
76
+ # Launch the Gradio UI for interaction
77
+ GradioUI(agent, title="Medical Biology AI Expert", description="Ask me anything about medical biology!").launch()