File size: 4,820 Bytes
8a8a771
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
"""

Setup script for the Wellness Platform



Run this script to initialize the system:

1. Install dependencies

2. Set up MongoDB

3. Pull Ollama models

4. Initialize database collections

"""

import subprocess
import sys
import os
import json
from pymongo import MongoClient

def install_requirements():
    """Install Python dependencies"""
    print("πŸ“¦ Installing Python dependencies...")
    subprocess.check_call([sys.executable, "-m", "pip", "install", "-r", "requirements.txt"])
    print("βœ… Dependencies installed successfully!")

def setup_mongodb():
    """Set up MongoDB connection and collections"""
    print("πŸƒ Setting up MongoDB...")
    try:
        client = MongoClient("mongodb://localhost:27017/")
        db = client["wellness_platform"]
        
        # Create collections
        collections = ["users", "activity_logs", "suggestions", "rewards"]
        for collection in collections:
            if collection not in db.list_collection_names():
                db.create_collection(collection)
                print(f"βœ… Created collection: {collection}")
        
        print("βœ… MongoDB setup complete!")
        return True
    except Exception as e:
        print(f"❌ MongoDB setup failed: {e}")
        return False

def setup_ollama():
    """Pull required Ollama models"""
    print("πŸ¦™ Setting up Ollama models...")
    try:
        # Check if Ollama is running
        result = subprocess.run(["ollama", "list"], capture_output=True, text=True)
        if result.returncode != 0:
            print("❌ Ollama is not running. Please start Ollama first.")
            return False
        
        # Pull granite model
        print("πŸ“₯ Pulling granite-code model...")
        subprocess.run(["ollama", "pull", "granite-code"], check=True)
        print("βœ… Granite model ready!")
        return True
    except subprocess.CalledProcessError as e:
        print(f"❌ Ollama setup failed: {e}")
        return False
    except FileNotFoundError:
        print("❌ Ollama not found. Please install Ollama first.")
        return False

def create_env_file():
    """Create .env file with default configuration"""
    print("πŸ“ Creating environment configuration...")
    env_content = """

# MongoDB Configuration

MONGODB_URI=mongodb://localhost:27017/



# API Keys (update with your actual keys)

GROQ_API_KEY=your_groq_api_key_here



# Ollama Configuration

OLLAMA_BASE_URL=http://localhost:11434/api/generate

"""
    
    if not os.path.exists(".env"):
        with open(".env", "w") as f:
            f.write(env_content.strip())
        print("βœ… Created .env file")
    else:
        print("ℹ️ .env file already exists")

def create_sample_user():
    """Create a sample user profile"""
    print("πŸ‘€ Creating sample user profile...")
    sample_profile = {
        "user_id": "demo_user",
        "Age": 30,
        "Gender": "Male",
        "Occupation": "Engineering",
        "Country": "USA",
        "Consultation_History": "No",
        "Stress_Level": "Medium",
        "Sleep_Hours": 7.5,
        "Work_Hours": 40,
        "Physical_Activity_Hours": 3.0,
        "Social_Media_Usage": 2.0,
        "Diet_Quality": "Average",
        "Smoking_Habit": "Non-Smoker",
        "Alcohol_Consumption": "Social Drinker",
        "Medication_Usage": "No",
        "coins": 50,
        "total_coins_earned": 50
    }
    
    try:
        client = MongoClient("mongodb://localhost:27017/")
        db = client["wellness_platform"]
        
        # Insert sample user if doesn't exist
        if not db.users.find_one({"user_id": "demo_user"}):
            db.users.insert_one(sample_profile)
            print("βœ… Sample user created!")
        else:
            print("ℹ️ Sample user already exists")
    except Exception as e:
        print(f"❌ Failed to create sample user: {e}")

def main():
    """Main setup function"""
    print("🌟 Welcome to Wellness Platform Setup!")
    print("=" * 50)
    
    # Install dependencies
    install_requirements()
    print()
    
    # Create environment file
    create_env_file()
    print()
    
    # Setup MongoDB
    if setup_mongodb():
        create_sample_user()
    print()
    
    # Setup Ollama
    setup_ollama()
    print()
    
    print("πŸŽ‰ Setup Complete!")
    print("=" * 50)
    print("Next steps:")
    print("1. Update your GROQ_API_KEY in the .env file")
    print("2. Make sure MongoDB is running (mongod)")
    print("3. Make sure Ollama is running (ollama serve)")
    print("4. Run the application: streamlit run main_app.py")
    print()
    print("πŸš€ Happy wellness tracking!")

if __name__ == "__main__":
    main()