Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -200,7 +200,37 @@ class BasicAgent:
|
|
| 200 |
return summary
|
| 201 |
except Exception as e:
|
| 202 |
return f"Excel reading error: {str(e)}"
|
| 203 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 204 |
def process_question(self, question: str) -> str:
|
| 205 |
try:
|
| 206 |
# Processing image
|
|
@@ -214,6 +244,13 @@ class BasicAgent:
|
|
| 214 |
if excel_url_match:
|
| 215 |
return self._read_excel(excel_url_match.group(0))
|
| 216 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 217 |
# Read csv
|
| 218 |
if "calculate" in question.lower() and any(c in question for c in "+-*/"):
|
| 219 |
calculation = re.search(r'calculate\s+([\d\s\+\-\*\/\(\)\.\,\^\%]+)', question, re.IGNORECASE)
|
|
@@ -334,8 +371,7 @@ class BasicAgent:
|
|
| 334 |
|
| 335 |
|
| 336 |
prompt = f"""
|
| 337 |
-
|
| 338 |
-
|
| 339 |
|
| 340 |
You: You are a general AI assistant. I will ask you a question. YOUR FINAL ANSWER should be a number OR as few words as possible OR a comma separated list of numbers and/or strings. If you are asked for a number, don't use comma to write your number neither use units such as $ or percent sign unless specified otherwise. If you are asked for a string, don't use articles, neither abbreviations (e.g. for cities), and write the digits in plain text unless specified otherwise. If you are asked for a comma separated list, apply the above rules depending of whether the element to be put in the list is a number or a string.
|
| 341 |
Instructions:
|
|
|
|
| 200 |
return summary
|
| 201 |
except Exception as e:
|
| 202 |
return f"Excel reading error: {str(e)}"
|
| 203 |
+
|
| 204 |
+
def _read_code_file(self, file_url):
|
| 205 |
+
try:
|
| 206 |
+
response = requests.get(file_url)
|
| 207 |
+
code_content = response.text
|
| 208 |
+
|
| 209 |
+
# Determine file extension for language detection
|
| 210 |
+
file_extension = file_url.split('.')[-1].lower()
|
| 211 |
+
|
| 212 |
+
# Map common extensions to language names
|
| 213 |
+
language_map = {
|
| 214 |
+
'py': 'Python', 'js': 'JavaScript', 'html': 'HTML', 'css': 'CSS',
|
| 215 |
+
'java': 'Java', 'c': 'C', 'cpp': 'C++', 'cs': 'C#',
|
| 216 |
+
'php': 'PHP', 'rb': 'Ruby', 'go': 'Go', 'rs': 'Rust',
|
| 217 |
+
'ts': 'TypeScript', 'sh': 'Shell', 'sql': 'SQL'
|
| 218 |
+
}
|
| 219 |
+
|
| 220 |
+
language = language_map.get(file_extension, 'Unknown')
|
| 221 |
+
|
| 222 |
+
# Count lines of code
|
| 223 |
+
line_count = code_content.count('\n') + 1
|
| 224 |
+
|
| 225 |
+
# Create a summary of the code file
|
| 226 |
+
summary = f"Code file ({language}) with {line_count} lines.\n"
|
| 227 |
+
summary += f"First 10 lines:\n{'\n'.join(code_content.split('\n')[:10])}"
|
| 228 |
+
|
| 229 |
+
return summary
|
| 230 |
+
except Exception as e:
|
| 231 |
+
return f"Code file reading error: {str(e)}"
|
| 232 |
+
|
| 233 |
+
|
| 234 |
def process_question(self, question: str) -> str:
|
| 235 |
try:
|
| 236 |
# Processing image
|
|
|
|
| 244 |
if excel_url_match:
|
| 245 |
return self._read_excel(excel_url_match.group(0))
|
| 246 |
|
| 247 |
+
# Code
|
| 248 |
+
code_extensions = ['py', 'js', 'html', 'css', 'java', 'c', 'cpp', 'cs', 'php', 'rb', 'go', 'rs', 'ts', 'sh', 'sql']
|
| 249 |
+
code_pattern = '|'.join(code_extensions)
|
| 250 |
+
code_url_match = re.search(f'https?://\\S+\\.({code_pattern})', question, re.IGNORECASE)
|
| 251 |
+
if code_url_match:
|
| 252 |
+
return self._read_code_file(code_url_match.group(0))
|
| 253 |
+
|
| 254 |
# Read csv
|
| 255 |
if "calculate" in question.lower() and any(c in question for c in "+-*/"):
|
| 256 |
calculation = re.search(r'calculate\s+([\d\s\+\-\*\/\(\)\.\,\^\%]+)', question, re.IGNORECASE)
|
|
|
|
| 371 |
|
| 372 |
|
| 373 |
prompt = f"""
|
| 374 |
+
|
|
|
|
| 375 |
|
| 376 |
You: You are a general AI assistant. I will ask you a question. YOUR FINAL ANSWER should be a number OR as few words as possible OR a comma separated list of numbers and/or strings. If you are asked for a number, don't use comma to write your number neither use units such as $ or percent sign unless specified otherwise. If you are asked for a string, don't use articles, neither abbreviations (e.g. for cities), and write the digits in plain text unless specified otherwise. If you are asked for a comma separated list, apply the above rules depending of whether the element to be put in the list is a number or a string.
|
| 377 |
Instructions:
|