Skip to content

Commit

Permalink
Merge pull request #105 from fractalego/new-version
Browse files Browse the repository at this point in the history
updated main script for webserver
  • Loading branch information
fractalego committed Jul 20, 2024
2 parents fe4c35f + 3d94b96 commit e9d5709
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 71 deletions.
71 changes: 37 additions & 34 deletions wafl/runners/run_web_and_audio_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,43 +19,46 @@
_logger = LocalFileLogger()


def run_app():
@app.route("/create_new_instance", methods=["POST"])
def create_new_instance():
conversation_id = random.randint(0, sys.maxsize)
result = create_scheduler_and_webserver_loop(conversation_id)
add_new_routes(conversation_id, result["web_server_handler"])
thread = threading.Thread(target=result["scheduler"].run)
thread.start()
return redirect(f"{conversation_id}/index")
@app.route("/create_new_instance", methods=["POST"])
def create_new_instance():
conversation_id = random.randint(0, sys.maxsize)
result = create_scheduler_and_webserver_loop(conversation_id)
add_new_routes(conversation_id, result["web_server_handler"])
thread = threading.Thread(target=result["scheduler"].run)
thread.start()
return redirect(f"{conversation_id}/index")


@app.route("/")
async def index():
return render_template("selector.html")


@app.route("/")
async def index():
return render_template("selector.html")
def create_scheduler_and_webserver_loop(conversation_id):
config = Configuration.load_local_config()
interface = ListInterface([VoiceInterface(config), QueueInterface()])
interface.activate()
conversation_events = ConversationEvents(
config=config,
interface=interface,
logger=_logger,
)
conversation_loop = ConversationHandler(
interface,
conversation_events,
_logger,
activation_word=config.get_value("waking_up_word"),
)
web_handler = WebHandler(
interface, config, conversation_id, conversation_events
)
return {
"scheduler": Scheduler([conversation_loop, web_handler]),
"web_server_handler": web_handler,
}

def create_scheduler_and_webserver_loop(conversation_id):
config = Configuration.load_local_config()
interface = ListInterface([VoiceInterface(config), QueueInterface()])
interface.activate()
conversation_events = ConversationEvents(
config=config,
interface=interface,
logger=_logger,
)
conversation_loop = ConversationHandler(
interface,
conversation_events,
_logger,
activation_word=config.get_value("waking_up_word"),
)
web_handler = WebHandler(
interface, config, conversation_id, conversation_events
)
return {
"scheduler": Scheduler([conversation_loop, web_handler]),
"web_server_handler": web_handler,
}

def run_app():
app.run(
host="0.0.0.0",
port=Configuration.load_local_config().get_value("frontend_port"),
Expand Down
77 changes: 40 additions & 37 deletions wafl/runners/run_web_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,46 +19,49 @@
_logger = LocalFileLogger()


def run_server_only_app():
@app.route("/create_new_instance", methods=["POST"])
def create_new_instance():
conversation_id = str(random.randint(0, sys.maxsize))
result = create_scheduler_and_webserver_loop(conversation_id)
add_new_routes(conversation_id, result["web_server_handler"])
thread = threading.Thread(target=result["scheduler"].run)
thread.start()
return redirect(f"{conversation_id}/index")
def create_scheduler_and_webserver_loop(conversation_id):
config = Configuration.load_local_config()
interface = QueueInterface()
interface.activate()
conversation_events = ConversationEvents(
config=config,
interface=interface,
logger=_logger,
)
conversation_loop = ConversationHandler(
interface,
conversation_events,
_logger,
activation_word="",
max_misses=-1,
deactivate_on_closed_conversation=False,
)
asyncio.run(interface.output("Hello. How may I help you?"))
web_handler = WebHandler(
interface, config, conversation_id, conversation_events
)
return {
"scheduler": Scheduler([conversation_loop, web_handler]),
"web_server_handler": web_handler,
}

@app.route("/")
async def index():
return render_template("selector.html")

def create_scheduler_and_webserver_loop(conversation_id):
config = Configuration.load_local_config()
interface = QueueInterface()
interface.activate()
conversation_events = ConversationEvents(
config=config,
interface=interface,
logger=_logger,
)
conversation_loop = ConversationHandler(
interface,
conversation_events,
_logger,
activation_word="",
max_misses=-1,
deactivate_on_closed_conversation=False,
)
asyncio.run(interface.output("Hello. How may I help you?"))
web_handler = WebHandler(
interface, config, conversation_id, conversation_events
)
return {
"scheduler": Scheduler([conversation_loop, web_handler]),
"web_server_handler": web_handler,
}
@app.route("/create_new_instance", methods=["POST"])
def create_new_instance():
conversation_id = str(random.randint(0, sys.maxsize))
result = create_scheduler_and_webserver_loop(conversation_id)
add_new_routes(conversation_id, result["web_server_handler"])
thread = threading.Thread(target=result["scheduler"].run)
thread.start()
return redirect(f"{conversation_id}/index")


@app.route("/")
async def index():
return render_template("selector.html")


def run_server_only_app():
app.run(
host="0.0.0.0",
port=Configuration.load_local_config().get_value("frontend_port"),
Expand Down

0 comments on commit e9d5709

Please sign in to comment.