-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup_hybrid_model.py
More file actions
68 lines (56 loc) · 1.87 KB
/
Copy pathsetup_hybrid_model.py
File metadata and controls
68 lines (56 loc) · 1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import os
import subprocess
import sys
from pathlib import Path
def install_requirements():
packages = [
"torch",
"torchvision",
"torchaudio",
"transformers",
"streamlit",
"google-cloud-vision",
"Pillow",
"opencv-python",
"numpy",
"pandas",
"python-dotenv",
"scikit-learn"
]
for package in packages:
print(f"Installing {package}...")
subprocess.check_call([sys.executable, "-m", "pip", "install", package])
def create_directories():
directories = [
"data/medical_images",
"data/annotations",
"medical-ocr-model"
]
for directory in directories:
Path(directory).mkdir(parents=True, exist_ok=True)
print(f"Created directory: {directory}")
def setup_pretrained_model():
try:
from transformers import TrOCRProcessor, VisionEncoderDecoderModel
print("Downloading base TrOCR model...")
processor = TrOCRProcessor.from_pretrained("microsoft/trocr-base-handwritten")
model = VisionEncoderDecoderModel.from_pretrained("microsoft/trocr-base-handwritten")
processor.save_pretrained("./medical-ocr-model")
model.save_pretrained("./medical-ocr-model")
print("Base model saved to medical-ocr-model/")
except Exception as e:
print(f"Error downloading model: {e}")
def main():
print("Setting up Medical Prescription OCR System...")
print("=" * 50)
create_directories()
install_requirements()
setup_pretrained_model()
print("\n" + "=" * 50)
print("Setup completed successfully!")
print("\nNext steps:")
print("1. Run: python data_preparation.py")
print("2. Configure Google Cloud credentials in .env file")
print("3. Run: streamlit run app.py")
if __name__ == "__main__":
main()