hujike commited on
Commit
0d84cbc
·
1 Parent(s): c75f0a1

Update test.py

Browse files
Files changed (1) hide show
  1. test.py +123 -30
test.py CHANGED
@@ -1,37 +1,130 @@
1
- import gradio as gr
2
- import argparse
3
- from utils import *
4
- from presets import *
5
 
 
 
 
 
6
 
7
- my_api_key = "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" # 在这里输入你的 API 密钥
8
 
9
  authflag = False
10
 
11
- if not my_api_key and os.path.exists("api_key.txt") and os.path.getsize("api_key.txt"):
12
- with open("api_key.txt", "r") as f:
13
- my_api_key = f.read().strip()
14
- if os.path.exists("auth.json"):
15
- with open("auth.json", "r") as f:
16
- auth = json.load(f)
17
- username = auth["username"]
18
- password = auth["password"]
19
- if username != "" and password != "":
20
- authflag = True
21
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
 
23
- gr.Chatbot.postprocess = postprocess
24
- with gr.Blocks(css=customCSS) as demo:
25
- history = gr.State([])
26
- token_count = gr.State([])
27
- promptTemplates = gr.State(load_template(get_template_names(plain=True)[0], mode=2))
28
- TRUECOMSTANT = gr.State(True)
29
- FALSECONSTANT = gr.State(False)
30
- topic = gr.State("未命名对话历史记录")
31
- gr.HTML(title)
32
- with gr.Row():
33
- with gr.Column():
34
- keyTxt = gr.Textbox(show_label=True, placeholder=f"在这里输入你的OpenAI API-key...",value=my_api_key, type="password", visible=not HIDE_MY_KEY, label="API-Key")
35
- with gr.Column():
36
- with gr.Row():
37
- model_select_dropdown = gr.Dropdown(label="选择模型", choices=MODELS, multiselect=False, value=MODELS[0])
 
1
+ # coding:utf-8
 
 
 
2
 
3
+ import gradio as gr
4
+ # import argparse
5
+ # from utils import *
6
+ # from presets import *
7
 
8
+ my_api_key = "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" # 在这里输入你的 API 密钥
9
 
10
  authflag = False
11
 
12
+ # gr.Chatbot.postprocess = postprocess
13
+
14
+ with gr.Blocks() as demo:
15
+ history = gr.inputs.Hidden()
16
+ token_count = gr.inputs.Hidden()
17
+ promptTemplates = gr.inputs.Hidden()
18
+ TRUECOMSTANT = gr.inputs.Hidden()
19
+ FALSECONSTANT = gr.inputs.Hidden()
20
+ topic = gr.inputs.Hidden()
 
21
 
22
+ gradio_interface = gr.Interface(
23
+ predict,
24
+ [
25
+ gr.inputs.Textbox(
26
+ show_label=True,
27
+ label="API-Key",
28
+ placeholder=f"在这里输入你的OpenAI API-key...",
29
+ value=my_api_key,
30
+ type="password",
31
+ visible=not HIDE_MY_KEY,
32
+ ),
33
+ gr.inputs.Textbox(
34
+ show_label=True, label="System prompt", value=initial_prompt
35
+ ),
36
+ history,
37
+ gr.inputs.Textbox(
38
+ show_label=False, placeholder="在这里输入", label="User Input"
39
+ ),
40
+ gr.inputs.Hidden(),
41
+ token_count,
42
+ gr.inputs.Slider(
43
+ label="Top-p (nucleus sampling)", min_val=0.0, max_val=1.0, step=0.05
44
+ ),
45
+ gr.inputs.Slider(
46
+ label="Temperature", min_val=0.0, max_val=5.0, step=0.1
47
+ ),
48
+ gr.inputs.Checkbox(label="实时传输回答", default=True),
49
+ gr.inputs.Dropdown(
50
+ label="选择模型",
51
+ choices=MODELS,
52
+ default=MODELS[0],
53
+ allow_multiple=False,
54
+ ),
55
+ ],
56
+ [
57
+ gr.outputs.Chat(
58
+ label="Conversation",
59
+ label_icon="💬",
60
+ outputs=["text"],
61
+ max_length=500,
62
+ header_show_all=True,
63
+ header_show_user_name=True,
64
+ ),
65
+ gr.outputs.Textbox(label="Status", default="Status: Ready"),
66
+ gr.outputs.Button(label="🧹 新的对话"),
67
+ gr.outputs.Button(label="🔄 重新生成"),
68
+ gr.outputs.Button(label="🗑️ 删除最近一条对话"),
69
+ gr.outputs.Button(label="♻️ 总结对话"),
70
+ gr.outputs.Button(label="💾 保存对话"),
71
+ gr.outputs.Dropdown(
72
+ label="从列表中加载对话",
73
+ choices=get_history_names(plain=True),
74
+ default=get_history_names(plain=True)[0],
75
+ allow_multiple=False,
76
+ ),
77
+ gr.outputs.Slider(
78
+ label="Top-p (nucleus sampling)",
79
+ min_val=0.0,
80
+ max_val=1.0,
81
+ step=0.05,
82
+ default=1.0,
83
+ ),
84
+ gr.outputs.Slider(label="Temperature", min_val=0.0, max_val=5.0, step=0.1),
85
+ gr.outputs.Markdown(
86
+ label="最新生成到的token数量",
87
+ default="待定",
88
+ ),
89
+ gr.outputs.Dropdown(
90
+ label="选择Prompt模板集合文件",
91
+ choices=get_template_names(plain=True),
92
+ default=get_template_names(plain=True)[0],
93
+ allow_multiple=False,
94
+ ),
95
+ gr.outputs.Dropdown(
96
+ label="从Prompt模板中加载",
97
+ choices=load_template(get_template_names(plain=True)[0], mode=1),
98
+ default=0,
99
+ allow_multiple=False,
100
+ ),
101
+ gr.outputs.Textbox(label="System prompt", default=initial_prompt),
102
+ gr.outputs.Textbox(
103
+ label="设置保存文件名", default="对话历史记录", allow_copy=True
104
+ ),
105
+ ],
106
+ title="川虎ChatGPT 🚀",
107
+ example=[
108
+ "请输入文本...",
109
+ "你好啊",
110
+ "",
111
+ "",
112
+ "",
113
+ "",
114
+ 1.0,
115
+ 1.0,
116
+ True,
117
+ "gpt3",
118
+ ],
119
+ theme="compact",
120
+ )
121
 
122
+ if __name__ == "__main__":
123
+ gradio_interface.launch() # 默认启动本地服务器,并通过默认的IP地址和端口进行访问
124
+ # gradio_interface.launch(share=True) # 启动本地服务器,创建公开分享链接
125
+ # gradio_interface.launch(server_name="0.0.0.0", server_port=7860) # 自定义IP和端口
126
+ # gradio_interface.launch(
127
+ # server_name="0.0.0.0",
128
+ # server_port=7860,
129
+ # auth=("在这里填写用户名", "在这里填写密码"),
130
+ # ) # 设置用户名和密码,适用于Nginx反向代理