Cie1 commited on
Commit
0423186
·
verified ·
1 Parent(s): 49a3557

Remove old mmsearch_plus.py file

Browse files
Files changed (1) hide show
  1. mmsearch_plus.py +0 -189
mmsearch_plus.py DELETED
@@ -1,189 +0,0 @@
1
- """MMSearch-Plus dataset with transparent decryption."""
2
-
3
- import base64
4
- import hashlib
5
- import io
6
- import os
7
- from typing import Dict, Any, List
8
- import datasets
9
- from PIL import Image
10
-
11
- _CITATION = """\
12
- @article{tao2025mmsearch,
13
- title={MMSearch-Plus: A Simple Yet Challenging Benchmark for Multimodal Browsing Agents},
14
- author={Tao, Xijia and Teng, Yihua and Su, Xinxing and Fu, Xinyu and Wu, Jihao and Tao, Chaofan and Liu, Ziru and Bai, Haoli and Liu, Rui and Kong, Lingpeng},
15
- journal={arXiv preprint arXiv:2508.21475},
16
- year={2025}
17
- }
18
- """
19
-
20
- _DESCRIPTION = """\
21
- MMSearch-Plus is a challenging benchmark designed to test multimodal browsing agents' ability to perform genuine visual reasoning.
22
- Unlike existing benchmarks where many tasks can be solved with text-only approaches, MMSearch-Plus requires models to extract
23
- and use fine-grained visual cues through iterative image-text retrieval.
24
- """
25
-
26
- _HOMEPAGE = "https://mmsearch-plus.github.io/"
27
-
28
- _LICENSE = "CC BY-NC 4.0"
29
-
30
- _URLS = {
31
- "train": [
32
- "data-00000-of-00002.arrow",
33
- "data-00001-of-00002.arrow"
34
- ]
35
- }
36
-
37
- def derive_key(password: str, length: int) -> bytes:
38
- """Derive encryption key from password using SHA-256."""
39
- hasher = hashlib.sha256()
40
- hasher.update(password.encode())
41
- key = hasher.digest()
42
- return key * (length // len(key)) + key[: length % len(key)]
43
-
44
- def decrypt_image(ciphertext_b64: str, password: str) -> Image.Image:
45
- """Decrypt base64-encoded encrypted image bytes back to PIL Image."""
46
- if not ciphertext_b64:
47
- return None
48
-
49
- try:
50
- encrypted = base64.b64decode(ciphertext_b64)
51
- key = derive_key(password, len(encrypted))
52
- decrypted = bytes([a ^ b for a, b in zip(encrypted, key)])
53
-
54
- # Convert bytes back to PIL Image
55
- img_buffer = io.BytesIO(decrypted)
56
- image = Image.open(img_buffer)
57
- return image
58
- except Exception:
59
- return None
60
-
61
- def decrypt_text(ciphertext_b64: str, password: str) -> str:
62
- """Decrypt base64-encoded ciphertext using XOR cipher with derived key."""
63
- if not ciphertext_b64:
64
- return ciphertext_b64
65
-
66
- try:
67
- encrypted = base64.b64decode(ciphertext_b64)
68
- key = derive_key(password, len(encrypted))
69
- decrypted = bytes([a ^ b for a, b in zip(encrypted, key)])
70
- return decrypted.decode('utf-8')
71
- except Exception:
72
- return ciphertext_b64
73
-
74
- class MmsearchPlus(datasets.GeneratorBasedBuilder):
75
- """MMSearch-Plus dataset with transparent decryption."""
76
-
77
- VERSION = datasets.Version("1.0.0")
78
-
79
- def _info(self):
80
- # Define features to handle the complete dataset schema
81
- features = datasets.Features({
82
- "question": datasets.Value("string"),
83
- "answer": datasets.Sequence(datasets.Value("string")),
84
- "num_images": datasets.Value("int64"),
85
- "arxiv_id": datasets.Value("string"),
86
- "video_url": datasets.Value("string"),
87
- "category": datasets.Value("string"),
88
- "difficulty": datasets.Value("string"),
89
- "subtask": datasets.Value("string"),
90
- # Image fields (not encrypted, kept as PIL Images)
91
- "img_1": datasets.Image(),
92
- "img_2": datasets.Image(),
93
- "img_3": datasets.Image(),
94
- "img_4": datasets.Image(),
95
- "img_5": datasets.Image(),
96
- # Additional fields that might exist in the dataset
97
- "choices": datasets.Sequence(datasets.Value("string")),
98
- "question_zh": datasets.Value("string"),
99
- "answer_zh": datasets.Sequence(datasets.Value("string")),
100
- "regex": datasets.Value("string"),
101
- "text_criteria": datasets.Value("string"),
102
- "original_filename": datasets.Value("string"),
103
- "screenshots_dir": datasets.Value("string"),
104
- "time_points": datasets.Sequence(datasets.Value("string")),
105
- "search_query": datasets.Value("string"),
106
- "question_type": datasets.Value("string"),
107
- "requires_image_understanding": datasets.Value("bool"),
108
- "source": datasets.Value("string"),
109
- "content_keywords": datasets.Value("string"),
110
- "reasoning": datasets.Value("string"),
111
- "processed_at": datasets.Value("string"),
112
- "model_used": datasets.Value("string"),
113
- "entry_index": datasets.Value("int64"),
114
- "original_image_paths": datasets.Sequence(datasets.Value("string")),
115
- "masked_image_paths": datasets.Sequence(datasets.Value("string")),
116
- "is_valid": datasets.Value("bool"),
117
- })
118
-
119
- return datasets.DatasetInfo(
120
- description=_DESCRIPTION,
121
- features=features,
122
- homepage=_HOMEPAGE,
123
- license=_LICENSE,
124
- citation=_CITATION,
125
- )
126
-
127
- def _split_generators(self, dl_manager):
128
- # Get canary from environment variable or kwargs
129
- canary = os.environ.get("MMSEARCH_PLUS")
130
-
131
- # Check if passed in the builder's initialization
132
- if hasattr(self, 'canary'):
133
- canary = self.canary
134
-
135
- if not canary:
136
- raise ValueError(
137
- "Canary string is required for decryption. Either set the MMSEARCH_PLUS "
138
- "environment variable or pass it via the dataset loading kwargs. "
139
- "Example: load_dataset('path/to/dataset', trust_remote_code=True) after setting "
140
- "os.environ['MMSEARCH_PLUS'] = 'your_canary_string'"
141
- )
142
-
143
- # Download files
144
- urls = _URLS["train"]
145
- downloaded_files = dl_manager.download(urls)
146
-
147
- return [
148
- datasets.SplitGenerator(
149
- name=datasets.Split.TRAIN,
150
- gen_kwargs={
151
- "filepaths": downloaded_files,
152
- "canary": canary,
153
- },
154
- ),
155
- ]
156
-
157
- def _generate_examples(self, filepaths, canary):
158
- """Generate examples with transparent decryption."""
159
- key = 0
160
-
161
- for filepath in filepaths:
162
- # Load the arrow file
163
- arrow_dataset = datasets.Dataset.from_file(filepath)
164
-
165
- for idx in range(len(arrow_dataset)):
166
- example = arrow_dataset[idx]
167
-
168
- # Decrypt text fields - matches encryption script fields
169
- text_fields = ['question', 'video_url', 'arxiv_id']
170
-
171
- for field in text_fields:
172
- if example.get(field):
173
- example[field] = decrypt_text(example[field], canary)
174
-
175
- # Handle answer field (list of strings)
176
- if example.get("answer"):
177
- decrypted_answers = []
178
- for answer in example["answer"]:
179
- if answer:
180
- decrypted_answers.append(decrypt_text(answer, canary))
181
- else:
182
- decrypted_answers.append(answer)
183
- example["answer"] = decrypted_answers
184
-
185
- # Images are not encrypted - they remain as PIL Image objects
186
- # No image decryption needed as per the encryption script
187
-
188
- yield key, example
189
- key += 1