Spaces:
Runtime error
Runtime error
File size: 2,687 Bytes
8c40b3a 354893a 8c40b3a 3168540 8c40b3a 3168540 8c40b3a e9bb5df 4c118b8 30d689e 04d6377 30d689e 04d6377 8c40b3a dc64f5a 8c40b3a dc64f5a 8c40b3a 6172969 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
import gradio as gr
from revChatGPT.V1 import Chatbot
#You can setup login information here, or login in from UI
global email, password access_token, session_token
email = None
password = None
access_token = None
session_token = None
def configure_chatbot(method, info):
if method=="Email/Password":
email, password = info.split()
elif method=="Access token":
access_token = info
elif method=="Session token":
session_token = info
config = {}
if email and password:
config.update({"email": email,
"password": password})
elif access_token:
config.update({"access_token": access_token})
elif session_token:
config.update({"session_token": session_token})
global chatbot
chatbot = Chatbot(config=config)
login_method = ['Email/Password',
'Access token',
'Session token',
]
def ask_bot(prompt):
message = ""
for data in chatbot.ask(prompt):
message = data["message"]
return message
def chatgpt_clone(inputs, history):
history = history or []
# s = list(sum(history, ()))
# s.append(inputs)
# inp = ' '.join(s)
# print(inp)
output = ask_bot(inputs)
history.append((inputs, output))
return history, history
with gr.Blocks() as demo:
gr.Markdown("""<h1><center>ChatGPT BOT build by revChatGPT & Gradio</center></h1>
""")
gr.Markdown(
"#### Author: [dotmet](https://github.com/dotmet) Github link:[ChatGPTWEB](https://github.com/dotmet/chatgpt_webui)")
gr.Markdown(
"I have used my own OpenAI account for this demo,you can skip Login and try chat.")
gr.Markdown(
"Duplicate this space and run for your own account: [demo](https://huggingface.co/spaces/dotmet/chatgpt_webui?duplicate=true).")
if not ((email and password) or access_token or session_token):
gr.Markdown("""<h2>Login to OpenAI</h2>""")
with gr.Row():
with gr.Group():
method = gr.Dropdown(label="Login Method", choices=login_method)
info = gr.Textbox(placeholder="email password/access_token/session_token", label="Login Information")
with gr.Row():
login = gr.Button("Login")
login.click(configure_chatbot, inputs=[method, info])
gr.Markdown("""<h2>Start Chatting ...</h2>""")
chatbot1 = gr.Chatbot()
message = gr.Textbox(placeholder="Chat here")
state = gr.State()
submit = gr.Button("SEND")
submit.click(chatgpt_clone, inputs=[message, state], outputs=[chatbot1, state])
demo.launch(debug = True, share=False) |