xjdeng commited on
Commit
c5b256d
·
verified ·
1 Parent(s): 1b14191

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -2
app.py CHANGED
@@ -6,6 +6,7 @@ import yaml
6
  import PyPDF2
7
  import os
8
  from tools.final_answer import FinalAnswerTool
 
9
 
10
  from Gradio_UI import GradioUI
11
 
@@ -29,6 +30,20 @@ def extract_text_from_pdf(file_path: str) -> str:
29
  except Exception as e:
30
  return f"Error reading PDF: {str(e)}"
31
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32
 
33
  final_answer = FinalAnswerTool()
34
 
@@ -39,7 +54,7 @@ model = HfApiModel(
39
  token= os.getenv('Token'),
40
  max_tokens=2096,
41
  temperature=0.5,
42
- model_id='Qwen/Qwen2.5-Coder-32B-Instruct',# it is possible that this model may be overloaded
43
  custom_role_conversions=None,
44
  )
45
 
@@ -52,7 +67,7 @@ with open("prompts.yaml", 'r') as stream:
52
 
53
  agent = CodeAgent(
54
  model=model,
55
- tools=[final_answer, extract_text_from_pdf], ## add your tools here (don't remove final answer)
56
  max_steps=6,
57
  verbosity_level=1,
58
  grammar=None,
 
6
  import PyPDF2
7
  import os
8
  from tools.final_answer import FinalAnswerTool
9
+ from dateutil.parser import parse
10
 
11
  from Gradio_UI import GradioUI
12
 
 
30
  except Exception as e:
31
  return f"Error reading PDF: {str(e)}"
32
 
33
+ @tool
34
+ def days_ago(date: str) -> int:
35
+ """
36
+ Gets how many days ago is the the date in question. If the result is negative, then it's in the future.
37
+ Args:
38
+ date: The date in mm/dd/yyyy format as a string
39
+ Output: the # of days ago as a int.
40
+
41
+ """
42
+ try:
43
+ return (datetime.datetime.today() - parse(date)).days
44
+ except Exception as e:
45
+ return f"Error parsing date, see error: {str(e)}"
46
+
47
 
48
  final_answer = FinalAnswerTool()
49
 
 
54
  token= os.getenv('Token'),
55
  max_tokens=2096,
56
  temperature=0.5,
57
+ model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud',
58
  custom_role_conversions=None,
59
  )
60
 
 
67
 
68
  agent = CodeAgent(
69
  model=model,
70
+ tools=[final_answer, extract_text_from_pdf, DuckDuckGoSearchTool(), days_ago], ## add your tools here (don't remove final answer)
71
  max_steps=6,
72
  verbosity_level=1,
73
  grammar=None,