Spaces:
Build error

Gajanand1's picture
Create setup.py
d6d168e verified
Raw History Blame Contribute Delete
4.24 kB
#!/usr/bin/env python3
import subprocess
import sys
import os
def install_requirements():
"""Install all required packages"""
print("Installing core requirements...")
# Core requirements (no conflicts)
core_packages = [
'SpeechRecognition==3.10.0',
'gTTS==2.4.0',
'pyttsx3==2.90',
'pydub==0.25.1',
'numpy==1.24.3',
'langdetect==1.0.9',
'playsound==1.2.2',
'requests==2.31.0',
]
for package in core_packages:
print(f"Installing {package}...")
subprocess.check_call([sys.executable, '-m', 'pip', 'install', package])
# Try to install googletrans (might have issues on some systems)
print("\nTrying to install googletrans...")
try:
subprocess.check_call([sys.executable, '-m', 'pip', 'install', 'googletrans==3.0.0'])
except:
print("Note: googletrans installation failed. Using alternative translation methods.")
# Streamlit packages
print("\nInstalling Streamlit packages...")
streamlit_packages = [
'streamlit==1.28.0',
'streamlit-audio-recorder==0.0.2',
]
for package in streamlit_packages:
subprocess.check_call([sys.executable, '-m', 'pip', 'install', package])
# Platform-specific installations
print("\nInstalling platform-specific packages...")
if sys.platform.startswith('linux'):
try:
subprocess.run(['sudo', 'apt-get', 'update'], check=True)
subprocess.run(['sudo', 'apt-get', 'install', '-y',
'portaudio19-dev', 'python3-pyaudio', 'ffmpeg'],
check=True)
except:
print("Note: Some Linux packages may need manual installation")
print("Run: sudo apt-get install portaudio19-dev python3-pyaudio ffmpeg")
elif sys.platform == 'darwin':
try:
subprocess.run(['brew', 'install', 'portaudio', 'ffmpeg'], check=True)
except:
print("Note: Install portaudio and ffmpeg using: brew install portaudio ffmpeg")
elif sys.platform == 'win32':
print("For Windows, please manually install:")
print("1. Microsoft Visual C++ Redistributable")
print("2. FFmpeg from ffmpeg.org")
# Try to install pyaudio (may need manual installation)
print("\nTrying to install pyaudio...")
try:
subprocess.check_call([sys.executable, '-m', 'pip', 'install', 'pyaudio'])
except:
print("Note: pyaudio may need manual installation:")
print("Linux: sudo apt-get install python3-pyaudio")
print("Mac: brew install portaudio && pip install pyaudio")
print("Windows: Download from https://www.lfd.uci.edu/~gohlke/pythonlibs/#pyaudio")
def check_installation():
"""Check if installation was successful"""
print("\n" + "="*50)
print("Checking installation...")
packages_to_check = [
('speech_recognition', 'SpeechRecognition'),
('gtts', 'gTTS'),
('pyttsx3', 'pyttsx3'),
('streamlit', 'streamlit'),
]
all_ok = True
for import_name, package_name in packages_to_check:
try:
__import__(import_name)
print(f"✓ {package_name}")
except ImportError:
print(f"✗ {package_name} - Not installed")
all_ok = False
return all_ok
def main():
print("Setting up Voice Translation Agent...")
print("=" * 50)
install_requirements()
if check_installation():
print("\n" + "="*50)
print("Setup completed successfully! 🎉")
else:
print("\n" + "="*50)
print("Some packages failed to install. Please install them manually.")
print("\nQuick Start Guide:")
print("1. Run the console app: python voice_translation_agent.py")
print("2. Run the web app: streamlit run app.py")
print("\nTroubleshooting:")
print("- If microphone doesn't work, check system permissions")
print("- On Windows, install pyaudio from: https://www.lfd.uci.edu/~gohlke/pythonlibs/#pyaudio")
print("- For translation issues, ensure you have internet connection")
if __name__ == "__main__":
main()