File size: 10,188 Bytes
8d1019d
 
 
ca06619
8d1019d
 
 
 
 
 
9944629
 
 
8d1019d
9944629
 
 
 
8d1019d
9944629
8d1019d
 
9944629
 
 
 
 
8d1019d
 
9944629
 
8d1019d
 
9944629
8d1019d
 
9944629
 
 
 
8d1019d
9944629
8d1019d
 
 
 
 
 
9944629
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8d1019d
 
9944629
8d1019d
 
 
 
 
 
 
9944629
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8d1019d
 
 
 
 
 
 
 
 
 
 
 
9944629
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8d1019d
 
9dc795c
 
8d1019d
 
 
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
from flask import Flask, jsonify, request
import os
# from "./emotion_recognition/ai_model_photo" import ai
# from emotion_recognition import ai_model_photo
# from palm_response import getResponse, init_connect
from flask_mysqldb import MySQL
import base64
import google.generativeai as genai

app = Flask(__name__)
@app.route('/',methods=['GET'])
def hello():
    return {"hello":"The deploy run"}

# app.config['MYSQL_HOST'] = 'localhost'
# app.config['MYSQL_USER'] = 'root'
# app.config['MYSQL_PASSWORD'] = ''
# app.config['MYSQL_DB'] = 'wanees_app'

# mysql = MySQL(app)


# def add_padding(base64_str):
#     missing_padding = len(base64_str) % 4
#     if missing_padding != 0:
#         base64_str += '=' * (4 - missing_padding)
#     return base64_str


# @app.route('/api/chat/gemini', methods=['POST'])
# def receive_chat():
#     try:
#         data = request.get_json()
#         prompt = data['message']
#         print(data)
#         print('promp is : ',prompt)
#         genai.configure(api_key="AIzaSyB7bKpGzkT_f32d-Xv4tb9zIBtb8vJUCCs")
#         model = genai.GenerativeModel('gemini-pro') 
#         response = model.generate_content(prompt)
#         print(response.text)
        
#         generated_text = response.text
#         print('generated_text: ',generated_text)
#         return jsonify({"response": generated_text}), 200
#     except Exception as e:
#         print('the catch is:',str(e))
#         return jsonify({"error": str(e)})

# # openai.api_key = "sk-proj-QtkCbMdxHjgMAyughGjgT3BlbkFJuoyNuhK2zO3uKm1Zc5S6"

# # @backoff.on_exception(backoff.expo, RateLimitError, max_tries=8)
# # def completions_with_backoff(client, messages):
# #     response = client.chat.completions.create(
# #         model="gpt-3.5-turbo",
# #         messages=messages,
# #         temperature=0,
# #     )
# #     return response


# # @app.route('/api/chat/gpt', methods=['POST'])
# # def receive_message():
# #     try:
# #         data = request.get_json()
# #         prompt = data.get('prompt', 'Hello')
# #         print(data)
# #         print('promp is : ',prompt)
# #         # client = OpenAI()
# #         messages = [{"role": "user", "content": prompt}]
# #         client = OpenAI(
# #         # This is the default and can be omitted
# #         api_key="sk-proj-EPQes2YgSJEx1e6EwDarT3BlbkFJrEtY36IDssJKi6VkVP7v"
# #         )
# #         #
# #         response = client.chat.completions.create(
# #         model="gpt-3.5-turbo",
# #         messages=messages,
# #         temperature=0,
# #         )
        
# #         # response = openai.Completion.create(
# #         #     engine="text-davinci-003",
# #         #     prompt=prompt,
# #         #     max_tokens=251,
# #         #     temperature=0,
# #         #     top_p=1
# #         # )
# #         print('response is: ',response.choices[0].message["content"])
        
# #         generated_text = response.choices[0].message["content"]
# #         print('generated_text: ',generated_text)
# #         return jsonify({"response": generated_text}), 200
# #     except Exception as e:
# #         print('the catch is:',str(e))
# #         return jsonify({"error": str(e)})


# @app.route('/api/photo', methods=['POST'])
# def receive_photo():
#     global photo_path
#     photo_data = request.files['photo']
#     photo_path = os.path.join('.', photo_data.filename)
#     photo_data.save(photo_path)
#     res = ai_model_photo.ai(photo_path)
#     print(photo_path)
#     return jsonify({'message': res}), 200
#     # return Response(status=200, mimetype='application/json')


# @app.route('/api/facedetect', methods=['POST'])
# def AddPhoto():
#     name = request.json['name']
#     email = request.json['email']
#     # mobile = request.json['mobile']
#     img64 = request.json['image']
#     img64_padded = add_padding(img64)
#     imageBinary = base64.b64decode(img64_padded)

#     imgdetect = request.json['imagedetect']
#     imgdetect_padded = add_padding(imgdetect)
#     imageBinarydetect = base64.b64decode(imgdetect_padded)
#     photo_path = os.path.join('.', imageBinarydetect.filename)
#     imageBinary.save(photo_path)
#     res = ai_model_photo.ai(photo_path)
#     print(photo_path)

# def receive_photo():
#     global photo_path
#     photo_data = request.files['photo']
#     photo_path = os.path.join('.', photo_data.filename)
#     photo_data.save(photo_path)
#     res = ai_model_photo.ai(photo_path)
#     print(photo_path)
    # return jsonify({'message': res}), 200


# @app.route('/api/chat/palm', methods=['POST'])
# def receive_message():
#     message ={
#        "message" : request.json['message']
#     }
#     response_palm = getResponse(message["message"])
#     print("res palm =====", response_palm)
#     return jsonify({'message': response_palm}), 200


