Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -31,7 +31,7 @@ class BasicAgent:
|
|
31 |
|
32 |
print("BasicAgent initialized.")
|
33 |
|
34 |
-
|
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 |
-
|
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 |
-
|
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 |
-
|
65 |
"""Get Wikipedia summary"""
|
66 |
page = self.wiki.page(query)
|
67 |
return page.summary if page.exists() else "No Wikipedia page found"
|
68 |
|
69 |
-
|
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 |
-
|
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 |
-
|
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 |
-
|
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
|