Add qr code
This commit is contained in:
parent
3144034362
commit
1c8d614e79
File diff suppressed because it is too large
Load Diff
|
@ -33,6 +33,7 @@ dateparser = "^1.2.0"
|
|||
pytimeparse = "^1.1.8"
|
||||
python-crontab = "^3.0.0"
|
||||
inquirer = "^3.2.4"
|
||||
pyqrcode = "^1.2.1"
|
||||
|
||||
[build-system]
|
||||
requires = ["poetry-core"]
|
||||
|
|
|
@ -2,12 +2,14 @@ import os
|
|||
import subprocess
|
||||
import re
|
||||
import shutil
|
||||
import pyqrcode
|
||||
import time
|
||||
from ..utils.print_markdown import print_markdown
|
||||
|
||||
def create_tunnel(tunnel_method='ngrok', server_host='localhost', server_port=10001):
|
||||
def create_tunnel(tunnel_method='ngrok', server_host='localhost', server_port=10001, qr=False):
|
||||
print_markdown(f"Exposing server to the internet...")
|
||||
|
||||
server_url = ""
|
||||
if tunnel_method == "bore":
|
||||
try:
|
||||
output = subprocess.check_output('command -v bore', shell=True)
|
||||
|
@ -27,6 +29,7 @@ def create_tunnel(tunnel_method='ngrok', server_host='localhost', server_port=10
|
|||
break
|
||||
if "listening at bore.pub:" in line:
|
||||
remote_port = re.search('bore.pub:([0-9]*)', line).group(1)
|
||||
server_url = f"bore.pub:{remote_port}"
|
||||
print_markdown(f"Your server is being hosted at the following URL: bore.pub:{remote_port}")
|
||||
break
|
||||
|
||||
|
@ -53,7 +56,7 @@ def create_tunnel(tunnel_method='ngrok', server_host='localhost', server_port=10
|
|||
if match:
|
||||
found_url = True
|
||||
remote_url = match.group(0).replace('your url is: ', '')
|
||||
|
||||
server_url = remote_url
|
||||
print(f"\nYour server is being hosted at the following URL: {remote_url}")
|
||||
break # Exit the loop once the URL is found
|
||||
|
||||
|
@ -71,7 +74,7 @@ def create_tunnel(tunnel_method='ngrok', server_host='localhost', server_port=10
|
|||
|
||||
# If ngrok is installed, start it on the specified port
|
||||
# process = subprocess.Popen(f'ngrok http {server_port} --log=stdout', shell=True, stdout=subprocess.PIPE)
|
||||
process = subprocess.Popen(f'ngrok http {server_port} --scheme http,https --log=stdout', shell=True, stdout=subprocess.PIPE)
|
||||
process = subprocess.Popen(f'ngrok http {server_port} --scheme http,https --domain=marten-advanced-dragon.ngrok-free.app --log=stdout', shell=True, stdout=subprocess.PIPE)
|
||||
|
||||
# Initially, no URL is found
|
||||
found_url = False
|
||||
|
@ -87,9 +90,16 @@ def create_tunnel(tunnel_method='ngrok', server_host='localhost', server_port=10
|
|||
if match:
|
||||
found_url = True
|
||||
remote_url = match.group(0)
|
||||
|
||||
server_url = remote_url
|
||||
print(f"\nYour server is being hosted at the following URL: {remote_url}")
|
||||
break # Exit the loop once the URL is found
|
||||
|
||||
|
||||
if not found_url:
|
||||
print("Failed to extract the ngrok tunnel URL. Please check ngrok's output for details.")
|
||||
|
||||
if server_url and qr:
|
||||
text = pyqrcode.create(remote_url)
|
||||
print(text.terminal(quiet_zone=1))
|
||||
|
||||
return server_url
|
||||
|
||||
|
|
|
@ -39,6 +39,8 @@ def run(
|
|||
stt_service: str = typer.Option("openai", "--stt-service", help="Specify the STT service"),
|
||||
|
||||
local: bool = typer.Option(False, "--local", help="Use recommended local services for LLM, STT, and TTS"),
|
||||
|
||||
qr: bool = typer.Option(False, "--qr", help="Print the QR code for the server URL")
|
||||
):
|
||||
|
||||
_run(
|
||||
|
@ -59,7 +61,8 @@ def run(
|
|||
temperature=temperature,
|
||||
tts_service=tts_service,
|
||||
stt_service=stt_service,
|
||||
local=local
|
||||
local=local,
|
||||
qr=qr
|
||||
)
|
||||
|
||||
def _run(
|
||||
|
@ -87,7 +90,9 @@ def _run(
|
|||
|
||||
stt_service: str = "openai",
|
||||
|
||||
local: bool = False
|
||||
local: bool = False,
|
||||
|
||||
qr: bool = False
|
||||
):
|
||||
|
||||
if local:
|
||||
|
@ -115,7 +120,7 @@ def _run(
|
|||
server_thread.start()
|
||||
|
||||
if expose:
|
||||
tunnel_thread = threading.Thread(target=create_tunnel, args=[tunnel_service, server_host, server_port])
|
||||
tunnel_thread = threading.Thread(target=create_tunnel, args=[tunnel_service, server_host, server_port, qr])
|
||||
tunnel_thread.start()
|
||||
|
||||
if client:
|
||||
|
|
Loading…
Reference in New Issue