codeEscounciousness dotmet commited on
Commit
71cbbdc
0 Parent(s):

Duplicate from dotmet/chatgpt_webui

Browse files

Co-authored-by: HuggingMat <dotmet@users.noreply.huggingface.co>

Files changed (6) hide show
  1. .gitattributes +34 -0
  2. LICENSE +28 -0
  3. README.md +16 -0
  4. app.py +146 -0
  5. requirements.txt +2 -0
  6. style.css +10 -0
.gitattributes ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ *.7z filter=lfs diff=lfs merge=lfs -text
2
+ *.arrow filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.bz2 filter=lfs diff=lfs merge=lfs -text
5
+ *.ckpt filter=lfs diff=lfs merge=lfs -text
6
+ *.ftz filter=lfs diff=lfs merge=lfs -text
7
+ *.gz filter=lfs diff=lfs merge=lfs -text
8
+ *.h5 filter=lfs diff=lfs merge=lfs -text
9
+ *.joblib filter=lfs diff=lfs merge=lfs -text
10
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
+ *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
+ *.model filter=lfs diff=lfs merge=lfs -text
13
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
14
+ *.npy filter=lfs diff=lfs merge=lfs -text
15
+ *.npz filter=lfs diff=lfs merge=lfs -text
16
+ *.onnx filter=lfs diff=lfs merge=lfs -text
17
+ *.ot filter=lfs diff=lfs merge=lfs -text
18
+ *.parquet filter=lfs diff=lfs merge=lfs -text
19
+ *.pb filter=lfs diff=lfs merge=lfs -text
20
+ *.pickle filter=lfs diff=lfs merge=lfs -text
21
+ *.pkl filter=lfs diff=lfs merge=lfs -text
22
+ *.pt filter=lfs diff=lfs merge=lfs -text
23
+ *.pth filter=lfs diff=lfs merge=lfs -text
24
+ *.rar filter=lfs diff=lfs merge=lfs -text
25
+ *.safetensors filter=lfs diff=lfs merge=lfs -text
26
+ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
+ *.tar.* filter=lfs diff=lfs merge=lfs -text
28
+ *.tflite filter=lfs diff=lfs merge=lfs -text
29
+ *.tgz filter=lfs diff=lfs merge=lfs -text
30
+ *.wasm filter=lfs diff=lfs merge=lfs -text
31
+ *.xz filter=lfs diff=lfs merge=lfs -text
32
+ *.zip filter=lfs diff=lfs merge=lfs -text
33
+ *.zst filter=lfs diff=lfs merge=lfs -text
34
+ *tfevents* filter=lfs diff=lfs merge=lfs -text
LICENSE ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ BSD 3-Clause License
2
+
3
+ Copyright (c) 2023, Mension
4
+
5
+ Redistribution and use in source and binary forms, with or without
6
+ modification, are permitted provided that the following conditions are met:
7
+
8
+ 1. Redistributions of source code must retain the above copyright notice, this
9
+ list of conditions and the following disclaimer.
10
+
11
+ 2. Redistributions in binary form must reproduce the above copyright notice,
12
+ this list of conditions and the following disclaimer in the documentation
13
+ and/or other materials provided with the distribution.
14
+
15
+ 3. Neither the name of the copyright holder nor the names of its
16
+ contributors may be used to endorse or promote products derived from
17
+ this software without specific prior written permission.
18
+
19
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
README.md ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: bsd-2-clause
3
+ title: ChatGPT WebUI
4
+ sdk: gradio
5
+ emoji: 👀
6
+ colorFrom: yellow
7
+ colorTo: red
8
+ app_file: app.py
9
+ duplicated_from: dotmet/chatgpt_webui
10
+ ---
11
+ # chatgpt_webui
12
+ Build an WebUI of ChatGPT with multiple authentication method using Gradio and revChatGPT
13
+
14
+ clone this space to run for your own account
15
+
16
+ ### This project will not SAVE/DISPLAY/SHARE the ACCOUNT INFO of any user!!
app.py ADDED
@@ -0,0 +1,146 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from revChatGPT.V1 import Chatbot
3
+
4
+ import argparse
5
+
6
+ #You can setup login information here, or login in from UI
7
+
8
+ # If you want to use Email/Password to login, put your account information here
9
+ email = ""
10
+ password = ""
11
+
12
+ # If you have an access token, put your access token here
13
+ access_token = ""
14
+
15
+ # If you have a session token, put your session token here
16
+ session_token = ""
17
+
18
+
19
+ def get_args():
20
+ parser = argparse.ArgumentParser(description='Command line args.')
21
+ parser.add_argument(
22
+ '--no_markdown',
23
+ action='store_true',
24
+ help='Disable the markdown of the web UI.',)
25
+ return parser.parse_args()
26
+
27
+ def is_google_colab():
28
+ try:
29
+ import google.colab
30
+ return True
31
+ except:
32
+ return False
33
+
34
+ chatbot = None
35
+
36
+ def configure_chatbot(method, info):
37
+
38
+ if method=="Email/Password":
39
+ email, password = info.split()
40
+ elif method=="Access token":
41
+ access_token = info
42
+ elif method=="Session token":
43
+ session_token = info
44
+
45
+ config = {}
46
+ if email and password:
47
+ config.update({"email": email,
48
+ "password": password})
49
+ elif access_token:
50
+ config.update({"access_token": access_token})
51
+ elif session_token:
52
+ config.update({"session_token": session_token})
53
+
54
+ global chatbot
55
+ try:
56
+ chatbot = Chatbot(config=config)
57
+ except:
58
+ chatbot = None
59
+
60
+ login_method = ['Email/Password',
61
+ 'Access token',
62
+ 'Session token',
63
+ ]
64
+
65
+ def ask_bot(prompt):
66
+ message = ""
67
+ if chatbot:
68
+ for data in chatbot.ask(prompt):
69
+ message = data["message"]
70
+ else:
71
+ message = "The chatbot is not set up properly! Try to login again."
72
+ return parse_text(message)
73
+
74
+ def parse_text(text):
75
+ lines = text.split("\n")
76
+ for i,line in enumerate(lines):
77
+ if "```" in line:
78
+ items = line.split('`')
79
+ if items[-1]:
80
+ lines[i] = f'<pre><code class="{items[-1]}">'
81
+ else:
82
+ lines[i] = f'</code></pre>'
83
+ else:
84
+ if i>0:
85
+ line = line.replace("<", "&lt;")
86
+ line = line.replace(">", "&gt;")
87
+ lines[i] = '<br/>'+line.replace(" ", "&nbsp;")
88
+ return "".join(lines)
89
+
90
+ def chat_clone(inputs, history):
91
+ history = history or []
92
+ output = ask_bot(inputs)
93
+ history.append((inputs, output))
94
+ return history, history
95
+
96
+ if ((email and password) or access_token or session_token):
97
+ css = "style.css"
98
+ else:
99
+ css = None
100
+
101
+ with gr.Blocks(css=css) as demo:
102
+
103
+ args = get_args()
104
+
105
+ if not args.no_markdown:
106
+ gr.Markdown("""<h1><center>ChatGPT BOT build by revChatGPT & Gradio</center></h1>""")
107
+ gr.Markdown("#### Author: [dotmet](https://github.com/dotmet) Github link:[ChatGPTWEB](https://github.com/dotmet/chatgpt_webui)")
108
+ gr.Markdown("I have used my own OpenAI account for this demo,you can skip Login and try chat.")
109
+ gr.Markdown("Duplicate this space and run for your own account: [chat_gpt_web](https://huggingface.co/spaces/dotmet/chatgpt_webui?duplicate=true).")
110
+
111
+ if not ((email and password) or access_token or session_token):
112
+ if not args.no_markdown:
113
+ gr.Markdown("""<h2>Login to OpenAI</h2>""")
114
+ with gr.Row():
115
+ with gr.Group():
116
+ method = gr.Dropdown(label="Login Method", choices=login_method)
117
+ info = gr.Textbox(placeholder="email password/access_token/session_token", label="Login Information (choose login method first)")
118
+ with gr.Row():
119
+ login = gr.Button("Login")
120
+ login.click(configure_chatbot, inputs=[method, info])
121
+ else:
122
+ if email and password:
123
+ method = "Email/Password"
124
+ info = email + " " + password
125
+ elif access_token:
126
+ method = "Access token"
127
+ info = access_token
128
+ elif session_token:
129
+ method = "Session token"
130
+ info = session_token
131
+ configure_chatbot(method, info)
132
+
133
+ if not args.no_markdown:
134
+ gr.Markdown("""<h2>Start Chatting ...</h2>""")
135
+
136
+ chatbot1 = gr.Chatbot(elem_id="chatbot", show_label=False)
137
+ state = gr.State([])
138
+ message = gr.Textbox(placeholder="Chat here", label="Human: ")
139
+ message.submit(chat_clone, inputs=[message, state], outputs=[chatbot1, state])
140
+ message.submit(lambda :"", None, message)
141
+
142
+ submit = gr.Button("SEND")
143
+ submit.click(chat_clone, inputs=[message, state], outputs=[chatbot1, state])
144
+ submit.click(lambda :"", None, message)
145
+
146
+ demo.launch(debug = True, share=is_google_colab())
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ revChatGPT
2
+ gradio
style.css ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ .gradio-container {
2
+ max-width: 100%;
3
+ max-height: 100%;
4
+ }
5
+
6
+ [id$=chatbot] > div{
7
+ border: 0;
8
+ height: 70vh;
9
+ overflow-y: auto;
10
+ }