Merge pull request #221 from tyfiero/Add-qr-code-to-expose-server-url
Add qr code
This commit is contained in:
commit
5d8757bbec
File diff suppressed because it is too large
Load Diff
|
@ -33,6 +33,7 @@ dateparser = "^1.2.0"
|
||||||
pytimeparse = "^1.1.8"
|
pytimeparse = "^1.1.8"
|
||||||
python-crontab = "^3.0.0"
|
python-crontab = "^3.0.0"
|
||||||
inquirer = "^3.2.4"
|
inquirer = "^3.2.4"
|
||||||
|
pyqrcode = "^1.2.1"
|
||||||
|
|
||||||
[build-system]
|
[build-system]
|
||||||
requires = ["poetry-core"]
|
requires = ["poetry-core"]
|
||||||
|
|
|
@ -2,12 +2,14 @@ import os
|
||||||
import subprocess
|
import subprocess
|
||||||
import re
|
import re
|
||||||
import shutil
|
import shutil
|
||||||
|
import pyqrcode
|
||||||
import time
|
import time
|
||||||
from ..utils.print_markdown import print_markdown
|
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...")
|
print_markdown(f"Exposing server to the internet...")
|
||||||
|
|
||||||
|
server_url = ""
|
||||||
if tunnel_method == "bore":
|
if tunnel_method == "bore":
|
||||||
try:
|
try:
|
||||||
output = subprocess.check_output('command -v bore', shell=True)
|
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
|
break
|
||||||
if "listening at bore.pub:" in line:
|
if "listening at bore.pub:" in line:
|
||||||
remote_port = re.search('bore.pub:([0-9]*)', line).group(1)
|
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}")
|
print_markdown(f"Your server is being hosted at the following URL: bore.pub:{remote_port}")
|
||||||
break
|
break
|
||||||
|
|
||||||
|
@ -53,7 +56,7 @@ def create_tunnel(tunnel_method='ngrok', server_host='localhost', server_port=10
|
||||||
if match:
|
if match:
|
||||||
found_url = True
|
found_url = True
|
||||||
remote_url = match.group(0).replace('your url is: ', '')
|
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}")
|
print(f"\nYour server is being hosted at the following URL: {remote_url}")
|
||||||
break # Exit the loop once the URL is found
|
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
|
# 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} --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
|
# Initially, no URL is found
|
||||||
found_url = False
|
found_url = False
|
||||||
|
@ -87,9 +90,16 @@ def create_tunnel(tunnel_method='ngrok', server_host='localhost', server_port=10
|
||||||
if match:
|
if match:
|
||||||
found_url = True
|
found_url = True
|
||||||
remote_url = match.group(0)
|
remote_url = match.group(0)
|
||||||
|
server_url = remote_url
|
||||||
print(f"\nYour server is being hosted at the following 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
|
break # Exit the loop once the URL is found
|
||||||
|
|
||||||
if not found_url:
|
if not found_url:
|
||||||
print("Failed to extract the ngrok tunnel URL. Please check ngrok's output for details.")
|
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"),
|
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"),
|
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(
|
_run(
|
||||||
|
@ -59,7 +61,8 @@ def run(
|
||||||
temperature=temperature,
|
temperature=temperature,
|
||||||
tts_service=tts_service,
|
tts_service=tts_service,
|
||||||
stt_service=stt_service,
|
stt_service=stt_service,
|
||||||
local=local
|
local=local,
|
||||||
|
qr=qr
|
||||||
)
|
)
|
||||||
|
|
||||||
def _run(
|
def _run(
|
||||||
|
@ -87,7 +90,9 @@ def _run(
|
||||||
|
|
||||||
stt_service: str = "openai",
|
stt_service: str = "openai",
|
||||||
|
|
||||||
local: bool = False
|
local: bool = False,
|
||||||
|
|
||||||
|
qr: bool = False
|
||||||
):
|
):
|
||||||
|
|
||||||
if local:
|
if local:
|
||||||
|
@ -115,7 +120,7 @@ def _run(
|
||||||
server_thread.start()
|
server_thread.start()
|
||||||
|
|
||||||
if expose:
|
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()
|
tunnel_thread.start()
|
||||||
|
|
||||||
if client:
|
if client:
|
||||||
|
|
Loading…
Reference in New Issue