JunchuanYu commited on
Commit
a3cc1e1
1 Parent(s): 6ffa208

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -10
app.py CHANGED
@@ -4,13 +4,13 @@ import sys
4
  import argparse
5
  from utils import *
6
  from chat_func import *
7
-
8
  my_api_key = os.environ.get('my_api_key')
9
 
10
  if my_api_key == "empty":
11
  print("Please give a api key!")
12
  sys.exit(1)
13
-
14
  gr.Chatbot.postprocess = postprocess
15
 
16
 
@@ -18,7 +18,7 @@ with open("css_new.css", "r", encoding="utf-8") as f:
18
  css = f.read()
19
 
20
  with gr.Blocks(css=css) as demo:
21
-
22
  history = gr.State([])
23
  token_count = gr.State([])
24
  promptTemplates = gr.State(load_template('myprompts.json', mode=2))
@@ -26,17 +26,22 @@ with gr.Blocks(css=css) as demo:
26
  TRUECOMSTANT = gr.State(True)
27
  FALSECONSTANT = gr.State(False)
28
  gr.Markdown(title)
29
-
30
- with gr.Accordion("Build by [45度科研人](WeChat Public Accounts)", open=False):
31
- gr.Markdown(description)
32
-
 
 
 
 
 
33
  with gr.Row(scale=1).style(equal_height=True):
34
  with gr.Column(scale=5):
35
  with gr.Column():
36
  chatbot = gr.Chatbot()
37
  user_input = gr.Textbox(show_label=False, placeholder="Enter text and press submit", visible=True).style(container=False)
38
- submitBtn = gr.Button("Submit", variant="primary" ).style(container=False)
39
- emptyBtn = gr.Button("Restart Conversation",variant="secondary").style(container=False)
40
  status_display = gr.Markdown("")
41
 
42
  with gr.Column():
@@ -69,6 +74,13 @@ with gr.Blocks(css=css) as demo:
69
  <img src="https://dunazo.oss-cn-beijing.aliyuncs.com/blog/shoukuanma222.png" style="margin-left:25px;width:170px;height:190px;">
70
  </div>
71
  """)
 
 
 
 
 
 
 
72
  keyTxt.submit(submit_key, keyTxt, [user_api_key, status_display])
73
  keyTxt.change(submit_key, keyTxt, [user_api_key, status_display])
74
  # Chatbot
@@ -86,4 +98,4 @@ with gr.Blocks(css=css) as demo:
86
 
87
 
88
  if __name__ == "__main__":
89
- demo.queue().launch(debug=False,show_api=False)
 
4
  import argparse
5
  from utils import *
6
  from chat_func import *
7
+
8
  my_api_key = os.environ.get('my_api_key')
9
 
10
  if my_api_key == "empty":
11
  print("Please give a api key!")
12
  sys.exit(1)
13
+
14
  gr.Chatbot.postprocess = postprocess
15
 
16
 
 
18
  css = f.read()
19
 
20
  with gr.Blocks(css=css) as demo:
21
+ # ,theme='gradio/soft'
22
  history = gr.State([])
23
  token_count = gr.State([])
24
  promptTemplates = gr.State(load_template('myprompts.json', mode=2))
 
26
  TRUECOMSTANT = gr.State(True)
27
  FALSECONSTANT = gr.State(False)
28
  gr.Markdown(title)
29
+
30
+ with gr.Row().style(equal_height=True):
31
+ with gr.Column(scale=12):
32
+ with gr.Accordion("Build by [45度科研人](WeChat Public Accounts)", open=False):
33
+ gr.Markdown(description)
34
+ with gr.Column(scale=1):
35
+ with gr.Box():
36
+ toggle_dark = gr.Button(value="Toggle Dark").style(full_width=True)
37
+
38
  with gr.Row(scale=1).style(equal_height=True):
39
  with gr.Column(scale=5):
40
  with gr.Column():
41
  chatbot = gr.Chatbot()
42
  user_input = gr.Textbox(show_label=False, placeholder="Enter text and press submit", visible=True).style(container=False)
43
+ submitBtn = gr.Button("Submit",variant="primary").style(container=False)
44
+ emptyBtn = gr.Button("Restart Conversation",variant="secondary")
45
  status_display = gr.Markdown("")
46
 
47
  with gr.Column():
 
74
  <img src="https://dunazo.oss-cn-beijing.aliyuncs.com/blog/shoukuanma222.png" style="margin-left:25px;width:170px;height:190px;">
75
  </div>
76
  """)
77
+
78
+ toggle_dark.click(None,_js="""
79
+ () => {
80
+ document.body.classList.toggle('dark');
81
+ document.querySelector('gradio-app').style.backgroundColor = 'var(--color-background-primary)'
82
+ }""",)
83
+
84
  keyTxt.submit(submit_key, keyTxt, [user_api_key, status_display])
85
  keyTxt.change(submit_key, keyTxt, [user_api_key, status_display])
86
  # Chatbot
 
98
 
99
 
100
  if __name__ == "__main__":
101
+ demo.queue().launch(debug=False,show_api=False)