aliceblue11 commited on
Commit
039e356
·
verified ·
1 Parent(s): fdfeff7

test_dependencies.py

Browse files
Files changed (1) hide show
  1. test_dependencies.py +0 -170
test_dependencies.py DELETED
@@ -1,170 +0,0 @@
1
- #!/usr/bin/env python3
2
- # -*- coding: utf-8 -*-
3
- """
4
- 의존성 모듈 테스트 스크립트
5
- app.py 실행 전에 모든 필요한 모듈이 설치되어 있는지 확인
6
- """
7
-
8
- import sys
9
- import subprocess
10
-
11
- def check_python_version():
12
- """Python 버전 확인"""
13
- version = sys.version_info
14
- print(f"Python 버전: {version.major}.{version.minor}.{version.micro}")
15
-
16
- if version.major < 3 or (version.major == 3 and version.minor < 8):
17
- print("❌ Python 3.8 이상이 필요합니다.")
18
- return False
19
- else:
20
- print("✅ Python 버전이 적절합니다.")
21
- return True
22
-
23
- def test_module_import(module_name, import_statement, install_command):
24
- """모듈 import 테스트"""
25
- try:
26
- exec(import_statement)
27
- print(f"✅ {module_name} 모듈 정상")
28
- return True
29
- except ImportError as e:
30
- print(f"❌ {module_name} 모듈 누락: {e}")
31
- print(f" 설치 명령어: {install_command}")
32
- return False
33
- except Exception as e:
34
- print(f"❌ {module_name} 모듈 오류: {e}")
35
- return False
36
-
37
- def install_requirements():
38
- """requirements.txt 설치"""
39
- try:
40
- print("\n📦 필요한 패키지를 설치합니다...")
41
- subprocess.check_call([sys.executable, "-m", "pip", "install", "-r", "requirements.txt"])
42
- print("✅ 패키지 설치 완료")
43
- return True
44
- except subprocess.CalledProcessError as e:
45
- print(f"❌ 패키지 설치 실패: {e}")
46
- return False
47
- except FileNotFoundError:
48
- print("❌ requirements.txt 파일을 찾을 수 없습니다.")
49
- return False
50
-
51
- def install_individual_packages():
52
- """개별 패키지 설치"""
53
- packages = [
54
- "gradio==4.44.0",
55
- "Pillow==10.4.0",
56
- "requests==2.32.3"
57
- ]
58
-
59
- try:
60
- print("\n📦 개별 패키지를 설치합니다...")
61
- for package in packages:
62
- print(f"설치 중: {package}")
63
- subprocess.check_call([sys.executable, "-m", "pip", "install", package])
64
- print("✅ 모든 패키지 설치 완료")
65
- return True
66
- except subprocess.CalledProcessError as e:
67
- print(f"❌ 패키지 설치 실패: {e}")
68
- return False
69
-
70
- def main():
71
- """메인 테스트 함수"""
72
- print("🔍 한국어 OCR 앱 의존성 검사를 시작합니다...\n")
73
-
74
- # Python 버전 확인
75
- if not check_python_version():
76
- return False
77
-
78
- print("\n📋 필수 모듈 확인:")
79
-
80
- # 필수 모듈 목록
81
- modules_to_test = [
82
- ("Gradio", "import gradio as gr", "pip install gradio==4.44.0"),
83
- ("Pillow", "from PIL import Image", "pip install Pillow==10.4.0"),
84
- ("Requests", "import requests", "pip install requests==2.32.3"),
85
- ("JSON", "import json", "기본 라이브러리"),
86
- ("Base64", "import base64", "기본 라이브러리"),
87
- ("IO", "import io", "기본 라이브러리"),
88
- ("OS", "import os", "기본 라이브러리"),
89
- ("Time", "import time", "기본 라이브러리"),
90
- ("Random", "import random", "기본 라이브러리"),
91
- ("RE", "import re", "기본 라이브러리"),
92
- ("Typing", "from typing import Optional, Tuple", "기본 라이브러리")
93
- ]
94
-
95
- failed_modules = []
96
-
97
- # 각 모듈 테스트
98
- for module_name, import_stmt, install_cmd in modules_to_test:
99
- if not test_module_import(module_name, import_stmt, install_cmd):
100
- if "기본 라이브러리" not in install_cmd:
101
- failed_modules.append((module_name, install_cmd))
102
-
103
- # 결과 출력
104
- if failed_modules:
105
- print(f"\n❌ {len(failed_modules)}개의 모듈이 누락되었습니다:")
106
- for module_name, install_cmd in failed_modules:
107
- print(f" • {module_name}: {install_cmd}")
108
-
109
- # 자동 설치 시도
110
- print("\n설치 방법을 선택하세요:")
111
- print("1. requirements.txt 사용 (권장)")
112
- print("2. 개별 패키지 설치")
113
- print("3. 수동 설치")
114
-
115
- try:
116
- choice = input("선택 (1/2/3): ").strip()
117
-
118
- if choice == "1":
119
- if install_requirements():
120
- print("\n🔄 설치 후 다시 테스트합니다...")
121
- return main() # 재귀 호출로 재테스트
122
- else:
123
- return False
124
- elif choice == "2":
125
- if install_individual_packages():
126
- print("\n🔄 설치 후 다시 테스트합니다...")
127
- return main() # 재귀 호출로 재테스트
128
- else:
129
- return False
130
- else:
131
- print("\n수동 설치 명령어:")
132
- print("pip install gradio==4.44.0 Pillow==10.4.0 requests==2.32.3")
133
- print("설치 후 다시 실행해주세요.")
134
- return False
135
-
136
- except KeyboardInterrupt:
137
- print("\n\n사용자가 취소했습니다.")
138
- return False
139
- else:
140
- print("\n🎉 모든 의존성이 정상적으로 설치되어 있습니다!")
141
- print("이제 app.py를 실행할 수 있습니다.")
142
-
143
- # Gradio 버전 확인
144
- try:
145
- import gradio as gr
146
- print(f"✅ Gradio 버전: {gr.__version__}")
147
- except:
148
- pass
149
-
150
- # 추가 정보 출력
151
- print("\n📌 실행 방법:")
152
- print("python app.py")
153
- print("\n🌐 브라우저에서 자동으로 열립니다 (http://localhost:7860)")
154
-
155
- return True
156
-
157
- if __name__ == "__main__":
158
- try:
159
- if main():
160
- print("\n✅ 테스트 완료 - app.py를 실행해주세요!")
161
- sys.exit(0)
162
- else:
163
- print("\n❌ 테스트 실패 - 문제를 해결한 후 다시 시도해주세요.")
164
- sys.exit(1)
165
- except KeyboardInterrupt:
166
- print("\n\n프로그램이 사용자에 의해 중단되었습니다.")
167
- sys.exit(1)
168
- except Exception as e:
169
- print(f"\n❌ 예상치 못한 오류 발생: {e}")
170
- sys.exit(1)