33 lines
1.0 KiB
Python
33 lines
1.0 KiB
Python
import random
|
|
|
|
import gradio as gr
|
|
from loguru import logger
|
|
|
|
from brain.brain_openai import CloudChatBrain
|
|
|
|
|
|
def brain_commander(prompt, history):
|
|
brain.listen(channel="api", prompt=prompt)
|
|
brain.understand()
|
|
history.append({"role": "user", "content": prompt})
|
|
history.append({"role": "assistant", "content": brain.answer})
|
|
messages = [(history[i]["content"], history[i+1]["content"]) for i in range(0, len(history)-1, 2)]
|
|
brain.command()
|
|
return messages, history
|
|
|
|
|
|
brain = CloudChatBrain()
|
|
|
|
with gr.Blocks() as demo:
|
|
chatbot_ui = gr.Chatbot(label="drone flight with chatgpt as copilot")
|
|
state = gr.State([])
|
|
with gr.Row():
|
|
prompt = gr.Textbox(
|
|
show_label=True,
|
|
label="what should I do now? (enter q for emergency)",
|
|
placeholder="Enter flight command and press enter")\
|
|
.style(container=True)
|
|
prompt.submit(brain_commander, [prompt, state], [chatbot_ui, state])
|
|
|
|
|
|
demo.launch(server_name="0.0.0.0", server_port=8890, debug=True) |