Yago Bolivar commited on
Commit
073b7fb
Β·
1 Parent(s): db8c127
{data/docs β†’ docs}/API.md RENAMED
File without changes
{data/docs β†’ docs}/GETTING_STARTED.md RENAMED
File without changes
{data/docs β†’ docs}/LOCAL_TESTING.md RENAMED
File without changes
{data/docs β†’ docs}/NEXT_STEPS.md RENAMED
File without changes
{data/docs β†’ docs}/devplan.md RENAMED
File without changes
docs/downloaded_files.md ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Downloaded files
2
+
3
+ Agent's requirements for the downloaded files:
4
+
5
+ - **Detect the file type** based on the extension and the linked question (referenced in `common_questions.py`).
6
+ - **Audio Files (.mp3):**
7
+ Use speech-to-text routines to transcribe the audio and then extract the required answer (e.g. page numbers or ingredient lists) with proper post‑processing (sorting, deduplication).
8
+ - **Spreadsheet Files (.xlsx):**
9
+ Parse the Excel file (using tools like pandas) to extract the numeric sales data, summing up relevant columns and formatting the number as specified.
10
+ - **Image Files (.png):**
11
+ Apply OCR or vision reasoning to interpret the chess position (or extract text details) so that the agent can compute the correct algebraic move.
12
+ - **Python Code Files (.py):**
13
+ Safely execute the code snippet in a sandboxed environment to capture its output (the final numeric value).
14
+
15
+ In short, the agent must determine which specialized tool (speech-to-text, spreadsheet reader, OCR/vision, or code interpreter) to invoke for each file type and then synthesize the outputs, ensuring that the final answers meet the exact-match formatting specified in the submission instructions (submission_instructions.md).
{data/docs β†’ docs}/log.md RENAMED
File without changes
{data/docs β†’ docs}/project_overview.md RENAMED
File without changes
{data/docs β†’ docs}/submission_instructions.md RENAMED
File without changes
{data/docs β†’ docs}/testing_recipe.md RENAMED
File without changes
src/file_processing_tool.py ADDED
@@ -0,0 +1,124 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import mimetypes # For a more robust way to guess types
3
+
4
+ class FileIdentifier:
5
+ def __init__(self):
6
+ # Initialize mimetypes database
7
+ mimetypes.init()
8
+ self.file_type_actions = {
9
+ "audio": "speech-to-text",
10
+ "spreadsheet": "spreadsheet_parser",
11
+ "image": "ocr_vision_reasoning",
12
+ "python_code": "safe_code_interpreter",
13
+ "pdf": "pdf_text_extractor",
14
+ "text": "text_file_reader",
15
+ "csv": "csv_parser",
16
+ # Add more mappings as needed
17
+ }
18
+
19
+ def identify_file(self, filepath):
20
+ """
21
+ Identifies the file type and suggests a processing action.
22
+ Returns a dictionary with 'file_type', 'mime_type', and 'suggested_action'.
23
+ """
24
+ if not os.path.exists(filepath):
25
+ return {
26
+ "error": "File not found",
27
+ "filepath": filepath
28
+ }
29
+ if not os.path.isfile(filepath):
30
+ return {
31
+ "error": "Path is not a file",
32
+ "filepath": filepath
33
+ }
34
+
35
+ _, extension = os.path.splitext(filepath)
36
+ extension = extension.lower()
37
+
38
+ # Primary detection by extension (as per downloaded_files.md)
39
+ file_type = "unknown"
40
+ if extension == ".mp3":
41
+ file_type = "audio"
42
+ elif extension == ".xlsx":
43
+ file_type = "spreadsheet"
44
+ elif extension == ".png": # Assuming .png for images as per downloaded_files.md
45
+ file_type = "image"
46
+ elif extension == ".py":
47
+ file_type = "python_code"
48
+ elif extension == ".pdf":
49
+ file_type = "pdf"
50
+ elif extension == ".txt":
51
+ file_type = "text"
52
+ elif extension == ".csv":
53
+ file_type = "csv"
54
+
55
+ # Fallback or complementary check using MIME types
56
+ mime_type, _ = mimetypes.guess_type(filepath)
57
+
58
+ # If extension-based detection was unknown, try to infer from MIME type
59
+ if file_type == "unknown" and mime_type:
60
+ if mime_type.startswith("audio/"):
61
+ file_type = "audio"
62
+ elif mime_type in ["application/vnd.ms-excel", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"]:
63
+ file_type = "spreadsheet"
64
+ elif mime_type.startswith("image/"):
65
+ file_type = "image"
66
+ elif mime_type in ["text/x-python", "application/x-python-code"]:
67
+ file_type = "python_code"
68
+ elif mime_type == "application/pdf":
69
+ file_type = "pdf"
70
+ elif mime_type.startswith("text/plain"):
71
+ file_type = "text"
72
+ elif mime_type == "text/csv":
73
+ file_type = "csv"
74
+
75
+
76
+ suggested_action = self.file_type_actions.get(file_type, "manual_inspection_required")
77
+
78
+ return {
79
+ "filepath": filepath,
80
+ "extension": extension,
81
+ "mime_type": mime_type,
82
+ "determined_type": file_type,
83
+ "suggested_action": suggested_action
84
+ }
85
+
86
+ # Example Usage:
87
+ if __name__ == "__main__":
88
+ identifier = FileIdentifier()
89
+
90
+ # Create dummy files for testing
91
+ dummy_files_dir = "dummy_files_for_test"
92
+ os.makedirs(dummy_files_dir, exist_ok=True)
93
+ test_files_info = {
94
+ "audio_sample.mp3": "audio content",
95
+ "report_data.xlsx": "excel content",
96
+ "diagram.png": "image content",
97
+ "analysis_script.py": "print('hello')",
98
+ "document.pdf": "pdf content",
99
+ "notes.txt": "text content",
100
+ "data.csv": "col1,col2\n1,2",
101
+ "unknown_file.zip": "zip content"
102
+ }
103
+ for filename, content in test_files_info.items():
104
+ with open(os.path.join(dummy_files_dir, filename), "w") as f:
105
+ # For binary files, this is not ideal, but for testing identification it's okay
106
+ # Real .xlsx, .png, .mp3, .pdf would be binary
107
+ if filename.endswith(('.xlsx', '.png', '.mp3', '.pdf', '.zip')):
108
+ with open(os.path.join(dummy_files_dir, filename), "wb") as fb: # Ensure binary files are writable
109
+ fb.write(b"dummy binary content") # placeholder
110
+ else:
111
+ f.write(content)
112
+
113
+
114
+ test_filepaths = [os.path.join(dummy_files_dir, f) for f in test_files_info.keys()]
115
+ test_filepaths.append("non_existent_file.doc") # Test non-existent file
116
+
117
+ for filepath in test_filepaths:
118
+ result = identifier.identify_file(filepath)
119
+ print(result)
120
+
121
+ # Clean up dummy files
122
+ # import shutil
123
+ # shutil.rmtree(dummy_files_dir)
124
+ print(f"\nNote: Dummy files created in '{dummy_files_dir}'. You may want to remove this directory.")