MohammedNasser commited on
Commit
4132a28
·
verified ·
1 Parent(s): e24a1f1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +42 -19
app.py CHANGED
@@ -11,26 +11,49 @@ from langchain.memory import ConversationBufferMemory
11
  from langchain.chains import ConversationalRetrievalChain
12
  from gtts import gTTS
13
  import sys
14
-
15
- try:
16
- import pytesseract
17
- from pdf2image import convert_from_path
18
- except ImportError as e:
19
- print(f"Error: {e}. Please make sure all system dependencies are installed.")
20
- sys.exit(1)
21
-
22
- # Rest of your imports...
23
-
24
- # Set the Tesseract path
25
- pytesseract.pytesseract.tesseract_cmd = '/usr/bin/tesseract'
26
-
27
- # Test Tesseract installation
28
- try:
29
- pytesseract.get_languages()
30
- except pytesseract.TesseractNotFoundError:
31
- print("Error: Tesseract is not installed or not in the system PATH.")
32
- sys.exit(1)
 
 
 
 
 
33
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34
  # Load environment variables
35
  load_dotenv()
36
  secret_key = os.getenv("GROQ_API_KEY")
 
11
  from langchain.chains import ConversationalRetrievalChain
12
  from gtts import gTTS
13
  import sys
14
+ import pytesseract
15
+ from pdf2image import convert_from_path
16
+
17
+ def check_installation(command):
18
+ try:
19
+ result = subprocess.run([command, '--version'], capture_output=True, text=True)
20
+ return result.returncode == 0, result.stdout
21
+ except FileNotFoundError:
22
+ return False, f"{command} not found"
23
+
24
+ def check_dependencies():
25
+ dependencies = {
26
+ 'tesseract': '/usr/bin/tesseract',
27
+ 'pdftoppm': '/usr/bin/pdftoppm', # Part of poppler-utils
28
+ }
29
+
30
+ status = {}
31
+ for dep, path in dependencies.items():
32
+ installed, version = check_installation(path)
33
+ status[dep] = {
34
+ 'installed': installed,
35
+ 'path': path,
36
+ 'version': version if installed else 'Not found'
37
+ }
38
 
39
+ return status
40
+
41
+ def log_dependency_status(status):
42
+ print("Dependency Status:")
43
+ for dep, info in status.items():
44
+ print(f"{dep}:")
45
+ print(f" Installed: {info['installed']}")
46
+ print(f" Path: {info['path']}")
47
+ print(f" Version: {info['version']}")
48
+ print("\nEnvironment Variables:")
49
+ for key, value in os.environ.items():
50
+ if 'PATH' in key or 'PYTHONPATH' in key:
51
+ print(f"{key}: {value}")
52
+
53
+ # Run dependency check
54
+ dependency_status = check_dependencies()
55
+ log_dependency_status(dependency_status)
56
+
57
  # Load environment variables
58
  load_dotenv()
59
  secret_key = os.getenv("GROQ_API_KEY")