Pijush2023 commited on
Commit
7d3451d
·
verified ·
1 Parent(s): 78029ec

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +86 -86
app.py CHANGED
@@ -835,86 +835,86 @@ def update_images():
835
 
836
 
837
 
838
- import sqlite3
839
- import bcrypt
840
- import gradio as gr
841
-
842
- # Set up the database
843
- def initialize_database():
844
- conn = sqlite3.connect('user_data.db')
845
- c = conn.cursor()
846
- c.execute('''
847
- CREATE TABLE IF NOT EXISTS users (
848
- id INTEGER PRIMARY KEY AUTOINCREMENT,
849
- email TEXT UNIQUE NOT NULL,
850
- password TEXT NOT NULL
851
- )
852
- ''')
853
- conn.commit()
854
- conn.close()
855
-
856
- # Email validation
857
- def is_valid_email(email):
858
- regex = r'^\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b'
859
- if re.match(regex, email):
860
- return True
861
- else:
862
- return False
863
 
864
- # Hashing and checking passwords
865
- def hash_password(password):
866
- return bcrypt.hashpw(password.encode(), bcrypt.gensalt())
867
 
868
- def check_password(password, hashed):
869
- return bcrypt.checkpw(password.encode(), hashed)
870
 
871
- # User signup and login functions
872
- def signup_user(email, password):
873
- if not is_valid_email(email):
874
- return "Invalid email!"
875
- conn = sqlite3.connect('user_data.db')
876
- c = conn.cursor()
877
- try:
878
- c.execute("INSERT INTO users (email, password) VALUES (?, ?)", (email, hash_password(password)))
879
- conn.commit()
880
- return "User signed up successfully!"
881
- except sqlite3.IntegrityError:
882
- return "Email already registered!"
883
- finally:
884
- conn.close()
885
-
886
- def login_user(email, password, state):
887
- if not is_valid_email(email):
888
- return "Invalid email!", state
889
- conn = sqlite3.connect('user_data.db')
890
- c = conn.cursor()
891
- c.execute("SELECT password FROM users WHERE email = ?", (email,))
892
- result = c.fetchone()
893
- conn.close()
894
- if result and check_password(password, result[0]):
895
- state['authenticated'] = True
896
- return "Login successful!", state
897
- else:
898
- return "Invalid email or password!", state
899
 
900
- def logout_user(state):
901
- state['authenticated'] = False
902
- return "Logged out successfully!", state
903
 
904
- # Define the necessary functions
905
- def signup(email, password):
906
- return signup_user(email, password)
907
 
908
- def login(email, password, state):
909
- message, state = login_user(email, password, state)
910
- return message, state, "Logout" if state['authenticated'] else "Login"
911
 
912
- def logout(state):
913
- message, state = logout_user(state)
914
- return message, state, "Login", "", ""
915
 
916
- # Initialize database
917
- initialize_database()
918
 
919
 
920
 
@@ -928,20 +928,20 @@ with gr.Blocks(theme='Pijush2023/scikit-learn-pijush') as demo:
928
  with gr.Column():
929
  gr.Markdown("<h1>Welcome to the App</h1>")
930
 
931
- with gr.Tab("Sign Up"):
932
- signup_email = gr.Textbox(placeholder="Email", label="Email", type="email")
933
- signup_password = gr.Textbox(placeholder="Password", label="Password", type="password")
934
- signup_button = gr.Button("Sign Up")
935
- signup_output = gr.Textbox(interactive=False, label="Output")
936
- signup_button.click(signup, inputs=[signup_email, signup_password], outputs=signup_output)
937
-
938
- with gr.Tab("Login"):
939
- login_email = gr.Textbox(placeholder="Email", label="Email", type="email")
940
- login_password = gr.Textbox(placeholder="Password", label="Password", type="password")
941
- login_button = gr.Button("Login")
942
- login_output = gr.Textbox(interactive=False, label="Output")
943
- login_button.click(login, inputs=[login_email, login_password, state], outputs=[login_output, state, login_button])
944
- login_button.click(logout, inputs=[state], outputs=[login_output, state, login_button, login_email, login_password], show_progress=False)
945
 
946
  state = gr.State()
947
  chatbot = gr.Chatbot([], elem_id="RADAR:Channel 94.1", bubble_full_width=False)
 
835
 
836
 
837
 
