Madiharehan commited on
Commit
669e9dd
·
verified ·
1 Parent(s): 6a73b14

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -10
app.py CHANGED
@@ -1,15 +1,34 @@
1
- # Import necessary libraries
2
  import os
 
3
 
4
- # Ensure required libraries are installed
5
- try:
6
- import whisper
7
- import gtts
8
- import gradio as gr
9
- from groq import Groq
10
- except ImportError:
11
- print("Required libraries not found. Please install them.")
12
- exit(1) # Exit the script if the libraries are not found
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
 
14
  # Load Whisper model
15
  model = whisper.load_model("base")
@@ -79,3 +98,4 @@ iface = gr.Interface(
79
 
80
  # Launch the interface
81
  iface.launch()
 
 
 
1
  import os
2
+ import sys
3
 
4
+ # Function to check and install required libraries
5
+ def install_libraries():
6
+ try:
7
+ import whisper
8
+ import gtts
9
+ import gradio as gr
10
+ from groq import Groq
11
+ except ImportError:
12
+ print("Required libraries not found. Installing now...")
13
+ os.system("pip install git+https://github.com/openai/whisper.git gtts gradio groq")
14
+ # Try to import again after installation
15
+ try:
16
+ import whisper
17
+ import gtts
18
+ import gradio as gr
19
+ from groq import Groq
20
+ except ImportError:
21
+ print("Failed to install required libraries. Please install them manually.")
22
+ sys.exit(1)
23
+
24
+ # Call the install function
25
+ install_libraries()
26
+
27
+ # Now we can safely import the libraries
28
+ import whisper
29
+ import gtts
30
+ import gradio as gr
31
+ from groq import Groq
32
 
33
  # Load Whisper model
34
  model = whisper.load_model("base")
 
98
 
99
  # Launch the interface
100
  iface.launch()
101
+