33 lines
1010 B
Python
33 lines
1010 B
Python
import random
|
|
|
|
import gradio as gr
|
|
from loguru import logger
|
|
|
|
|
|
|
|
def make_completion(history):
|
|
return "ok"
|
|
|
|
def answer(input, history):
|
|
history.append({"role": "user", "content": input})
|
|
response = random.choice(["How are you?", "I love you", "I'm very hungry"])
|
|
history.append({"role": "assistant", "content": response})
|
|
messages = [(history[i]["content"], history[i+1]["content"]) for i in range(0, len(history)-1, 2)]
|
|
logger.debug(history)
|
|
return messages, history
|
|
|
|
|
|
|
|
with gr.Blocks() as demo:
|
|
chatbot = gr.Chatbot(label="Fly my drone with chatGPT as copilot")
|
|
state = gr.State([])
|
|
with gr.Row():
|
|
prompt = gr.Textbox(
|
|
show_label=True,
|
|
label="what should I do now?\n(enter q for emergency)",
|
|
placeholder="Enter text and press enter")\
|
|
.style(container=True)
|
|
prompt.submit(answer, [prompt, state], [chatbot, state])
|
|
|
|
|
|
demo.launch(server_name="0.0.0.0", server_port=8890, debug=True) |