Liuli commited on
Commit
ef7b87e
1 Parent(s): c77e963
Files changed (4) hide show
  1. app.py +21 -22
  2. requirements.txt +1 -0
  3. test.py +9 -6
  4. user.db +0 -0
app.py CHANGED
@@ -10,19 +10,15 @@ from presets import *
10
  from overwrites import *
11
  from chat_func import *
12
 
13
- import requests
14
- from urllib import parse
15
-
16
- requestUrl = 'http://82.156.209.58:8520/api/user'
17
- headers = {
18
- 'Content-Type': 'application/x-www-form-urlencoded'
19
- }
20
- formData = {
21
-
22
- }
23
- data = parse.urlencode(formData, True)
24
- response = requests.post(requestUrl, headers = headers, data = data)
25
- users=response.json()["data"]
26
 
27
  logging.basicConfig(
28
  level=logging.DEBUG,
@@ -449,6 +445,12 @@ logging.info(
449
  # 默认开启本地服务器,默认可以直接从IP访问,默认不创建公开分享链接
450
  demo.title = "中建chatgpt"
451
 
 
 
 
 
 
 
452
 
453
 
454
 
@@ -457,12 +459,9 @@ if __name__ == "__main__":
457
  # if running in Docker
458
  if dockerflag:
459
  if authflag:
460
- for user in users:
461
- username=user["username"]
462
- password=user["password"]
463
- demo.queue().launch(
464
- server_name="0.0.0.0", server_port=7860, auth=(username, password),
465
- favicon_path="./assets/favicon.png"
466
  )
467
  else:
468
  demo.queue().launch(server_name="0.0.0.0", server_port=7860, share=False, favicon_path="./assets/favicon.png")
@@ -470,9 +469,9 @@ if __name__ == "__main__":
470
  else:
471
  if authflag:
472
  for user in users:
473
- username=user["username"]
474
- password=user["password"]
475
- demo.queue().launch(share=False, auth=(username, password), favicon_path="./assets/favicon.png", inbrowser=True)
476
  else:
477
  demo.queue(concurrency_count=1000).launch(share=False, favicon_path="./assets/favicon.ico", inbrowser=True) # 改为 share=True 可以创建公开分享链接
478
  # demo.queue().launch(server_name="0.0.0.0", server_port=7860, share=False) # 可自定义端口
 
10
  from overwrites import *
11
  from chat_func import *
12
 
13
+ import sqlite3
14
+ mydb=sqlite3.connect("user.db")
15
+ ## 读取sqlite3的数据
16
+ cursor=mydb.cursor()
17
+
18
+ #查询表名
19
+ cursor.execute("SELECT username,password FROM user WHERE expire_time > date('now');")
20
+ users=cursor.fetchall()
21
+
 
 
 
 
22
 
23
  logging.basicConfig(
24
  level=logging.DEBUG,
 
445
  # 默认开启本地服务器,默认可以直接从IP访问,默认不创建公开分享链接
446
  demo.title = "中建chatgpt"
447
 
448
+ def authenticate(username, password):
449
+ # 验证用户名和密码是否匹配
450
+ for user in users:
451
+ if user[0] == username and user[1] == password:
452
+ return True
453
+ return False
454
 
455
 
456
 
 
459
  # if running in Docker
460
  if dockerflag:
461
  if authflag:
462
+ demo.queue().launch(
463
+ server_name="0.0.0.0", server_port=7860, auth=authenticate,
464
+ favicon_path="./assets/favicon.png"
 
 
 
465
  )
466
  else:
467
  demo.queue().launch(server_name="0.0.0.0", server_port=7860, share=False, favicon_path="./assets/favicon.png")
 
469
  else:
470
  if authflag:
471
  for user in users:
472
+ username=user[0]
473
+ password=user[1]
474
+ demo.queue().launch(share=False, auth=authenticate, favicon_path="./assets/favicon.png", inbrowser=True)
475
  else:
476
  demo.queue(concurrency_count=1000).launch(share=False, favicon_path="./assets/favicon.ico", inbrowser=True) # 改为 share=True 可以创建公开分享链接
477
  # demo.queue().launch(server_name="0.0.0.0", server_port=7860, share=False) # 可自定义端口
requirements.txt CHANGED
@@ -10,3 +10,4 @@ Pygments
10
  llama_index
11
  langchain
12
  markdown
 
 
10
  llama_index
11
  langchain
12
  markdown
13
+ requests
test.py CHANGED
@@ -1,6 +1,9 @@
1
- import os
2
- os.path.exists("api_key.txt")
3
- with open("api_key.txt", "r") as f:
4
- my_api_key = f.read().strip()
5
- my_api_key = os.environ.get("my_api_key")
6
- print(my_api_key)
 
 
 
 
1
+ import sqlite3
2
+ mydb=sqlite3.connect("user.db")
3
+ ## 读取sqlite3的数据
4
+ cursor=mydb.cursor()
5
+
6
+ #查询表名
7
+ cursor.execute("SELECT username,password FROM user WHERE expire_time > date('now');")
8
+ Tables=cursor.fetchall()
9
+ print(Tables)
user.db ADDED
Binary file (8.19 kB). View file