Files
feedmill-auto-label/scratch/refactor.py
T
asus 5c7c122105 feat: add counting bench, triage, and dataset modules
This commit includes major additions and updates to the frontend and backend architectures, introducing new dataset management, live counting features, batch processing, and triage logic. Includes new UI pages, components, and API routes.
2026-08-14 16:28:52 +07:00

70 lines
2.8 KiB
Python

import re
def main():
path = '/home/asus/reTraining/frontend/src/pages/LibraryPage.jsx'
with open(path, 'r') as f:
content = f.read()
# 1. Add import AutoAnnotateModal
if "import AutoAnnotateModal" not in content:
content = content.replace("import React,", "import AutoAnnotateModal from '../components/AutoAnnotateModal'\nimport React,")
# 2. Replace state definitions
# Replace appendModalState, sam3AppendState, customPromptInput, baseModelModalState with autoAnnotateConfig
content = re.sub(r'const \[appendModalState.*?\n', '', content)
content = re.sub(r'const \[sam3AppendState.*?\n', '', content)
content = re.sub(r'const \[customPromptInput.*?\n', '', content)
content = re.sub(r'const \[baseModelModalState.*?\n', ' const [autoAnnotateConfig, setAutoAnnotateConfig] = useState(null)\n', content)
# 3. Replace openBaseModelAutolabelModal
base_model_func = """ function openBaseModelAutolabelModal(batch) {
setAutoAnnotateConfig({ batch, project, engine: 'base_model' })
}"""
content = re.sub(r' function openBaseModelAutolabelModal.*?\}', base_model_func, content, flags=re.DOTALL)
# 4. Replace openSam3AppendModal
sam3_func = """ function openSam3AppendModal(batch) {
setAppendChoiceBatch(null)
setAutoAnnotateConfig({ batch, project, engine: 'sam3' })
}"""
content = re.sub(r' function openSam3AppendModal.*?\}', sam3_func, content, flags=re.DOTALL)
# 5. Modify openFilePickerForYolo
# We replace from "const info = await api.inspectModel(file)" to the end of the try block.
# Actually let's just replace setAppendModalState( ... )
yolo_replacement = """ setAutoAnnotateConfig({
batch,
project,
engine: 'custom',
customModelStagedPath: info.staged_path,
customModelClasses: info.classes || []
})"""
content = re.sub(r' setAppendModalState\(\{[\s\S]*?\}\)', yolo_replacement, content, flags=re.DOTALL)
# 6. Remove all 3 modals from the JSX, replace with AutoAnnotateModal
# Let's find the start of SAM3 Append Modal
sam3_idx = content.find("{/* SAM3 Append Modal */}")
if sam3_idx != -1:
# Find the end of the Fragment "</>"
end_idx = content.find(" </>\n )\n}", sam3_idx)
if end_idx != -1:
new_jsx = """ {autoAnnotateConfig && (
<AutoAnnotateModal
{...autoAnnotateConfig}
onClose={() => setAutoAnnotateConfig(null)}
onSuccess={() => {
setAutoAnnotateConfig(null)
onChanged()
}}
/>
)}
"""
content = content[:sam3_idx] + new_jsx + content[end_idx:]
with open(path, 'w') as f:
f.write(content)
if __name__ == '__main__':
main()