Spaces:
Sleeping
Sleeping
| """Setup script for first-time configuration.""" | |
| import os | |
| import sys | |
| def create_env_file(): | |
| """Create .env file from template if it doesn't exist.""" | |
| if os.path.exists('.env'): | |
| print("β .env file already exists") | |
| return | |
| if not os.path.exists('.env.example'): | |
| print("β .env.example not found") | |
| return | |
| print("π Creating .env file from template...") | |
| with open('.env.example', 'r') as f: | |
| content = f.read() | |
| print("\nπ Please provide your API keys:") | |
| gemini_key = input("Gemini API Key (required): ").strip() | |
| serpapi_key = input("SerpApi Key (required): ").strip() | |
| if not gemini_key or not serpapi_key: | |
| print("β Both API keys are required!") | |
| sys.exit(1) | |
| content = content.replace('your_gemini_api_key_here', gemini_key) | |
| content = content.replace('your_serpapi_key_here', serpapi_key) | |
| telegram_token = input("Telegram Bot Token (optional, press Enter to skip): ").strip() | |
| if telegram_token: | |
| content = content.replace('your_telegram_bot_token_here', telegram_token) | |
| with open('.env', 'w') as f: | |
| f.write(content) | |
| print("β .env file created successfully!") | |
| def check_dependencies(): | |
| """Check if all dependencies are installed.""" | |
| print("\nπ¦ Checking dependencies...") | |
| try: | |
| import fastapi | |
| import uvicorn | |
| import gradio | |
| import langchain | |
| import google.generativeai | |
| print("β All core dependencies installed") | |
| except ImportError as e: | |
| print(f"β Missing dependency: {e}") | |
| print("Run: pip install -r requirements.txt") | |
| sys.exit(1) | |
| def initialize_database(): | |
| """Initialize the SQLite database.""" | |
| print("\nποΈ Initializing database...") | |
| try: | |
| sys.path.append('..') | |
| from database import db | |
| db.init_db() | |
| print("β Database initialized successfully!") | |
| except Exception as e: | |
| print(f"β Database initialization failed: {e}") | |
| sys.exit(1) | |
| def main(): | |
| """Run setup.""" | |
| print("="*60) | |
| print("π Rural E-commerce Suggestion Bot - Setup") | |
| print("="*60 + "\n") | |
| create_env_file() | |
| check_dependencies() | |
| initialize_database() | |
| print("\n" + "="*60) | |
| print("β¨ Setup completed successfully!") | |
| print("="*60) | |
| print("\nπ Next steps:") | |
| print("1. Review your .env file") | |
| print("2. Run: python main.py --mode all") | |
| print("3. Open: http://localhost:7860 (Gradio UI)") | |
| print("4. Check API docs: http://localhost:8000/docs") | |
| print("\nπ Happy coding!\n") | |
| if __name__ == "__main__": | |
| main() | |