Spaces:
Sleeping
Sleeping
File size: 1,868 Bytes
d0fd383 fce5ca7 d0fd383 fce5ca7 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | """Create a reviewable Gradio or Docker Space bundle locally; never uploads or writes Git."""
import argparse
import shutil
from pathlib import Path
def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("destination", type=Path)
parser.add_argument("--sdk", choices=["gradio", "docker"], default="gradio")
args = parser.parse_args()
source = Path(__file__).resolve().parents[1]
destination = args.destination.resolve()
if destination.exists():
raise SystemExit("Destination must be new to avoid overwriting files")
if destination == source or source in destination.parents:
raise SystemExit("Choose a destination outside this repository")
destination.mkdir(parents=True)
for name in ["pyproject.toml", "setup.py", "requirements.txt", "THIRD_PARTY.md"]:
shutil.copy2(source / name, destination / name)
for name in ["scripts", "api"]:
shutil.copytree(
source / name,
destination / name,
ignore=shutil.ignore_patterns("__pycache__", "*.pyc", "*.egg-info"),
)
if args.sdk == "docker":
shutil.copy2(source / "api/Dockerfile", destination / "Dockerfile")
metadata = "---\ntitle: Math2LaTeX\nsdk: docker\napp_port: 7860\n---\n\nVisit /docs for an upload smoke test. See THIRD_PARTY.md.\n"
(destination / "README.md").write_text(metadata)
else:
shutil.copy2(source / "space/app.py", destination / "app.py")
shutil.copy2(source / "space/theme.css", destination / "theme.css")
shutil.copytree(source / "space/examples", destination / "examples")
shutil.copy2(source / "space/packages.txt", destination / "packages.txt")
shutil.copy2(source / "space/README.md", destination / "README.md")
print(destination)
if __name__ == "__main__":
main()
|