Skip to content

Commit

Permalink
Moving Browser Related files into it's own directory (pytorch#845)
Browse files Browse the repository at this point in the history
* Initial move of browser GUI related files

* Fix css reference issue

* Remove moved file
  • Loading branch information
Jack-Khuu authored and malfet committed Jul 17, 2024
1 parent 8899d4c commit 8993774
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 28 deletions.
37 changes: 37 additions & 0 deletions browser/browser.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import subprocess
import sys


def main(args):

# Directory Containing the server file "chat_in_browser.py"
server_dir = "browser"

# Look for port from cmd args. Default to 5000 if not found.
port = 5000
i = 2
while i < len(sys.argv):
if sys.argv[i] == "--port":
if i + 1 < len(sys.argv):
# Extract the value and remove '--port' and the value from sys.argv
port = sys.argv[i + 1]
del sys.argv[i : i + 2]
break
else:
i += 1

# Construct arguments for the flask app minus 'browser' command
# plus '--chat'
args_plus_chat = ["'{}'".format(s) for s in sys.argv[1:] if s != "browser"] + [
'"--chat"'
]
formatted_args = ", ".join(args_plus_chat)
command = [
"flask",
"--app",
f"{server_dir}/chat_in_browser:create_app(" + formatted_args + ")",
"run",
"--port",
f"{port}",
]
subprocess.run(command)
File renamed without changes.
File renamed without changes.
File renamed without changes.
31 changes: 3 additions & 28 deletions torchchat.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,34 +67,9 @@
args.gui = True
check_args(args, "browser")

# Look for port from cmd args. Default to 5000 if not found.
port = 5000
i = 2
while i < len(sys.argv):
if sys.argv[i] == "--port":
if i + 1 < len(sys.argv):
# Extract the value and remove '--port' and the value from sys.argv
port = sys.argv[i + 1]
del sys.argv[i : i + 2]
break
else:
i += 1

# Construct arguments for the flask app minus 'browser' command
# plus '--chat'
args_plus_chat = ["'{}'".format(s) for s in sys.argv[1:] if s != "browser"] + [
'"--chat"'
]
formatted_args = ", ".join(args_plus_chat)
command = [
"flask",
"--app",
"chat_in_browser:create_app(" + formatted_args + ")",
"run",
"--port",
f"{port}",
]
subprocess.run(command)
from browser.browser import main as browser_main

browser_main(args)
elif args.command == "download":
check_args(args, "download")
from download import download_main
Expand Down

0 comments on commit 8993774

Please sign in to comment.