-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1.py
More file actions
72 lines (60 loc) · 2.42 KB
/
1.py
File metadata and controls
72 lines (60 loc) · 2.42 KB
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
from fastapi import FastAPI, HTTPException
from pydantic import BaseModel
from typing import List, Optional
import numpy as np
import pandas as pd
from sklearn.ensemble import RandomForestClassifier
from sklearn.model_selection import train_test_split
import requests
app = FastAPI()
# In-memory data storage (to be replaced with Vultr cloud)
user_data = {}
food_availability_data = {}
# Sample Model for User Input
class UserInput(BaseModel):
age: int
weight: float
activity_level: str
health_goal: str
dietary_preferences: List[str]
location: str
# Sample User Feedback Model
class Feedback(BaseModel):
user_id: int
feedback: str
# Dummy ML Model (could be more complex)
def generate_diet_plan(user_input):
# Example of how you might generate a diet plan based on activity level
plans = {
"low": ["Plan A", "Plan B"],
"medium": ["Plan C", "Plan D"],
"high": ["Plan E", "Plan F"]
}
return plans[user_input['activity_level']]
# Add User Data and Get Diet Plan
@app.post("/generate_diet_plan/")
def create_diet_plan(user_input: UserInput):
# Save user data in memory (or store in Vultr cloud)
user_id = len(user_data) + 1
user_data[user_id] = user_input.dict()
# Get local food availability (dummy function, could use Vultr cloud storage here)
food_data = get_local_food_availability(user_input.location)
# Generate diet plan using simple ML logic (can be replaced with advanced model)
diet_plan = generate_diet_plan(user_input.dict())
return {"user_id": user_id, "diet_plan": diet_plan, "local_food": food_data}
# Example to Get Local Food Availability
def get_local_food_availability(location):
# This function could call a real-time API or use pre-stored data
# Dummy data for now
return ["Apples", "Bananas", "Carrots"] if location == "region_a" else ["Mangoes", "Papayas", "Tomatoes"]
# Feedback Endpoint
@app.post("/feedback/")
def add_feedback(feedback: Feedback):
user_id = feedback.user_id
if user_id not in user_data:
raise HTTPException(status_code=404, detail="User not found")
# Log feedback and potentially update the plan (dummy implementation)
print(f"Received feedback from User {user_id}: {feedback.feedback}")
return {"message": "Feedback received, thank you!"}
# Start the server with Uvicorn
# Command: uvicorn main:app --reload