pavankm96 commited on
Commit
e9b5166
·
verified ·
1 Parent(s): 3020cf4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +1 -80
app.py CHANGED
@@ -4,11 +4,7 @@ from PIL import Image
4
  import numpy as np
5
  import cv2
6
  import tensorflow as tf # Assuming you're using TensorFlow for loading your model
7
- from pydantic import BaseModel
8
- from datetime import datetime, date
9
- import pg8000
10
- import hashlib
11
- from typing import Annotated
12
 
13
  app = FastAPI()
14
 
@@ -49,82 +45,7 @@ async def predict(upload: UploadFile = File(...)):
49
  raise HTTPException(status_code=500, detail=str(e))
50
 
51
 
52
- def get_db_connection():
53
- return pg8000.connect(
54
- user="new_hor",
55
- password="R99oQ4CtlfuYx6gBepBfxC78EnRAjuFB",
56
- host="dpg-cudg8a2j1k6c73cnc310-a.oregon-postgres.render.com",
57
- database="user_db_ron3"
58
- )
59
-
60
- # Password hashing function
61
- def hash_password(password: str) -> str:
62
- return hashlib.sha256(password.encode()).hexdigest()
63
-
64
-
65
- # Request models
66
- class RegisterUserRequest(BaseModel):
67
- email: str
68
- username: str
69
- password: str
70
- phone: str
71
- dob_day: int
72
- dob_month: int
73
- dob_year: int
74
-
75
- class LoginUserRequest(BaseModel):
76
- email: str
77
- password: str
78
 
79
- # Register user endpoint
80
- @app.post("/register")
81
- def register_user(user: RegisterUserRequest):
82
- try:
83
-
84
-
85
- password_hash = hash_password(user.password)
86
-
87
- conn = get_db_connection()
88
- cursor = conn.cursor()
89
-
90
- cursor.execute("SELECT * FROM users WHERE email = %s", (user.email,))
91
- if cursor.fetchone():
92
- raise HTTPException(status_code=400, detail="Email already registered.")
93
-
94
- cursor.execute(
95
- "INSERT INTO users (email, username, password_hash, phone, dob) VALUES (%s, %s, %s, %s, %s)",
96
- (user.email, user.username, password_hash, user.phone, dob)
97
- )
98
- conn.commit()
99
-
100
- cursor.close()
101
- conn.close()
102
-
103
- return {"message": "Registration successful!"}
104
- except Exception as error:
105
- raise HTTPException(status_code=500, detail=f"Error: {error}")
106
-
107
- # Login user endpoint
108
- @app.post("/login")
109
- def login_user(user: LoginUserRequest):
110
- try:
111
- password_hash = hash_password(user.password)
112
-
113
- conn = get_db_connection()
114
- cursor = conn.cursor()
115
-
116
- cursor.execute("SELECT * FROM users WHERE email = %s", (user.email,))
117
- user_record = cursor.fetchone()
118
-
119
- cursor.close()
120
- conn.close()
121
-
122
- if user_record and user_record[3] == password_hash: # user[3] is the password_hash field
123
- return {"message": "Login successful!", "email": user.email}
124
- else:
125
- raise HTTPException(status_code=400, detail="Invalid email or password.")
126
- except Exception as error:
127
- raise HTTPException(status_code=500, detail=f"Error: {error}")
128
 
129
  # To run the FastAPI app, use the following command:
130
  # uvicorn app:app --reload
 
4
  import numpy as np
5
  import cv2
6
  import tensorflow as tf # Assuming you're using TensorFlow for loading your model
7
+
 
 
 
 
8
 
9
  app = FastAPI()
10
 
 
45
  raise HTTPException(status_code=500, detail=str(e))
46
 
47
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
48
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49
 
50
  # To run the FastAPI app, use the following command:
51
  # uvicorn app:app --reload