File size: 3,175 Bytes
6fcb283
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e7f77e9
6fcb283
 
e7f77e9
 
6fcb283
 
 
 
 
9cd0bf1
6fcb283
9cd0bf1
e7f77e9
6fcb283
 
 
 
 
 
 
 
 
 
 
a93cec5
 
 
 
 
6fcb283
 
 
 
 
 
 
 
 
 
e7f77e9
6fcb283
 
 
fee0019
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
"""
ChatGPT + Robotics Gradio demo.
Author: Sai Vemprala
For details, please check out our blog post: https://aka.ms/ChatGPT-Robotics, and our paper:
https://www.microsoft.com/en-us/research/uploads/prod/2023/02/ChatGPT___Robotics.pdf
In this demo, we provide a quick way to interact with ChatGPT in robotics settings using some custom prompts.
As seen in our paper, we provide prompts for several scenarios: robot manipulation, drone navigation 
(in a simulated setting (airsim) as well as real life), and embodied AI. embodied_agent_closed_loop is an
experimental setting where observations from a scene can be described to ChatGPT as text.
Parts of the code were inspired by https://huggingface.co/spaces/VladislavMotkov/chatgpt_webui/
"""

import gradio as gr
from revChatGPT.V1 import Chatbot
import glob, os

access_token = None


def parse_text(text):
    lines = text.split("\n")
    for i, line in enumerate(lines):
        if "```" in line:
            items = line.split("`")
            if items[-1]:
                lines[i] = f'<pre><code class="{items[-1]}">'
            else:
                lines[i] = f"</code></pre>"
        else:
            if i > 0:
                lines[i] = "<br/>" + line.replace(" ", "&nbsp;")
    return "".join(lines)


def configure_chatgpt(info):
    access_token = info
    config = {}
    config.update({"access_token": access_token})

    global chatgpt
    chatgpt = Chatbot(config=config)


def ask(prompt):
    message = ""
    for data in chatgpt.ask(prompt):
        message = data["message"]
    return parse_text(message)


def query_chatgpt(inputs, history, message):
    history = history or []
    output = ask(inputs)
    history.append((inputs, output))
    return history, history, ""


def initialize_prompt(history):
    history = history or []

    output = ask('Hello ChatGPT!')
    history.append(("<ORIGINAL PROMPT>", output))

    return history, history


with gr.Blocks() as demo:
    gr.Markdown("""<h3><center>Free ChatGPT</center></h3>""")
    gr.Markdown(
        """This is a free version of chatgpt built by @techwithanirudh.
        """
    )

    if not access_token:
        gr.Markdown("""<h4>Login to ChatGPT</h4>""")
        with gr.Row():
            with gr.Group():
                info = gr.Textbox(placeholder="Enter access token here (from https://chat.openai.com/api/auth/session)", label="ChatGPT Login")
                with gr.Row():
                    login = gr.Button("Login")
                    login.click(configure_chatgpt, inputs=[info])


    gr.Markdown("""<h4>Initialize ChatGPT</h4>""")

    initialize = gr.Button(value="Initialize")

    gr.Markdown("""<h4>Conversation</h4>""")
    chatgpt_robot = gr.Chatbot()
    message = gr.Textbox(
        placeholder="Enter query",
        label="",
        info='Talk to ChatGPT and ask it to help with specific tasks! For example, "take off and reach an altitude of five meters"',
    )

    state = gr.State()

    initialize.click(fn=initialize_prompt, inputs=[state], outputs=[chatgpt_robot, state])

    message.submit(query_chatgpt, inputs=[message, state], outputs=[chatgpt_robot, state, message])

    demo.launch()