|
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_name="0.0.0.0", server_port=7860) |
|
|
|
soar_agent.kill() |
|
|