mirror of
https://github.com/gradio-app/gradio.git
synced 2025-02-17 11:29:58 +08:00
reload-dev-mode (#1370)
* reload-dev-mode - add dev reload mode * reload-dev-mode - support reload mode from different directories as well * reload-dev-mode - add file reload to the dev-reload-mode * Update contributing * Update CONTRIBUTING.md Co-authored-by: Abubakar Abid <abubakar@huggingface.co> * reload-dev-mode - fetch gradio_folder with inspect, allowing running in reload dev mode from any directory - unite user and dev reload mode Co-authored-by: Abubakar Abid <abubakar@huggingface.co>
This commit is contained in:
parent
3a7f9a3b1a
commit
fc054a16ab
@ -40,6 +40,11 @@ bash scripts/create_test_requirements.sh
|
||||
bash scripts/install_test_requirements.sh
|
||||
```
|
||||
|
||||
* You can run gradio scripts in developer reload mode which will watch for changes in the `gradio` folder and reload the app if changes are made.
|
||||
```
|
||||
gradio-dev app.py
|
||||
```
|
||||
|
||||
* Run the tests
|
||||
|
||||
```
|
||||
|
@ -1,35 +0,0 @@
|
||||
# Contains the function that runs when `gradio` is called from the command line. Specifically, allows
|
||||
# $ gradio app.py to run app.py in development mode where any changes reload the script.
|
||||
|
||||
import os
|
||||
import sys
|
||||
|
||||
from gradio import networking
|
||||
|
||||
|
||||
def main():
|
||||
args = sys.argv[1:]
|
||||
if len(args) == 0:
|
||||
raise ValueError("No file specified.")
|
||||
if len(args) == 1:
|
||||
demo_name = "demo"
|
||||
else:
|
||||
demo_name = args[1]
|
||||
|
||||
path = args[0]
|
||||
path = os.path.normpath(path)
|
||||
if not (path == os.path.basename(path)):
|
||||
raise ValueError("Must provide file name in the current directory")
|
||||
filename = os.path.splitext(path)[0]
|
||||
|
||||
port = networking.get_first_available_port(
|
||||
networking.INITIAL_PORT_VALUE,
|
||||
networking.INITIAL_PORT_VALUE + networking.TRY_NUM_PORTS,
|
||||
)
|
||||
|
||||
print(
|
||||
f"\nLaunching in *reload mode* on: http://{networking.LOCALHOST_NAME}:{port} (Press CTRL+C to quit)\n"
|
||||
)
|
||||
os.system(
|
||||
f"uvicorn {filename}:{demo_name}.app --reload --port {port} --log-level warning"
|
||||
)
|
44
gradio/reload.py
Normal file
44
gradio/reload.py
Normal file
@ -0,0 +1,44 @@
|
||||
"""
|
||||
|
||||
Contains the functions that run when `gradio` is called from the command line. Specifically, allows
|
||||
|
||||
$ gradio app.py, to run app.py in user reload mode where any changes in the app.py reload the demo.
|
||||
$ gradio-dev app.py, to run app.py in developer reload mode where any changes in the Gradio library reloads the demo.
|
||||
$ gradio app.py my_demo, to use variable names other than "demo"
|
||||
$ gradio-dev app.py my_demo, to use variable names other than "demo"
|
||||
"""
|
||||
import inspect
|
||||
import os
|
||||
import sys
|
||||
|
||||
import gradio
|
||||
from gradio import networking
|
||||
|
||||
|
||||
def run_in_reload_mode():
|
||||
args = sys.argv[1:]
|
||||
if len(args) == 0:
|
||||
raise ValueError("No file specified.")
|
||||
if len(args) == 1:
|
||||
demo_name = "demo"
|
||||
else:
|
||||
demo_name = args[1]
|
||||
|
||||
original_path = args[0]
|
||||
path = os.path.normpath(original_path)
|
||||
path = path.replace("/", ".")
|
||||
path = path.replace("\\", ".")
|
||||
gradio_folder = os.path.dirname(inspect.getfile(gradio))
|
||||
|
||||
filename = os.path.splitext(path)[0]
|
||||
|
||||
port = networking.get_first_available_port(
|
||||
networking.INITIAL_PORT_VALUE,
|
||||
networking.INITIAL_PORT_VALUE + networking.TRY_NUM_PORTS,
|
||||
)
|
||||
print(
|
||||
f"\nLaunching in *reload mode* on: http://{networking.LOCALHOST_NAME}:{port} (Press CTRL+C to quit)\n"
|
||||
)
|
||||
os.system(
|
||||
f"uvicorn {filename}:{demo_name}.app --reload --port {port} --log-level warning --reload-dir {gradio_folder} --reload-dir {os.path.dirname(original_path)}"
|
||||
)
|
@ -6,4 +6,3 @@ else
|
||||
echo "Installing gradio"
|
||||
pip install -e .
|
||||
fi
|
||||
|
||||
|
6
setup.py
6
setup.py
@ -16,7 +16,7 @@ setup(
|
||||
long_description_content_type='text/markdown',
|
||||
author="Abubakar Abid, Ali Abid, Ali Abdalla, Dawood Khan, Ahsen Khaliq, Pete Allen, Ömer Faruk Özdemir",
|
||||
author_email="team@gradio.app",
|
||||
url="https://github.com/gradio-app/gradio-UI",
|
||||
url="https://github.com/gradio-app/gradio",
|
||||
packages=["gradio"],
|
||||
license="Apache License 2.0",
|
||||
keywords=["machine learning", "visualization", "reproducibility"],
|
||||
@ -39,7 +39,7 @@ setup(
|
||||
"uvicorn",
|
||||
"Jinja2"
|
||||
],
|
||||
entry_points = {
|
||||
'console_scripts': ['gradio=gradio.dev:main'],
|
||||
entry_points={
|
||||
'console_scripts': ['gradio=gradio.reload:run_in_reload_mode']
|
||||
},
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user