Files
tello-commander/brain/service.py
ALIHAN DIKEL 892547375c try sth
2023-05-19 03:07:32 +03:00

36 lines
1.2 KiB
Python

import random
import os, sys
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
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])
prompt.click(lambda x: gr.update(value=""), None, [""], queue=False)
demo.launch(server_name="0.0.0.0", server_port=8890, debug=True, )