Pijush2023 commited on
Commit
e172e67
·
verified ·
1 Parent(s): 6bd0c3b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -23
app.py CHANGED
@@ -837,29 +837,30 @@ def update_images():
837
 
838
  import sqlite3
839
  import bcrypt
 
840
 
841
- # Create a database connection
842
- conn = sqlite3.connect('user_data.db')
843
- c = conn.cursor()
844
-
845
- # Create users table
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
 
 
857
  def hash_password(password):
858
  return bcrypt.hashpw(password.encode(), bcrypt.gensalt())
859
 
860
  def check_password(password, hashed):
861
  return bcrypt.checkpw(password.encode(), hashed)
862
 
 
863
  def signup_user(email, password):
864
  conn = sqlite3.connect('user_data.db')
865
  c = conn.cursor()
@@ -883,27 +884,38 @@ def login_user(email, password):
883
  else:
884
  return "Invalid email or password!"
885
 
 
 
 
 
 
 
 
 
 
 
886
 
887
 
888
 
889
 
890
 
 
891
  with gr.Blocks(theme='Pijush2023/scikit-learn-pijush') as demo:
892
  with gr.Row():
893
  with gr.Column():
894
  gr.Markdown("<h1>Welcome to the App</h1>")
895
  with gr.Tab("Sign Up"):
896
- signup_email = gr.Textbox(placeholder="Email")
897
- signup_password = gr.Password(placeholder="Password")
898
  signup_button = gr.Button("Sign Up")
899
- signup_output = gr.Textbox(interactive=False)
900
  signup_button.click(signup, inputs=[signup_email, signup_password], outputs=signup_output)
901
 
902
  with gr.Tab("Login"):
903
- login_email = gr.Textbox(placeholder="Email")
904
- login_password = gr.Password(placeholder="Password")
905
  login_button = gr.Button("Login")
906
- login_output = gr.Textbox(interactive=False)
907
  login_button.click(login, inputs=[login_email, login_password], outputs=login_output)
908
 
909
  state = gr.State()
@@ -929,7 +941,7 @@ with gr.Blocks(theme='Pijush2023/scikit-learn-pijush') as demo:
929
  with gr.Column():
930
  weather_output = gr.HTML(value=fetch_local_weather())
931
  news_output = gr.HTML(value=fetch_local_news())
932
- news_output = gr.HTML(value=fetch_local_events())
933
 
934
  with gr.Column():
935
  image_output_1 = gr.Image(value=generate_image(hardcoded_prompt_1), width=400, height=400)
@@ -939,4 +951,4 @@ with gr.Blocks(theme='Pijush2023/scikit-learn-pijush') as demo:
939
  refresh_button.click(fn=update_images, inputs=None, outputs=[image_output_1, image_output_2, image_output_3])
940
 
941
  demo.queue()
942
- demo.launch(share=True)
 
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
+ # Hashing and checking passwords
857
  def hash_password(password):
858
  return bcrypt.hashpw(password.encode(), bcrypt.gensalt())
859
 
860
  def check_password(password, hashed):
861
  return bcrypt.checkpw(password.encode(), hashed)
862
 
863
+ # User signup and login functions
864
  def signup_user(email, password):
865
  conn = sqlite3.connect('user_data.db')
866
  c = conn.cursor()
 
884
  else:
885
  return "Invalid email or password!"
886
 
887
+ # Functions for Gradio interface
888
+ def signup(email, password):
889
+ return signup_user(email, password)
890
+
891
+ def login(email, password):
892
+ return login_user(email, password)
893
+
894
+ # Initialize database
895
+ initialize_database()
896
+
897
 
898
 
899
 
900
 
901
 
902
+ # Gradio interface
903
  with gr.Blocks(theme='Pijush2023/scikit-learn-pijush') as demo:
904
  with gr.Row():
905
  with gr.Column():
906
  gr.Markdown("<h1>Welcome to the App</h1>")
907
  with gr.Tab("Sign Up"):
908
+ signup_email = gr.Textbox(placeholder="Email", label="Email")
909
+ signup_password = gr.Textbox(placeholder="Password", label="Password", type="password")
910
  signup_button = gr.Button("Sign Up")
911
+ signup_output = gr.Textbox(interactive=False, label="Output")
912
  signup_button.click(signup, inputs=[signup_email, signup_password], outputs=signup_output)
913
 
914
  with gr.Tab("Login"):
915
+ login_email = gr.Textbox(placeholder="Email", label="Email")
916
+ login_password = gr.Textbox(placeholder="Password", label="Password", type="password")
917
  login_button = gr.Button("Login")
918
+ login_output = gr.Textbox(interactive=False, label="Output")
919
  login_button.click(login, inputs=[login_email, login_password], outputs=login_output)
920
 
921
  state = gr.State()
 
941
  with gr.Column():
942
  weather_output = gr.HTML(value=fetch_local_weather())
943
  news_output = gr.HTML(value=fetch_local_news())
944
+ events_output = gr.HTML(value=fetch_local_events())
945
 
946
  with gr.Column():
947
  image_output_1 = gr.Image(value=generate_image(hardcoded_prompt_1), width=400, height=400)
 
951
  refresh_button.click(fn=update_images, inputs=None, outputs=[image_output_1, image_output_2, image_output_3])
952
 
953
  demo.queue()
954
+ demo.launch(share=True)