File size: 1,174 Bytes
2130399
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import sys
import gradio as gr

from pysoarlib import SoarClient
from soar_io import GeneralSoarIOConnector

class SoarAgent():
    def __init__(self):
        self.client, self.agent_io = self.make_soar_agent()
        print("Agent created.")

    def make_soar_agent(self):
        client = SoarClient(write_to_stdout=True,remote_connection=False)
        myIOConnector = GeneralSoarIOConnector(client)
        client.add_connector("generalIO", myIOConnector)
        client.connect()

        return client, myIOConnector

    def execute_command(self, cmd):
        try:
            self.client.execute_command(str(cmd))
        except:
            print(" * ERROR: Caught exception from Soar", file=sys.stderr)

    def get_output(self):
        return self.agent_io.get_agent_output()

    def kill(self):
        self.client.kill()
        print("Agent shut down.")


soar_agent = SoarAgent()

def run_soar(cmd):
    soar_agent.execute_command(cmd)
    agent_output = soar_agent.get_output()
    return str(agent_output)

gr.Interface(fn=run_soar,
            inputs=["text"],
            outputs=["text"]).launch(inbrowser=True, server_port=7860)

soar_agent.kill()