rohangbs commited on
Commit
f0f3217
·
1 Parent(s): c65d606
Files changed (1) hide show
  1. app.py +7 -5
app.py CHANGED
@@ -20,17 +20,20 @@ app.add_middleware(SessionMiddleware, secret_key=os.urandom(24))
20
  client = Groq(api_key='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')
21
 
22
  # Database initialization
 
 
23
  def init_db():
24
- conn = sqlite3.connect('chat_history.db')
 
 
 
25
  c = conn.cursor()
26
-
27
- # Users table
28
  c.execute('''CREATE TABLE IF NOT EXISTS users
29
  (id INTEGER PRIMARY KEY AUTOINCREMENT,
30
  username TEXT UNIQUE NOT NULL,
31
  password TEXT NOT NULL,
32
  created_at DATETIME DEFAULT CURRENT_TIMESTAMP)''')
33
-
34
  c.execute('''CREATE TABLE IF NOT EXISTS chats
35
  (id INTEGER PRIMARY KEY AUTOINCREMENT,
36
  user_id INTEGER NOT NULL,
@@ -44,7 +47,6 @@ def init_db():
44
  conn.close()
45
 
46
  init_db()
47
-
48
  # Helper functions
49
  def hash_password(password):
50
  return hashlib.sha256(password.encode()).hexdigest()
 
20
  client = Groq(api_key='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')
21
 
22
  # Database initialization
23
+ DATABASE_PATH = '/app/chat_history.db'
24
+
25
  def init_db():
26
+ # Ensure the directory exists
27
+ os.makedirs(os.path.dirname(DATABASE_PATH), exist_ok=True)
28
+
29
+ conn = sqlite3.connect(DATABASE_PATH)
30
  c = conn.cursor()
 
 
31
  c.execute('''CREATE TABLE IF NOT EXISTS users
32
  (id INTEGER PRIMARY KEY AUTOINCREMENT,
33
  username TEXT UNIQUE NOT NULL,
34
  password TEXT NOT NULL,
35
  created_at DATETIME DEFAULT CURRENT_TIMESTAMP)''')
36
+
37
  c.execute('''CREATE TABLE IF NOT EXISTS chats
38
  (id INTEGER PRIMARY KEY AUTOINCREMENT,
39
  user_id INTEGER NOT NULL,
 
47
  conn.close()
48
 
49
  init_db()
 
50
  # Helper functions
51
  def hash_password(password):
52
  return hashlib.sha256(password.encode()).hexdigest()