-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.py
More file actions
120 lines (100 loc) · 3.59 KB
/
server.py
File metadata and controls
120 lines (100 loc) · 3.59 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
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
from flask import Flask, request, jsonify, json
from PIL import Image
from LLM import gemini_output, get_llm_response
# import pytesseract
app = Flask(__name__)
user_details = {}
print("out",user_details)
@app.route('/post_data', methods=['POST'])
def get_data():
global user_details
data = request.json
name_val = data['name']
age_val = data['age']
height_val = data['height']
weight_val = data['weight']
gender_val = data['gender']
supplements_val = str(data['supplements'])
activity_level_val = data['activity_level']
food_allergies_val = data['food_allergies']
eating_habits_val = data['eating_habits']
goal_val = data['goal']
water_consump_val = data['water_consump']
pregnant_val = str(data['pregnant'])
diet_plan_val = data['diet_plan']
health_problems_val = data['health_problems']
user_details = {
'name': name_val,
'age': age_val,
'height':height_val,
'weight':weight_val,
'gender':gender_val,
'activity level':activity_level_val,
'food allergies':food_allergies_val,
'eating habits':eating_habits_val,
'goal':goal_val,
'water consumption':water_consump_val,
'pregnant':pregnant_val,
'diet plans':diet_plan_val,
'health problems':health_problems_val,
'supplements consumption':supplements_val
}
print("in post",user_details)
return("success")
@app.route('/signin', methods=['POST'])
def signin():
data = request.json
email_val = data['email']
mobile_val = data['mobile']
password_val = data['password']
signin_details = {
'email':email_val,
'mobile': mobile_val,
'password':password_val
}
print(signin_details)
return("success")
@app.route('/upload-image', methods = ['POST'])
def upload_image():
global user_details
uploaded_file = request.files['file']
if uploaded_file.filename != '':
# Save the uploaded file
uploaded_file.save(uploaded_file.filename)
print("in camera",user_details)
system_prompt = """
You are a specialist in nutritional facts.
Input images in the form of wrappers of packaged good will be provided to you,
and your task is to respond with the text document of all the ingredients present in it give it in a list format.
take the nutritional facts table part and return how much quantity of the specific nutrients present in that food
"""
user_prompt = "Give me the information about it"
extracted_text = gemini_output(uploaded_file.filename,system_prompt,user_prompt)
llm_response = get_llm_response(extracted_text,user_details)
# with open('myFile.txt','w') as file:
# file.write(llm_response)
# with open('myFile.txt', 'r') as file:
# lines = file.readlines()
global llm
llm= llm_response.split("```json")[1].strip()
llm = llm.strip("`")
return "Image uploaded successfully."
else:
return "No Image received."
@app.route('/camera-image', methods = ['POST'])
def camera_image():
global user_details
uploaded_file = request.files['file']
if uploaded_file.filename != '':
# Save the uploaded file
uploaded_file.save(uploaded_file.filename)
print("in camera",user_details)
return "Image uploaded successfully."
else:
return "No Image received."
@app.route('/output', methods=['GET'])
def output():
return llm
print(user_details)
if __name__ == "__main__":
app.run(debug=True)