simondby commited on
Commit
8340535
·
1 Parent(s): 5410de6
Files changed (2) hide show
  1. app.py +29 -18
  2. requirements.txt +1 -1
app.py CHANGED
@@ -34,21 +34,6 @@ def get_current_time():
34
  timestamp = now.strftime("%Y-%m-%d %H:%M:%S")
35
  return timestamp
36
 
37
- # auth check
38
- def auth_check(username, password):
39
- global logged_in_user
40
- if_pass = False
41
- for user in user_tuple:
42
- if user[0] == username and user[1] == password:
43
- if_pass = True
44
- logged_in_user = username
45
- break
46
- if if_pass:
47
- print(f"Logged in as {logged_in_user}")
48
- else:
49
- print(f"Login attempt failed:[{username},{password}]")
50
- return if_pass
51
-
52
  # db fetch
53
  def fetch_data(query):
54
  # connect to db
@@ -70,6 +55,25 @@ try:
70
  except:
71
  user_tuple = os.environ.get('user_tuple')
72
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
73
  # db write
74
  def write_data(time, session_id, chat_id, api_key, round, system, user, assistant, messages, payload, username):
75
 
@@ -378,7 +382,9 @@ css_styles = """
378
  """
379
 
380
  # build UI
381
- with gr.Blocks(css=css_styles,title="Chatbot🚀") as interface:
 
 
382
 
383
  history = gr.State([])
384
  promptTemplates = gr.State({})
@@ -538,5 +544,10 @@ if dockerflag:
538
  interface.queue(concurrency_count=2,status_update_rate="auto").launch(server_name="0.0.0.0", server_port=7860,auth=auth_check)
539
  #if not running in Docker
540
  else:
541
- interface.queue(concurrency_count=2,status_update_rate="auto").launch(height='800px',debug=True,show_error=True,
542
- auth=auth_check,auth_message="请联系Simon获取用户名与密码!")
 
 
 
 
 
 
34
  timestamp = now.strftime("%Y-%m-%d %H:%M:%S")
35
  return timestamp
36
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
37
  # db fetch
38
  def fetch_data(query):
39
  # connect to db
 
55
  except:
56
  user_tuple = os.environ.get('user_tuple')
57
 
58
+ # print(user_tuple)
59
+
60
+ # auth check
61
+ def auth_check(username, password):
62
+ global logged_in_user
63
+ if_pass = False
64
+ for user in user_tuple:
65
+ # print(user)
66
+ if user[0] == username and user[1] == password:
67
+ if_pass = True
68
+ logged_in_user = username
69
+ break
70
+ if if_pass:
71
+ print(f"Logged in as {logged_in_user}")
72
+ else:
73
+ print(f"Login attempt failed:[{username},{password}]")
74
+ return if_pass
75
+
76
+
77
  # db write
78
  def write_data(time, session_id, chat_id, api_key, round, system, user, assistant, messages, payload, username):
79
 
 
382
  """
383
 
384
  # build UI
385
+ with gr.Blocks(css=css_styles,title="Chatbot🚀"
386
+ # ,theme=gr.themes.Default()
387
+ ) as interface:
388
 
389
  history = gr.State([])
390
  promptTemplates = gr.State({})
 
544
  interface.queue(concurrency_count=2,status_update_rate="auto").launch(server_name="0.0.0.0", server_port=7860,auth=auth_check)
545
  #if not running in Docker
546
  else:
547
+ interface.queue(concurrency_count=2,status_update_rate="auto").launch(
548
+ height='800px',
549
+ debug=True,
550
+ show_error=True,
551
+ auth=auth_check,
552
+ auth_message="请联系Simon获取用户名与密码!"
553
+ )
requirements.txt CHANGED
@@ -1,3 +1,3 @@
1
  openai==0.27.0
2
- gradio==3.22.1
3
  pymysql==1.0.2
 
1
  openai==0.27.0
2
+ gradio==3.20.1
3
  pymysql==1.0.2