wt002 commited on
Commit
b7b0a53
·
verified ·
1 Parent(s): 6b81dc2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -8
app.py CHANGED
@@ -31,7 +31,7 @@ class BasicAgent:
31
 
32
  print("BasicAgent initialized.")
33
 
34
- def __call__(self, question: str) -> str:
35
  print(f"Agent received question (first 50 chars): {question[:50]}...")
36
  fixed_answer = self.agent.process_request(question)
37
  print(f"Agent returning answer: {fixed_answer}")
@@ -39,7 +39,7 @@ class BasicAgent:
39
 
40
 
41
 
42
- def generate_response(self, prompt: str) -> str:
43
  """Get response from Gemini"""
44
  try:
45
  response = self.model.generate_content(prompt)
@@ -47,7 +47,7 @@ class BasicAgent:
47
  except Exception as e:
48
  return f"Error generating response: {str(e)}"
49
 
50
- def web_search(self, query: str) -> List[Dict]:
51
  """Use SearxNG meta-search engine"""
52
  params = {
53
  "q": query,
@@ -61,12 +61,12 @@ class BasicAgent:
61
  except requests.RequestException:
62
  return []
63
 
64
- def wikipedia_search(self, query: str) -> str:
65
  """Get Wikipedia summary"""
66
  page = self.wiki.page(query)
67
  return page.summary if page.exists() else "No Wikipedia page found"
68
 
69
- def process_document(self, file_path: str) -> str:
70
  """Handle PDF, Word, CSV, Excel files"""
71
  if not os.path.exists(file_path):
72
  return "File not found"
@@ -87,7 +87,7 @@ class BasicAgent:
87
  except Exception as e:
88
  return f"Error processing document: {str(e)}"
89
 
90
- def _process_pdf(self, file_path: str) -> str:
91
  """Process PDF using Gemini's vision capability"""
92
  try:
93
  # For Gemini 1.5 or later which supports file uploads
@@ -107,7 +107,7 @@ class BasicAgent:
107
  except ImportError:
108
  return "PDF processing requires PyPDF2 (pip install PyPDF2)"
109
 
110
- def _process_word(self, file_path: str) -> str:
111
  """Process Word documents"""
112
  try:
113
  from docx import Document
@@ -116,7 +116,7 @@ class BasicAgent:
116
  except ImportError:
117
  return "Word processing requires python-docx (pip install python-docx)"
118
 
119
- def process_request(self, request: Union[str, Dict]) -> str:
120
  """
121
  Handle different request types:
122
  - Direct text queries
 
31
 
32
  print("BasicAgent initialized.")
33
 
34
+ def __call__(self, question: str) -> str:
35
  print(f"Agent received question (first 50 chars): {question[:50]}...")
36
  fixed_answer = self.agent.process_request(question)
37
  print(f"Agent returning answer: {fixed_answer}")
 
39
 
40
 
41
 
42
+ def generate_response(self, prompt: str) -> str:
43
  """Get response from Gemini"""
44
  try:
45
  response = self.model.generate_content(prompt)
 
47
  except Exception as e:
48
  return f"Error generating response: {str(e)}"
49
 
50
+ def web_search(self, query: str) -> List[Dict]:
51
  """Use SearxNG meta-search engine"""
52
  params = {
53
  "q": query,
 
61
  except requests.RequestException:
62
  return []
63
 
64
+ def wikipedia_search(self, query: str) -> str:
65
  """Get Wikipedia summary"""
66
  page = self.wiki.page(query)
67
  return page.summary if page.exists() else "No Wikipedia page found"
68
 
69
+ def process_document(self, file_path: str) -> str:
70
  """Handle PDF, Word, CSV, Excel files"""
71
  if not os.path.exists(file_path):
72
  return "File not found"
 
87
  except Exception as e:
88
  return f"Error processing document: {str(e)}"
89
 
90
+ def _process_pdf(self, file_path: str) -> str:
91
  """Process PDF using Gemini's vision capability"""
92
  try:
93
  # For Gemini 1.5 or later which supports file uploads
 
107
  except ImportError:
108
  return "PDF processing requires PyPDF2 (pip install PyPDF2)"
109
 
110
+ def _process_word(self, file_path: str) -> str:
111
  """Process Word documents"""
112
  try:
113
  from docx import Document
 
116
  except ImportError:
117
  return "Word processing requires python-docx (pip install python-docx)"
118
 
119
+ def process_request(self, request: Union[str, Dict]) -> str:
120
  """
121
  Handle different request types:
122
  - Direct text queries