Spaces:
Sleeping
Sleeping
File size: 2,734 Bytes
75788a5 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 | """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()
|