Skip to content

Commit

Permalink
Add headers to folders (#888)
Browse files Browse the repository at this point in the history
* Add headers

* Headers

* Add headers to other folders

* Update

* update title

* minor text fixes

---------

Co-authored-by: Charles Frye <[email protected]>
  • Loading branch information
yirenlu92 and charlesfrye authored Sep 23, 2024
1 parent 79c5b4e commit c84a7c7
Show file tree
Hide file tree
Showing 18 changed files with 105 additions and 0 deletions.
7 changes: 7 additions & 0 deletions 01_getting_started/generators.py
Original file line number Diff line number Diff line change
@@ -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")
Expand Down
15 changes: 15 additions & 0 deletions 05_scheduling/schedule_simple.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down
10 changes: 10 additions & 0 deletions 07_web_endpoints/count_faces.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions 07_web_endpoints/fastapi_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions 07_web_endpoints/fasthtml_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
5 changes: 5 additions & 0 deletions 07_web_endpoints/flask_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 4 additions & 0 deletions 07_web_endpoints/flask_streaming.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 4 additions & 0 deletions 07_web_endpoints/streaming.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 5 additions & 0 deletions 08_advanced/generators_async.py
Original file line number Diff line number Diff line change
@@ -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")
Expand Down
6 changes: 6 additions & 0 deletions 08_advanced/parallel_execution.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
8 changes: 8 additions & 0 deletions 08_advanced/poll_delayed_result.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 4 additions & 0 deletions 10_integrations/pyjulia.py
Original file line number Diff line number Diff line change
@@ -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 = (
Expand Down
5 changes: 5 additions & 0 deletions 10_integrations/webscraper.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 4 additions & 0 deletions misc/lmdeploy_oai_compatible.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 4 additions & 0 deletions misc/say_hello_cron.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 4 additions & 0 deletions misc/stable_lm.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 4 additions & 0 deletions misc/tgi_oai_compatible.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 4 additions & 0 deletions misc/tqdm_progress_bar.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit c84a7c7

Please sign in to comment.