Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GUI with PyWebIO #329

Merged
merged 7 commits into from
May 1, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
GUI with PyWebIO
  • Loading branch information
taiyi747 committed May 1, 2023
commit 03dc49a5a9519fd6368bee2ea4f29f998eefc7af
58 changes: 58 additions & 0 deletions gui/pywebio-gui/pywebio-usesless.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import usesless,time
from pywebio import start_server,config
from pywebio.input import *
from pywebio.output import *
from pywebio.session import local
message_id = ""
def status():
try:
req = usesless.Completion.create(prompt="hello", parentMessageId=message_id)
print(f"Answer: {req['text']}")
put_success(f"Answer: {req['text']}",scope="body")
except:
put_error("Program Error",scope="body")

def ask(prompt):
req = usesless.Completion.create(prompt=prompt, parentMessageId=local.message_id)
rp=req['text']
local.message_id=req["id"]
print("AI:\n"+rp)
local.conversation.extend([
{"role": "user", "content": prompt},
{"role": "assistant", "content": rp}
])
print(local.conversation)
return rp

def msg():
while True:
text= input_group("You:",[textarea('You:',name='text',rows=3, placeholder='请输入问题')])
if not(bool(text)):
break
if not(bool(text["text"])):
continue
time.sleep(0.5)
put_code("You:"+text["text"],scope="body")
print("Question:"+text["text"])
with use_scope('foot'):
put_loading(color="info")
rp= ask(text["text"])
clear(scope="foot")
time.sleep(0.5)
put_markdown("Bot:\n"+rp,scope="body")
time.sleep(0.7)

@config(title="AIchat",theme="dark")
def main():
put_scope("heads")
with use_scope('heads'):
put_html("<h1><center>AI Chat</center></h1>")
put_scope("body")
put_scope("foot")
status()
local.conversation=[]
local.message_id=""
msg()

print("Click link to chat page")
start_server(main, port=8099,allowed_origins="*",auto_open_webbrowser=True,debug=True)