osmanYusuf commited on
Commit
d9d7c7c
1 Parent(s): 31e0768

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -22
app.py CHANGED
@@ -1,9 +1,8 @@
1
  import streamlit as st
2
- import os
3
- import sqlite3
4
- from home import show_home_page
5
- from auth import signup, login
6
- import database # Ensure database initialization
7
 
8
  def main():
9
  st.set_page_config(page_title="Auto Assist Chatbot", layout="wide")
@@ -51,19 +50,6 @@ def main():
51
  unsafe_allow_html=True
52
  )
53
 
54
- # Function to create a connection to the SQLite database
55
- def create_connection():
56
- db_path = os.path.join(os.path.dirname(__file__), 'database.db')
57
- conn = sqlite3.connect(db_path)
58
- return conn
59
-
60
- def is_valid_input(username, password):
61
- prefix = "autoassist"
62
- return username.startswith(prefix) and password.startswith(prefix)
63
-
64
- # Ensure table creation
65
- database.create_table()
66
-
67
  if st.session_state.logged_in:
68
  if st.sidebar.button('Back to Login'):
69
  st.session_state.logged_in = False
@@ -81,8 +67,11 @@ def main():
81
  if st.button('Signup'):
82
  if password_signup == confirm_password_signup:
83
  if is_valid_input(username_signup, password_signup):
84
- signup(username_signup, password_signup)
85
- st.success('Signup successful!')
 
 
 
86
  else:
87
  st.error('You are not able to use "autoassist chatbot".')
88
  else:
@@ -95,7 +84,8 @@ def main():
95
 
96
  if st.button('Login'):
97
  if is_valid_input(username_login, password_login):
98
- if login(username_login, password_login):
 
99
  st.session_state.logged_in = True
100
  st.experimental_rerun()
101
  else:
@@ -104,4 +94,4 @@ def main():
104
  st.error('You are not able to use "autoassist chatbot".')
105
 
106
  if __name__ == '__main__':
107
- main()
 
1
  import streamlit as st
2
+ import requests
3
+
4
+ # Define your FastAPI backend URL
5
+ BACKEND_URL = "http://127.0.0.2:8001"
 
6
 
7
  def main():
8
  st.set_page_config(page_title="Auto Assist Chatbot", layout="wide")
 
50
  unsafe_allow_html=True
51
  )
52
 
 
 
 
 
 
 
 
 
 
 
 
 
 
53
  if st.session_state.logged_in:
54
  if st.sidebar.button('Back to Login'):
55
  st.session_state.logged_in = False
 
67
  if st.button('Signup'):
68
  if password_signup == confirm_password_signup:
69
  if is_valid_input(username_signup, password_signup):
70
+ response = requests.post(f"{BACKEND_URL}/signup/", json={"username": username_signup, "password": password_signup})
71
+ if response.status_code == 200:
72
+ st.success('Signup successful!')
73
+ else:
74
+ st.error('Signup failed. Please try again.')
75
  else:
76
  st.error('You are not able to use "autoassist chatbot".')
77
  else:
 
84
 
85
  if st.button('Login'):
86
  if is_valid_input(username_login, password_login):
87
+ response = requests.post(f"{BACKEND_URL}/login/", json={"username": username_login, "password": password_login})
88
+ if response.status_code == 200:
89
  st.session_state.logged_in = True
90
  st.experimental_rerun()
91
  else:
 
94
  st.error('You are not able to use "autoassist chatbot".')
95
 
96
  if __name__ == '__main__':
97
+ main()