Spaces:
Running
Running
theme
Browse files
main.py
CHANGED
@@ -3,22 +3,22 @@ import gradio as gr
|
|
3 |
from predict import predict
|
4 |
from toolbox import format_io, find_free_port
|
5 |
|
6 |
-
# 建议您复制一个config_private.py
|
7 |
-
try: from config_private import proxies, WEB_PORT
|
8 |
-
except: from config import proxies, WEB_PORT
|
9 |
|
10 |
-
# 如果WEB_PORT是-1
|
11 |
PORT = find_free_port() if WEB_PORT <= 0 else WEB_PORT
|
12 |
|
13 |
initial_prompt = "Serve me as a writing and programming assistant."
|
14 |
title_html = """<h1 align="center">ChatGPT 学术优化</h1>"""
|
15 |
|
16 |
-
#
|
17 |
import logging
|
18 |
os.makedirs('gpt_log', exist_ok=True)
|
19 |
try:logging.basicConfig(filename='gpt_log/chat_secrets.log', level=logging.INFO, encoding='utf-8')
|
20 |
except:logging.basicConfig(filename='gpt_log/chat_secrets.log', level=logging.INFO)
|
21 |
-
print('所有问询记录将自动保存在本地目录./gpt_log/chat_secrets.log
|
22 |
|
23 |
# 一些普通功能模块
|
24 |
from functional import get_functionals
|
@@ -31,12 +31,9 @@ crazy_functional = get_crazy_functionals()
|
|
31 |
# 处理markdown文本格式的转变
|
32 |
gr.Chatbot.postprocess = format_io
|
33 |
|
34 |
-
#
|
35 |
-
|
36 |
-
|
37 |
-
font_mono=["ui-monospace", "Consolas", "monospace", gr.themes.utils.fonts.GoogleFont("IBM Plex Mono")])
|
38 |
-
except:
|
39 |
-
set_theme = None; print('gradio版本较旧,不能自定义字体和颜色')
|
40 |
|
41 |
with gr.Blocks(theme=set_theme, analytics_enabled=False) as demo:
|
42 |
gr.HTML(title_html)
|
@@ -53,7 +50,10 @@ with gr.Blocks(theme=set_theme, analytics_enabled=False) as demo:
|
|
53 |
with gr.Column(scale=12):
|
54 |
txt = gr.Textbox(show_label=False, placeholder="Input question here.").style(container=False)
|
55 |
with gr.Column(scale=1):
|
56 |
-
submitBtn = gr.Button("
|
|
|
|
|
|
|
57 |
with gr.Row():
|
58 |
for k in functional:
|
59 |
variant = functional[k]["Color"] if "Color" in functional[k] else "secondary"
|
@@ -69,8 +69,6 @@ with gr.Blocks(theme=set_theme, analytics_enabled=False) as demo:
|
|
69 |
with gr.Row():
|
70 |
file_upload = gr.Files(label='任何文件,但推荐上传压缩文件(zip, tar)', file_count="multiple")
|
71 |
|
72 |
-
from check_proxy import check_proxy
|
73 |
-
statusDisplay = gr.Markdown(f"{check_proxy(proxies)}")
|
74 |
systemPromptTxt = gr.Textbox(show_label=True, placeholder=f"System Prompt", label="System prompt", value=initial_prompt).style(container=True)
|
75 |
#inputs, top_p, temperature, top_k, repetition_penalty
|
76 |
with gr.Accordion("arguments", open=False):
|
@@ -91,7 +89,7 @@ with gr.Blocks(theme=set_theme, analytics_enabled=False) as demo:
|
|
91 |
except: pass
|
92 |
|
93 |
|
94 |
-
#
|
95 |
def auto_opentab_delay():
|
96 |
import threading, webbrowser, time
|
97 |
print(f"URL http://localhost:{PORT}")
|
|
|
3 |
from predict import predict
|
4 |
from toolbox import format_io, find_free_port
|
5 |
|
6 |
+
# 建议您复制一个config_private.py放自己的秘密, 如API和代理网址, 避免不小心传github被别人看到
|
7 |
+
try: from config_private import proxies, WEB_PORT, LLM_MODEL
|
8 |
+
except: from config import proxies, WEB_PORT, LLM_MODEL
|
9 |
|
10 |
+
# 如果WEB_PORT是-1, 则随机选取WEB端口
|
11 |
PORT = find_free_port() if WEB_PORT <= 0 else WEB_PORT
|
12 |
|
13 |
initial_prompt = "Serve me as a writing and programming assistant."
|
14 |
title_html = """<h1 align="center">ChatGPT 学术优化</h1>"""
|
15 |
|
16 |
+
# 问询记录, python 版本建议3.9+(越新越好)
|
17 |
import logging
|
18 |
os.makedirs('gpt_log', exist_ok=True)
|
19 |
try:logging.basicConfig(filename='gpt_log/chat_secrets.log', level=logging.INFO, encoding='utf-8')
|
20 |
except:logging.basicConfig(filename='gpt_log/chat_secrets.log', level=logging.INFO)
|
21 |
+
print('所有问询记录将自动保存在本地目录./gpt_log/chat_secrets.log, 请注意自我隐私保护哦!')
|
22 |
|
23 |
# 一些普通功能模块
|
24 |
from functional import get_functionals
|
|
|
31 |
# 处理markdown文本格式的转变
|
32 |
gr.Chatbot.postprocess = format_io
|
33 |
|
34 |
+
# 做一些外观色彩上的调整
|
35 |
+
from theme import adjust_theme
|
36 |
+
set_theme = adjust_theme()
|
|
|
|
|
|
|
37 |
|
38 |
with gr.Blocks(theme=set_theme, analytics_enabled=False) as demo:
|
39 |
gr.HTML(title_html)
|
|
|
50 |
with gr.Column(scale=12):
|
51 |
txt = gr.Textbox(show_label=False, placeholder="Input question here.").style(container=False)
|
52 |
with gr.Column(scale=1):
|
53 |
+
submitBtn = gr.Button("提交", variant="primary")
|
54 |
+
with gr.Row():
|
55 |
+
from check_proxy import check_proxy
|
56 |
+
statusDisplay = gr.Markdown(f"Tip: 按Enter提交, 按Shift+Enter换行. \nNetwork: {check_proxy(proxies)}\nModel: {LLM_MODEL}")
|
57 |
with gr.Row():
|
58 |
for k in functional:
|
59 |
variant = functional[k]["Color"] if "Color" in functional[k] else "secondary"
|
|
|
69 |
with gr.Row():
|
70 |
file_upload = gr.Files(label='任何文件,但推荐上传压缩文件(zip, tar)', file_count="multiple")
|
71 |
|
|
|
|
|
72 |
systemPromptTxt = gr.Textbox(show_label=True, placeholder=f"System Prompt", label="System prompt", value=initial_prompt).style(container=True)
|
73 |
#inputs, top_p, temperature, top_k, repetition_penalty
|
74 |
with gr.Accordion("arguments", open=False):
|
|
|
89 |
except: pass
|
90 |
|
91 |
|
92 |
+
# 延迟函数, 做一些准备工作, 最后尝试打开浏览器
|
93 |
def auto_opentab_delay():
|
94 |
import threading, webbrowser, time
|
95 |
print(f"URL http://localhost:{PORT}")
|
theme.py
ADDED
@@ -0,0 +1,83 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
|
3 |
+
# gradio可用颜色列表
|
4 |
+
|
5 |
+
# slate
|
6 |
+
# gray
|
7 |
+
# zinc
|
8 |
+
# neutral
|
9 |
+
# stone
|
10 |
+
# red
|
11 |
+
# orange
|
12 |
+
# amber
|
13 |
+
# yellow
|
14 |
+
# lime
|
15 |
+
# green
|
16 |
+
# emerald
|
17 |
+
# teal
|
18 |
+
# cyan
|
19 |
+
# sky
|
20 |
+
# blue
|
21 |
+
# indigo
|
22 |
+
# violet
|
23 |
+
# purple
|
24 |
+
# fuchsia
|
25 |
+
# pink
|
26 |
+
# rose
|
27 |
+
|
28 |
+
def adjust_theme():
|
29 |
+
try:
|
30 |
+
color_er = gr.themes.utils.colors.pink
|
31 |
+
set_theme = gr.themes.Default(
|
32 |
+
primary_hue=gr.themes.utils.colors.orange,
|
33 |
+
neutral_hue=gr.themes.utils.colors.gray,
|
34 |
+
font=["sans-serif", "Microsoft YaHei", "ui-sans-serif", "system-ui", "sans-serif", gr.themes.utils.fonts.GoogleFont("Source Sans Pro")],
|
35 |
+
font_mono=["ui-monospace", "Consolas", "monospace", gr.themes.utils.fonts.GoogleFont("IBM Plex Mono")])
|
36 |
+
set_theme.set(
|
37 |
+
# Colors
|
38 |
+
input_background_fill_dark="*neutral_800",
|
39 |
+
# Transition
|
40 |
+
button_transition="none",
|
41 |
+
# Shadows
|
42 |
+
button_shadow="*shadow_drop",
|
43 |
+
button_shadow_hover="*shadow_drop_lg",
|
44 |
+
button_shadow_active="*shadow_inset",
|
45 |
+
input_shadow="0 0 0 *shadow_spread transparent, *shadow_inset",
|
46 |
+
input_shadow_focus="0 0 0 *shadow_spread *secondary_50, *shadow_inset",
|
47 |
+
input_shadow_focus_dark="0 0 0 *shadow_spread *neutral_700, *shadow_inset",
|
48 |
+
checkbox_label_shadow="*shadow_drop",
|
49 |
+
block_shadow="*shadow_drop",
|
50 |
+
form_gap_width="1px",
|
51 |
+
# Button borders
|
52 |
+
input_border_width="1px",
|
53 |
+
input_background_fill="white",
|
54 |
+
# Gradients
|
55 |
+
stat_background_fill="linear-gradient(to right, *primary_400, *primary_200)",
|
56 |
+
stat_background_fill_dark="linear-gradient(to right, *primary_400, *primary_600)",
|
57 |
+
error_background_fill=f"linear-gradient(to right, {color_er.c100}, *background_fill_secondary)",
|
58 |
+
error_background_fill_dark="*background_fill_primary",
|
59 |
+
checkbox_label_background_fill="linear-gradient(to top, *neutral_50, white)",
|
60 |
+
checkbox_label_background_fill_dark="linear-gradient(to top, *neutral_900, *neutral_800)",
|
61 |
+
checkbox_label_background_fill_hover="linear-gradient(to top, *neutral_100, white)",
|
62 |
+
checkbox_label_background_fill_hover_dark="linear-gradient(to top, *neutral_900, *neutral_800)",
|
63 |
+
button_primary_background_fill="linear-gradient(to bottom right, *primary_100, *primary_300)",
|
64 |
+
button_primary_background_fill_dark="linear-gradient(to bottom right, *primary_500, *primary_600)",
|
65 |
+
button_primary_background_fill_hover="linear-gradient(to bottom right, *primary_100, *primary_200)",
|
66 |
+
button_primary_background_fill_hover_dark="linear-gradient(to bottom right, *primary_500, *primary_500)",
|
67 |
+
button_primary_border_color_dark="*primary_500",
|
68 |
+
button_secondary_background_fill="linear-gradient(to bottom right, *neutral_100, *neutral_200)",
|
69 |
+
button_secondary_background_fill_dark="linear-gradient(to bottom right, *neutral_600, *neutral_700)",
|
70 |
+
button_secondary_background_fill_hover="linear-gradient(to bottom right, *neutral_100, *neutral_100)",
|
71 |
+
button_secondary_background_fill_hover_dark="linear-gradient(to bottom right, *neutral_600, *neutral_600)",
|
72 |
+
button_cancel_background_fill=f"linear-gradient(to bottom right, {color_er.c100}, {color_er.c200})",
|
73 |
+
button_cancel_background_fill_dark=f"linear-gradient(to bottom right, {color_er.c600}, {color_er.c700})",
|
74 |
+
button_cancel_background_fill_hover=f"linear-gradient(to bottom right, {color_er.c100}, {color_er.c100})",
|
75 |
+
button_cancel_background_fill_hover_dark=f"linear-gradient(to bottom right, {color_er.c600}, {color_er.c600})",
|
76 |
+
button_cancel_border_color=color_er.c200,
|
77 |
+
button_cancel_border_color_dark=color_er.c600,
|
78 |
+
button_cancel_text_color=color_er.c600,
|
79 |
+
button_cancel_text_color_dark="white",
|
80 |
+
)
|
81 |
+
except:
|
82 |
+
set_theme = None; print('gradio版本较旧, 不能自定义字体和颜色')
|
83 |
+
return set_theme
|