Files
tello-commander/brain/service.py

40 lines
1.5 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
from settings.config import settings
def brain_commander(prompt, history):
brain.listen(channel="api", prompt=prompt)
if not brain.is_emergency(brain.cmd_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(title="drone commander", analytics_enabled=False) as webui:
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",
interactive=True)\
.style(container=True)
prompt.submit(brain_commander, [prompt, state], [chatbot_ui, state], queue=False)
prompt.submit(lambda x: gr.update(value=""), [state], [prompt], queue=False)
#webui.queue(concurrency_count=5)
webui.launch(server_name="0.0.0.0", server_port=8890, debug=False, auth=(settings.USERNAME, settings.PASSW))