repositories
loading repo index
repositories
loading repo index
repository
loading code, commits, and activity
public Clawd ADK gateway launch mirror
stars
latest
clone command
git clone gitlawb://did:key:z6Mkq5mY...iFZ5/my-project-publ...git clone gitlawb://did:key:z6Mkq5mY.../my-project-publ...2fa351d6docs: add automaton and perps launch sources16d ago| #1 | import os |
| #2 | import re |
| #3 | import shutil |
| #4 | import subprocess |
| #5 | |
| #6 | import pkg_resources |
| #7 | from rich.console import Console |
| #8 | |
| #9 | console = Console() |
| #10 | |
| #11 | |
| #12 | def get_pkg_path_from_name(template: str): |
| #13 | try: |
| #14 | # Determine the installation location of the embedchain package |
| #15 | package_path = pkg_resources.resource_filename("embedchain", "") |
| #16 | except ImportError: |
| #17 | console.print("❌ [bold red]Failed to locate the 'embedchain' package. Is it installed?[/bold red]") |
| #18 | return |
| #19 | |
| #20 | # Construct the source path from the embedchain package |
| #21 | src_path = os.path.join(package_path, "deployment", template) |
| #22 | |
| #23 | if not os.path.exists(src_path): |
| #24 | console.print(f"❌ [bold red]Template '{template}' not found.[/bold red]") |
| #25 | return |
| #26 | |
| #27 | return src_path |
| #28 | |
| #29 | |
| #30 | def setup_fly_io_app(extra_args): |
| #31 | fly_launch_command = ["fly", "launch", "--region", "sjc", "--no-deploy"] + list(extra_args) |
| #32 | try: |
| #33 | console.print(f"🚀 [bold cyan]Running: {' '.join(fly_launch_command)}[/bold cyan]") |
| #34 | shutil.move(".env.example", ".env") |
| #35 | subprocess.run(fly_launch_command, check=True) |
| #36 | console.print("✅ [bold green]'fly launch' executed successfully.[/bold green]") |
| #37 | except subprocess.CalledProcessError as e: |
| #38 | console.print(f"❌ [bold red]An error occurred: {e}[/bold red]") |
| #39 | except FileNotFoundError: |
| #40 | console.print( |
| #41 | "❌ [bold red]'fly' command not found. Please ensure Fly CLI is installed and in your PATH.[/bold red]" |
| #42 | ) |
| #43 | |
| #44 | |
| #45 | def setup_modal_com_app(extra_args): |
| #46 | modal_setup_file = os.path.join(os.path.expanduser("~"), ".modal.toml") |
| #47 | if os.path.exists(modal_setup_file): |
| #48 | console.print( |
| #49 | """✅ [bold green]Modal setup already done. You can now install the dependencies by doing \n |
| #50 | `pip install -r requirements.txt`[/bold green]""" |
| #51 | ) |
| #52 | else: |
| #53 | modal_setup_cmd = ["modal", "setup"] + list(extra_args) |
| #54 | console.print(f"🚀 [bold cyan]Running: {' '.join(modal_setup_cmd)}[/bold cyan]") |
| #55 | subprocess.run(modal_setup_cmd, check=True) |
| #56 | shutil.move(".env.example", ".env") |
| #57 | console.print( |
| #58 | """Great! Now you can install the dependencies by doing: \n |
| #59 | `pip install -r requirements.txt`\n |
| #60 | \n |
| #61 | To run your app locally:\n |
| #62 | `ec dev` |
| #63 | """ |
| #64 | ) |
| #65 | |
| #66 | |
| #67 | def setup_render_com_app(): |
| #68 | render_setup_file = os.path.join(os.path.expanduser("~"), ".render/config.yaml") |
| #69 | if os.path.exists(render_setup_file): |
| #70 | console.print( |
| #71 | """✅ [bold green]Render setup already done. You can now install the dependencies by doing \n |
| #72 | `pip install -r requirements.txt`[/bold green]""" |
| #73 | ) |
| #74 | else: |
| #75 | render_setup_cmd = ["render", "config", "init"] |
| #76 | console.print(f"🚀 [bold cyan]Running: {' '.join(render_setup_cmd)}[/bold cyan]") |
| #77 | subprocess.run(render_setup_cmd, check=True) |
| #78 | shutil.move(".env.example", ".env") |
| #79 | console.print( |
| #80 | """Great! Now you can install the dependencies by doing: \n |
| #81 | `pip install -r requirements.txt`\n |
| #82 | \n |
| #83 | To run your app locally:\n |
| #84 | `ec dev` |
| #85 | """ |
| #86 | ) |
| #87 | |
| #88 | |
| #89 | def setup_streamlit_io_app(): |
| #90 | # nothing needs to be done here |
| #91 | console.print("Great! Now you can install the dependencies by doing `pip install -r requirements.txt`") |
| #92 | |
| #93 | |
| #94 | def setup_gradio_app(): |
| #95 | # nothing needs to be done here |
| #96 | console.print("Great! Now you can install the dependencies by doing `pip install -r requirements.txt`") |
| #97 | |
| #98 | |
| #99 | def setup_hf_app(): |
| #100 | subprocess.run(["pip", "install", "huggingface_hub[cli]"], check=True) |
| #101 | hf_setup_file = os.path.join(os.path.expanduser("~"), ".cache/huggingface/token") |
| #102 | if os.path.exists(hf_setup_file): |
| #103 | console.print( |
| #104 | """✅ [bold green]HuggingFace setup already done. You can now install the dependencies by doing \n |
| #105 | `pip install -r requirements.txt`[/bold green]""" |
| #106 | ) |
| #107 | else: |
| #108 | console.print( |
| #109 | """🚀 [cyan]Running: huggingface-cli login \n |
| #110 | Please provide a [bold]WRITE[/bold] token so that we can directly deploy\n |
| #111 | your apps from the terminal.[/cyan] |
| #112 | """ |
| #113 | ) |
| #114 | subprocess.run(["huggingface-cli", "login"], check=True) |
| #115 | console.print("Great! Now you can install the dependencies by doing `pip install -r requirements.txt`") |
| #116 | |
| #117 | |
| #118 | def run_dev_fly_io(debug, host, port): |
| #119 | uvicorn_command = ["uvicorn", "app:app"] |
| #120 | |
| #121 | if debug: |
| #122 | uvicorn_command.append("--reload") |
| #123 | |
| #124 | uvicorn_command.extend(["--host", host, "--port", str(port)]) |
| #125 | |
| #126 | try: |
| #127 | console.print(f"🚀 [bold cyan]Running FastAPI app with command: {' '.join(uvicorn_command)}[/bold cyan]") |
| #128 | subprocess.run(uvicorn_command, check=True) |
| #129 | except subprocess.CalledProcessError as e: |
| #130 | console.print(f"❌ [bold red]An error occurred: {e}[/bold red]") |
| #131 | except KeyboardInterrupt: |
| #132 | console.print("\n🛑 [bold yellow]FastAPI server stopped[/bold yellow]") |
| #133 | |
| #134 | |
| #135 | def run_dev_modal_com(): |
| #136 | modal_run_cmd = ["modal", "serve", "app"] |
| #137 | try: |
| #138 | console.print(f"🚀 [bold cyan]Running FastAPI app with command: {' '.join(modal_run_cmd)}[/bold cyan]") |
| #139 | subprocess.run(modal_run_cmd, check=True) |
| #140 | except subprocess.CalledProcessError as e: |
| #141 | console.print(f"❌ [bold red]An error occurred: {e}[/bold red]") |
| #142 | except KeyboardInterrupt: |
| #143 | console.print("\n🛑 [bold yellow]FastAPI server stopped[/bold yellow]") |
| #144 | |
| #145 | |
| #146 | def run_dev_streamlit_io(): |
| #147 | streamlit_run_cmd = ["streamlit", "run", "app.py"] |
| #148 | try: |
| #149 | console.print(f"🚀 [bold cyan]Running Streamlit app with command: {' '.join(streamlit_run_cmd)}[/bold cyan]") |
| #150 | subprocess.run(streamlit_run_cmd, check=True) |
| #151 | except subprocess.CalledProcessError as e: |
| #152 | console.print(f"❌ [bold red]An error occurred: {e}[/bold red]") |
| #153 | except KeyboardInterrupt: |
| #154 | console.print("\n🛑 [bold yellow]Streamlit server stopped[/bold yellow]") |
| #155 | |
| #156 | |
| #157 | def run_dev_render_com(debug, host, port): |
| #158 | uvicorn_command = ["uvicorn", "app:app"] |
| #159 | |
| #160 | if debug: |
| #161 | uvicorn_command.append("--reload") |
| #162 | |
| #163 | uvicorn_command.extend(["--host", host, "--port", str(port)]) |
| #164 | |
| #165 | try: |
| #166 | console.print(f"🚀 [bold cyan]Running FastAPI app with command: {' '.join(uvicorn_command)}[/bold cyan]") |
| #167 | subprocess.run(uvicorn_command, check=True) |
| #168 | except subprocess.CalledProcessError as e: |
| #169 | console.print(f"❌ [bold red]An error occurred: {e}[/bold red]") |
| #170 | except KeyboardInterrupt: |
| #171 | console.print("\n🛑 [bold yellow]FastAPI server stopped[/bold yellow]") |
| #172 | |
| #173 | |
| #174 | def run_dev_gradio(): |
| #175 | gradio_run_cmd = ["gradio", "app.py"] |
| #176 | try: |
| #177 | console.print(f"🚀 [bold cyan]Running Gradio app with command: {' '.join(gradio_run_cmd)}[/bold cyan]") |
| #178 | subprocess.run(gradio_run_cmd, check=True) |
| #179 | except subprocess.CalledProcessError as e: |
| #180 | console.print(f"❌ [bold red]An error occurred: {e}[/bold red]") |
| #181 | except KeyboardInterrupt: |
| #182 | console.print("\n🛑 [bold yellow]Gradio server stopped[/bold yellow]") |
| #183 | |
| #184 | |
| #185 | def read_env_file(env_file_path): |
| #186 | """ |
| #187 | Reads an environment file and returns a dictionary of key-value pairs. |
| #188 | |
| #189 | Args: |
| #190 | env_file_path (str): The path to the .env file. |
| #191 | |
| #192 | Returns: |
| #193 | dict: Dictionary of environment variables. |
| #194 | """ |
| #195 | env_vars = {} |
| #196 | pattern = re.compile(r"(\w+)=(.*)") # compile regular expression for better performance |
| #197 | with open(env_file_path, "r") as file: |
| #198 | lines = file.readlines() # readlines is faster as it reads all at once |
| #199 | for line in lines: |
| #200 | line = line.strip() |
| #201 | # Ignore comments and empty lines |
| #202 | if line and not line.startswith("#"): |
| #203 | # Assume each line is in the format KEY=VALUE |
| #204 | key_value_match = pattern.match(line) |
| #205 | if key_value_match: |
| #206 | key, value = key_value_match.groups() |
| #207 | env_vars[key] = value |
| #208 | return env_vars |
| #209 | |
| #210 | |
| #211 | def deploy_fly(): |
| #212 | app_name = "" |
| #213 | with open("fly.toml", "r") as file: |
| #214 | for line in file: |
| #215 | if line.strip().startswith("app ="): |
| #216 | app_name = line.split("=")[1].strip().strip('"') |
| #217 | |
| #218 | if not app_name: |
| #219 | console.print("❌ [bold red]App name not found in fly.toml[/bold red]") |
| #220 | return |
| #221 | |
| #222 | env_vars = read_env_file(".env") |
| #223 | secrets_command = ["flyctl", "secrets", "set", "-a", app_name] + [f"{k}={v}" for k, v in env_vars.items()] |
| #224 | |
| #225 | deploy_command = ["fly", "deploy"] |
| #226 | try: |
| #227 | # Set secrets |
| #228 | console.print(f"🔐 [bold cyan]Setting secrets for {app_name}[/bold cyan]") |
| #229 | subprocess.run(secrets_command, check=True) |
| #230 | |
| #231 | # Deploy application |
| #232 | console.print(f"🚀 [bold cyan]Running: {' '.join(deploy_command)}[/bold cyan]") |
| #233 | subprocess.run(deploy_command, check=True) |
| #234 | console.print("✅ [bold green]'fly deploy' executed successfully.[/bold green]") |
| #235 | |
| #236 | except subprocess.CalledProcessError as e: |
| #237 | console.print(f"❌ [bold red]An error occurred: {e}[/bold red]") |
| #238 | except FileNotFoundError: |
| #239 | console.print( |
| #240 | "❌ [bold red]'fly' command not found. Please ensure Fly CLI is installed and in your PATH.[/bold red]" |
| #241 | ) |
| #242 | |
| #243 | |
| #244 | def deploy_modal(): |
| #245 | modal_deploy_cmd = ["modal", "deploy", "app"] |
| #246 | try: |
| #247 | console.print(f"🚀 [bold cyan]Running: {' '.join(modal_deploy_cmd)}[/bold cyan]") |
| #248 | subprocess.run(modal_deploy_cmd, check=True) |
| #249 | console.print("✅ [bold green]'modal deploy' executed successfully.[/bold green]") |
| #250 | except subprocess.CalledProcessError as e: |
| #251 | console.print(f"❌ [bold red]An error occurred: {e}[/bold red]") |
| #252 | except FileNotFoundError: |
| #253 | console.print( |
| #254 | "❌ [bold red]'modal' command not found. Please ensure Modal CLI is installed and in your PATH.[/bold red]" |
| #255 | ) |
| #256 | |
| #257 | |
| #258 | def deploy_streamlit(): |
| #259 | streamlit_deploy_cmd = ["streamlit", "run", "app.py"] |
| #260 | try: |
| #261 | console.print(f"🚀 [bold cyan]Running: {' '.join(streamlit_deploy_cmd)}[/bold cyan]") |
| #262 | console.print( |
| #263 | """\n\n✅ [bold yellow]To deploy a streamlit app, you can directly it from the UI.\n |
| #264 | Click on the 'Deploy' button on the top right corner of the app.\n |
| #265 | For more information, please refer to https://docs.embedchain.ai/deployment/streamlit_io |
| #266 | [/bold yellow] |
| #267 | \n\n""" |
| #268 | ) |
| #269 | subprocess.run(streamlit_deploy_cmd, check=True) |
| #270 | except subprocess.CalledProcessError as e: |
| #271 | console.print(f"❌ [bold red]An error occurred: {e}[/bold red]") |
| #272 | except FileNotFoundError: |
| #273 | console.print( |
| #274 | """❌ [bold red]'streamlit' command not found.\n |
| #275 | Please ensure Streamlit CLI is installed and in your PATH.[/bold red]""" |
| #276 | ) |
| #277 | |
| #278 | |
| #279 | def deploy_render(): |
| #280 | render_deploy_cmd = ["render", "blueprint", "launch"] |
| #281 | |
| #282 | try: |
| #283 | console.print(f"🚀 [bold cyan]Running: {' '.join(render_deploy_cmd)}[/bold cyan]") |
| #284 | subprocess.run(render_deploy_cmd, check=True) |
| #285 | console.print("✅ [bold green]'render blueprint launch' executed successfully.[/bold green]") |
| #286 | except subprocess.CalledProcessError as e: |
| #287 | console.print(f"❌ [bold red]An error occurred: {e}[/bold red]") |
| #288 | except FileNotFoundError: |
| #289 | console.print( |
| #290 | "❌ [bold red]'render' command not found. Please ensure Render CLI is installed and in your PATH.[/bold red]" # noqa:E501 |
| #291 | ) |
| #292 | |
| #293 | |
| #294 | def deploy_gradio_app(): |
| #295 | gradio_deploy_cmd = ["gradio", "deploy"] |
| #296 | |
| #297 | try: |
| #298 | console.print(f"🚀 [bold cyan]Running: {' '.join(gradio_deploy_cmd)}[/bold cyan]") |
| #299 | subprocess.run(gradio_deploy_cmd, check=True) |
| #300 | console.print("✅ [bold green]'gradio deploy' executed successfully.[/bold green]") |
| #301 | except subprocess.CalledProcessError as e: |
| #302 | console.print(f"❌ [bold red]An error occurred: {e}[/bold red]") |
| #303 | except FileNotFoundError: |
| #304 | console.print( |
| #305 | "❌ [bold red]'gradio' command not found. Please ensure Gradio CLI is installed and in your PATH.[/bold red]" # noqa:E501 |
| #306 | ) |
| #307 | |
| #308 | |
| #309 | def deploy_hf_spaces(ec_app_name): |
| #310 | if not ec_app_name: |
| #311 | console.print("❌ [bold red]'name' not found in embedchain.json[/bold red]") |
| #312 | return |
| #313 | hf_spaces_deploy_cmd = ["huggingface-cli", "upload", ec_app_name, ".", ".", "--repo-type=space"] |
| #314 | |
| #315 | try: |
| #316 | console.print(f"🚀 [bold cyan]Running: {' '.join(hf_spaces_deploy_cmd)}[/bold cyan]") |
| #317 | subprocess.run(hf_spaces_deploy_cmd, check=True) |
| #318 | console.print("✅ [bold green]'huggingface-cli upload' executed successfully.[/bold green]") |
| #319 | except subprocess.CalledProcessError as e: |
| #320 | console.print(f"❌ [bold red]An error occurred: {e}[/bold red]") |
| #321 |