838
+ # import sqlite3
839
+ # import bcrypt
840
+ # import gradio as gr
841
+
842
+ # # Set up the database
843
+ # def initialize_database():
844
+ # conn = sqlite3.connect('user_data.db')
845
+ # c = conn.cursor()
846
+ # c.execute('''
847
+ # CREATE TABLE IF NOT EXISTS users (
848
+ # id INTEGER PRIMARY KEY AUTOINCREMENT,
849
+ # email TEXT UNIQUE NOT NULL,
850
+ # password TEXT NOT NULL
851
+ # )
852
+ # ''')
853
+ # conn.commit()
854
+ # conn.close()
855
+
856
+ # # Email validation
857
+ # def is_valid_email(email):
858
+ # regex = r'^\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b'
859
+ # if re.match(regex, email):
860
+ # return True
861
+ # else:
862
+ # return False
863
 
864
+ # # Hashing and checking passwords
865
+ # def hash_password(password):
866
+ # return bcrypt.hashpw(password.encode(), bcrypt.gensalt())
867
 
868
+ # def check_password(password, hashed):
869
+ # return bcrypt.checkpw(password.encode(), hashed)
870
 
871
+ # # User signup and login functions
872
+ # def signup_user(email, password):
873
+ # if not is_valid_email(email):
874
+ # return "Invalid email!"
875
+ # conn = sqlite3.connect('user_data.db')
876
+ # c = conn.cursor()
877
+ # try:
878
+ # c.execute("INSERT INTO users (email, password) VALUES (?, ?)", (email, hash_password(password)))
879
+ # conn.commit()
880
+ # return "User signed up successfully!"
881
+ # except sqlite3.IntegrityError:
882
+ # return "Email already registered!"
883
+ # finally:
884
+ # conn.close()
885
+
886
+ # def login_user(email, password, state):
887
+ # if not is_valid_email(email):
888
+ # return "Invalid email!", state
889
+ # conn = sqlite3.connect('user_data.db')
890
+ # c = conn.cursor()
891
+ # c.execute("SELECT password FROM users WHERE email = ?", (email,))
892
+ # result = c.fetchone()
893
+ # conn.close()
894
+ # if result and check_password(password, result[0]):
895
+ # state['authenticated'] = True
896
+ # return "Login successful!", state
897
+ # else:
898
+ # return "Invalid email or password!", state
899
 
900
+ # def logout_user(state):
901
+ # state['authenticated'] = False
902
+ # return "Logged out successfully!", state
903
 
904
+ # # Define the necessary functions
905
+ # def signup(email, password):
906
+ # return signup_user(email, password)
907
 
908
+ # def login(email, password, state):
909
+ # message, state = login_user(email, password, state)
910
+ # return message, state, "Logout" if state['authenticated'] else "Login"
911
 
912
+ # def logout(state):
913
+ # message, state = logout_user(state)
914
+ # return message, state, "Login", "", ""
915
 
916
+ # # Initialize database
917
+ # initialize_database()
918
 
919
 
920
 
 
928
  with gr.Column():
929
  gr.Markdown("<h1>Welcome to the App</h1>")
930
 
931
+ # with gr.Tab("Sign Up"):
932
+ # signup_email = gr.Textbox(placeholder="Email", label="Email", type="email")
933
+ # signup_password = gr.Textbox(placeholder="Password", label="Password", type="password")
934
+ # signup_button = gr.Button("Sign Up")
935
+ # signup_output = gr.Textbox(interactive=False, label="Output")
936
+ # signup_button.click(signup, inputs=[signup_email, signup_password], outputs=signup_output)
937
+
938
+ # with gr.Tab("Login"):
939
+ # login_email = gr.Textbox(placeholder="Email", label="Email", type="email")
940
+ # login_password = gr.Textbox(placeholder="Password", label="Password", type="password")
941
+ # login_button = gr.Button("Login")
942
+ # login_output = gr.Textbox(interactive=False, label="Output")
943
+ # login_button.click(login, inputs=[login_email, login_password, state], outputs=[login_output, state, login_button])
944
+ # login_button.click(logout, inputs=[state], outputs=[login_output, state, login_button, login_email, login_password], show_progress=False)
945
 
946
  state = gr.State()
947
  chatbot = gr.Chatbot([], elem_id="RADAR:Channel 94.1", bubble_full_width=False)