# @app.route('/add', methods=['POST'])
# def Add():
#     name = request.json['name']
#     email = request.json['email']
#     mobile = request.json['mobile']
#     mobile_emergency = request.json['mobile_emergency']
#     age = request.json['age']
#     gender = request.json['gender']
#     location = request.json['location']
#     img64 = request.json['image']
#     user_disease = request.json['user_disease']
#     user_medicine = request.json['user_medicine']

#     img64_padded = add_padding(img64)
#     imageBinary = base64.b64decode(img64_padded)

#     cur = mysql.connection.cursor()
#     cur.execute("""
#                 INSERT INTO users
#                 (name, email ,mobile, mobile_emergency, age, gender, location, image)
#                 VALUES (%s,%s,%s,%s,%s,%s,%s,%s) 
#                 """, (name, email, mobile, mobile_emergency, age, gender, location, imageBinary))
#     mysql.connection.commit()
#     cur.execute("""
#                 SELECT * FROM users 
#                 WHERE name=%s AND email=%s 
#                 """, (name, email))
#     data = cur.fetchall()
#     id = data[0][0]
#     for disease in user_disease:
#         print(disease)
#         cur.execute("""INSERT INTO user_disease 
#                     (user_id, disease_name) 
#                     VALUES (%s, %s)
#                     """, (id, disease))
#     for medicine in user_medicine:
#         img64 = medicine['medicine_image']
#         img64_padded = add_padding(img64)
#         imageBinary = base64.b64decode(img64_padded)
#         cur.execute("""INSERT INTO user_medicine 
#                     (user_id, medicine_name,medicine_dose ,medicine_image) 
#                     VALUES (%s, %s, %s, %s)
#                     """, (id, medicine['medicine_name'], medicine['medicine_dose'], medicine['medicine_image']))
#     mysql.connection.commit()
#     cur.close()
#     return jsonify({"message": "done"}), 200


# @app.route('/delete/<string:email>', methods=['DELETE'])
# def Delete(email):
#     cur = mysql.connection.cursor()
#     cur.execute("""
#                 SELECT id FROM users 
#                 WHERE email=%s 
#                 """, (email, ))
#     data = cur.fetchall()
#     id = data[0][0]
#     cur.execute("DELETE FROM user_disease WHERE user_id=%s", (id,))
#     cur.execute("DELETE FROM user_medicine WHERE user_id=%s", (id,))
#     cur.execute("DELETE FROM users WHERE id=%s", (id,))
#     mysql.connection.commit()
#     return jsonify({"message": "done"}), 200


# @app.route('/update/<int:id>',  methods=['PUT'])
# def Update(id):
#     name = request.json['name']
#     email = request.json['email']
#     mobile = request.json['mobile']
#     mobile_emergency = request.json['mobile_emergency']
#     age = request.json['age']
#     gender = request.json['gender']
#     location = request.json['location']
#     img64 = request.json['image']
#     user_disease = request.json['user_disease']
#     user_medicine = request.json['user_medicine']

#     img64_padded = add_padding(img64)
#     imageBinary = base64.b64decode(img64_padded)

#     cur = mysql.connection.cursor()
#     cur.execute("""
#             UPDATE users 
#             SET name=%s,email=%s, mobile=%s ,mobile_emergency=%s ,age=%s ,gender=%s ,location=%s ,image=%s
#             WHERE id=%s 
#             """, (name, email, mobile, mobile_emergency, age, gender, location, imageBinary, id))
#     cur.execute("DELETE FROM user_disease WHERE user_id=%s", (id,))
#     cur.execute("DELETE FROM user_medicine WHERE user_id=%s", (id,))

#     for disease in user_disease:
#         cur.execute("""INSERT INTO user_disease 
#                     (user_id, disease_name) 
#                     VALUES (%s, %s)
#                     """, (id, disease['disease_name']))
#     for medicine in user_medicine:
#         cur.execute("""INSERT INTO user_medicine 
#                     (user_id, medicine_name, medicine_image) 
#                     VALUES (%s, %s, %s)
#                     """, (id, medicine['medicine_name'], medicine['medicine_image']))
#     mysql.connection.commit()
#     return jsonify({"message": "done"}), 200



# @app.route('/select/<int:id>', methods=['GET'])
# def Select(id):
#     cur = mysql.connection.cursor()
#     cur.execute("SELECT * FROM users WHERE id=%s", (id,))
#     table1 = cur.fetchall()
#     cur.execute("SELECT * FROM user_disease WHERE user_id=%s", (id,))
#     table2 = cur.fetchall()
#     cur.execute("SELECT * FROM user_medicine WHERE user_id=%s", (id,))
#     table3 = cur.fetchall()
#     cur.close()
#     user_data = {
#         "name": table1[0][1],
#         "email": table1[0][2],
#         "mobile": table1[0][3],
#         "mobile_emergency": table1[0][4],
#         "age": table1[0][5],
#         "gender": table1[0][6],
#         "location": table1[0][7],
#         "image": base64.b64encode(table1[0][8]).decode('utf-8'),
#         "user_disease": [{"disease_name": disease[1]} for disease in table2],
#         "user_medicine": [{"medicine_name": medicine[1], "medicine_image": base64.b64encode(medicine[3]).decode('utf-8')} for medicine in table3]
#     }
#     return jsonify(user_data), 200


# if __name__ == '__main__':
#     app.run(host='0.0.0.0', port=7860, debug=True)
    # init_connect()
    # app.run(host='192.168.137.241', port=5000, debug=True) # 192.168.1.114 http://192.168.137.241:5000  192.168.1.122