From c84a7c74a9bace0698b42ad612f04f6959330c2c Mon Sep 17 00:00:00 2001 From: Ren Date: Mon, 23 Sep 2024 19:45:07 -0400 Subject: [PATCH] Add headers to folders (#888) * Add headers * Headers * Add headers to other folders * Update * update title * minor text fixes --------- Co-authored-by: Charles Frye --- 01_getting_started/generators.py | 7 +++++++ 05_scheduling/schedule_simple.py | 15 +++++++++++++++ 07_web_endpoints/count_faces.py | 10 ++++++++++ 07_web_endpoints/fastapi_app.py | 5 +++++ 07_web_endpoints/fasthtml_app.py | 7 +++++++ 07_web_endpoints/flask_app.py | 5 +++++ 07_web_endpoints/flask_streaming.py | 4 ++++ 07_web_endpoints/streaming.py | 4 ++++ 08_advanced/generators_async.py | 5 +++++ 08_advanced/parallel_execution.py | 6 ++++++ 08_advanced/poll_delayed_result.py | 8 ++++++++ 10_integrations/pyjulia.py | 4 ++++ 10_integrations/webscraper.py | 5 +++++ misc/lmdeploy_oai_compatible.py | 4 ++++ misc/say_hello_cron.py | 4 ++++ misc/stable_lm.py | 4 ++++ misc/tgi_oai_compatible.py | 4 ++++ misc/tqdm_progress_bar.py | 4 ++++ 18 files changed, 105 insertions(+) diff --git a/01_getting_started/generators.py b/01_getting_started/generators.py index 33a7b057b..d6df729c1 100644 --- a/01_getting_started/generators.py +++ b/01_getting_started/generators.py @@ -1,3 +1,10 @@ +# # Run a generator function on Modal + +# This example shows how you can run a generator function on Modal. We define a +# function that `yields` values and then call it with the [`remote_gen`](https://modal.com/docs/reference/modal.Function#remote_gen) method. The +# `remote_gen` method returns a generator object that can be used to iterate over +# the values produced by the function. + import modal app = modal.App("example-generators") diff --git a/05_scheduling/schedule_simple.py b/05_scheduling/schedule_simple.py index 42a9b08ad..47d498c5d 100644 --- a/05_scheduling/schedule_simple.py +++ b/05_scheduling/schedule_simple.py @@ -1,6 +1,21 @@ # --- # cmd: ["python", "-m", "05_scheduling.schedule_simple"] # --- + +# # Scheduling remote jobs + +# This example shows how you can schedule remote jobs on Modal. +# You can do this either with: +# +# - [`modal.Period`](https://modal.com/docs/reference/modal.Period) - a time interval between function calls. +# - [`modal.Cron`](https://modal.com/docs/reference/modal.Cron) - a cron expression to specify the schedule. + +# In the code below, the first function runs every +# 5 seconds, and the second function runs every minute. We use the `schedule` +# argument to specify the schedule for each function. The `schedule` argument can +# take a `modal.Period` object to specify a time interval or a `modal.Cron` object +# to specify a cron expression. + import time from datetime import datetime diff --git a/07_web_endpoints/count_faces.py b/07_web_endpoints/count_faces.py index 20d0e96c1..4d0041ec4 100644 --- a/07_web_endpoints/count_faces.py +++ b/07_web_endpoints/count_faces.py @@ -2,6 +2,16 @@ # lambda-test: false # --- +# Run OpenCV face detection on an image + +# This example shows how you can use OpenCV on Modal to detect faces in an image. We use +# the `opencv-python` package to load the image and the `opencv` library to +# detect faces. The function `count_faces` takes an image as input and returns +# the number of faces detected in the image. + +# The code below also shows how you can create a web server with Sanic to upload +# an image and get the number of faces detected in the image. + import os import modal diff --git a/07_web_endpoints/fastapi_app.py b/07_web_endpoints/fastapi_app.py index a1ab0782c..5871178df 100644 --- a/07_web_endpoints/fastapi_app.py +++ b/07_web_endpoints/fastapi_app.py @@ -2,6 +2,11 @@ # lambda-test: false # --- +# # Deploy FastAPI app with Modal + +# This example shows how you can deploy a [FastAPI](https://fastapi.tiangolo.com/) app with Modal. +# You can serve any app written in an ASGI-compatible web framework (like FastAPI) using this pattern or you can server WSGI-compatible frameworks like Flask with [`wsgi_app`](https://modal.com/docs/guide/webhooks#wsgi). + from typing import Optional import modal diff --git a/07_web_endpoints/fasthtml_app.py b/07_web_endpoints/fasthtml_app.py index 9c2c9c7cf..04a90eb3f 100644 --- a/07_web_endpoints/fasthtml_app.py +++ b/07_web_endpoints/fasthtml_app.py @@ -2,6 +2,13 @@ # deploy: true # cmd: ["modal", "serve", "07_web_endpoints/fasthtml_app.py"] # --- + +# # Deploy a FastHTML app with Modal + +# This example shows how you can deploy a FastHTML app with Modal. +# [FastHTML](https://www.fastht.ml/) is a Python library that allows you to create entire web applications using only Python. + + import modal app = modal.App("example-fasthtml") diff --git a/07_web_endpoints/flask_app.py b/07_web_endpoints/flask_app.py index ed43a108d..7ea0345ad 100644 --- a/07_web_endpoints/flask_app.py +++ b/07_web_endpoints/flask_app.py @@ -2,6 +2,11 @@ # lambda-test: false # --- +# # Deploy Flask app with Modal + +# This example shows how you can deploy a [Flask](https://flask.palletsprojects.com/en/3.0.x/) app with Modal. +# You can serve any app written in a WSGI-compatible web framework (like Flask) on Modal with this pattern. You can serve an app written in an ASGI-compatible framework, like FastAPI, with [`asgi_app`](https://modal.com/docs/guide/webhooks#asgi). + import modal app = modal.App( diff --git a/07_web_endpoints/flask_streaming.py b/07_web_endpoints/flask_streaming.py index 1cd4c98f5..241069d73 100644 --- a/07_web_endpoints/flask_streaming.py +++ b/07_web_endpoints/flask_streaming.py @@ -2,6 +2,10 @@ # lambda-test: false # --- +# # Deploy Flask app with streaming results with Modal + +# This example shows how you can deploy a [Flask](https://flask.palletsprojects.com/en/3.0.x/) app with Modal that streams results back to the client. + import modal app = modal.App( diff --git a/07_web_endpoints/streaming.py b/07_web_endpoints/streaming.py index 764c09f1d..38850efc9 100644 --- a/07_web_endpoints/streaming.py +++ b/07_web_endpoints/streaming.py @@ -2,6 +2,10 @@ # cmd: ["modal", "serve", "07_web_endpoints/streaming.py"] # deploy: true # --- + +# # Deploy FastAPI app with streaming results with Modal +# This example shows how you can deploy a [FastAPI](https://fastapi.tiangolo.com/) app with Modal that streams results back to the client. + import asyncio import time diff --git a/08_advanced/generators_async.py b/08_advanced/generators_async.py index d7cb85abf..46663eda1 100644 --- a/08_advanced/generators_async.py +++ b/08_advanced/generators_async.py @@ -1,3 +1,8 @@ +# # Run async generator function on Modal + +# This example shows how you can run an async generator function on Modal. +# Modal natively supports async/await syntax using asyncio. + import modal app = modal.App("example-generators-async") diff --git a/08_advanced/parallel_execution.py b/08_advanced/parallel_execution.py index 5ddad3559..908f237ba 100644 --- a/08_advanced/parallel_execution.py +++ b/08_advanced/parallel_execution.py @@ -1,3 +1,9 @@ +# # Parallel execution on Modal with `spawn` + +# This example shows how you can run multiple functions in parallel on Modal. +# We use the `spawn` method to start a function and return a handle to its result. +# The `get` method is used to retrieve the result of the function call. + import time import modal diff --git a/08_advanced/poll_delayed_result.py b/08_advanced/poll_delayed_result.py index 6990d7285..285adea79 100644 --- a/08_advanced/poll_delayed_result.py +++ b/08_advanced/poll_delayed_result.py @@ -1,6 +1,14 @@ # --- # lambda-test: false # --- + +# # Polling for a delayed result on Modal + +# This example shows how you can poll for a delayed result on Modal. + +# The function `factor_number` takes a number as input and returns the prime factors of the number. The function could take a long time to run, so we don't want to wait for the result in the web server. +# Instead, we return a URL that the client can poll to get the result. + import fastapi import modal from modal.functions import FunctionCall diff --git a/10_integrations/pyjulia.py b/10_integrations/pyjulia.py index d98b52395..df7cca4f7 100644 --- a/10_integrations/pyjulia.py +++ b/10_integrations/pyjulia.py @@ -1,3 +1,7 @@ +# # Run Julia code from Python using PyJulia + +# This example shows how you can run Julia code from Python using the PyJulia package. + import modal image = image = ( diff --git a/10_integrations/webscraper.py b/10_integrations/webscraper.py index ad3c0d534..bb351763b 100644 --- a/10_integrations/webscraper.py +++ b/10_integrations/webscraper.py @@ -1,6 +1,11 @@ # --- # runtimes: ["runc", "gvisor"] # --- + +# # Web Scraping on Modal + +# This example shows how you can scrape links from a website and post them to a Slack channel using Modal. + import os import modal diff --git a/misc/lmdeploy_oai_compatible.py b/misc/lmdeploy_oai_compatible.py index d82d41b86..c8794874e 100644 --- a/misc/lmdeploy_oai_compatible.py +++ b/misc/lmdeploy_oai_compatible.py @@ -1,3 +1,7 @@ +# # Deploy a model with `lmdeploy` +# +# This script is used to deploy a model using [lmdeploy](https://github.com/InternLM/lmdeploy) with OpenAI compatible API. + import subprocess import modal diff --git a/misc/say_hello_cron.py b/misc/say_hello_cron.py index ab45bc0eb..e6c1ac566 100644 --- a/misc/say_hello_cron.py +++ b/misc/say_hello_cron.py @@ -2,6 +2,10 @@ # lambda-test: false # --- +# # Deploy a cron job with Modal + +# This example shows how you can deploy a cron job with Modal. + import time from datetime import datetime, timezone diff --git a/misc/stable_lm.py b/misc/stable_lm.py index 3d4655357..48060eec9 100644 --- a/misc/stable_lm.py +++ b/misc/stable_lm.py @@ -1,3 +1,7 @@ +# # Run StableLM text completion model + +# This example shows how you can run [`stabilityai/stablelm-tuned-alpha-7b`](https://huggingface.co/stabilityai/stablelm-tuned-alpha-7b) on Modal + import os import time from pathlib import Path diff --git a/misc/tgi_oai_compatible.py b/misc/tgi_oai_compatible.py index dab03639c..aebce5e0b 100644 --- a/misc/tgi_oai_compatible.py +++ b/misc/tgi_oai_compatible.py @@ -1,3 +1,7 @@ +# # Run TGI on Modal + +# This example shows how you can run LLMs with the [Text Generation Inference (TGI)](https://huggingface.co/docs/text-generation-inference/en/index) inference framework on Modal. + import subprocess import modal diff --git a/misc/tqdm_progress_bar.py b/misc/tqdm_progress_bar.py index 46453c338..ce22a3a99 100644 --- a/misc/tqdm_progress_bar.py +++ b/misc/tqdm_progress_bar.py @@ -1,3 +1,7 @@ +# # Show a progress bar with tqdm on Modal + +# This example shows how you can show a progress bar with [tqdm](https://github.com/tqdm/tqdm) on Modal. + import time import modal