import gradio as gr from revChatGPT.V1 import Chatbot import argparse #You can setup login information here, or login in from UI # If you want to use Email/Password to login, put your account information here email = "" password = "" # If you have an access token, put your access token here access_token = "" # If you have a session token, put your session token here session_token = "" def get_args(): parser = argparse.ArgumentParser(description='Command line args.') parser.add_argument( '--no_markdown', action='store_true', help='Disable the markdown of the web UI.',) return parser.parse_args() def is_google_colab(): try: import google.colab return True except: return False chatbot = 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 try: chatbot = Chatbot(config=config) except: chatbot = None login_method = ['Email/Password', 'Access token', 'Session token', ] def ask_bot(prompt): message = "" if chatbot: for data in chatbot.ask(prompt): message = data["message"] else: message = "The chatbot is not set up properly! Try to login again." return parse_text(message) def parse_text(text): lines = text.split("\n") for i,line in enumerate(lines): if "```" in line: items = line.split('`') if items[-1]: lines[i] = f'
'
else:
lines[i] = f''
else:
if i>0:
line = line.replace("<", "<")
line = line.replace(">", ">")
lines[i] = '