Clarifying the secrets

This commit is contained in:
Edward Donner
2025-04-30 15:45:32 -04:00
parent 17f797c024
commit d500dc2906
3 changed files with 20 additions and 6 deletions

View File

@@ -241,6 +241,14 @@
"\n", "\n",
"You can also build REST endpoints easily, although we won't cover that as we'll be calling direct from Python.\n", "You can also build REST endpoints easily, although we won't cover that as we'll be calling direct from Python.\n",
"\n", "\n",
"## Important note about secrets\n",
"\n",
"In both the files `pricer_service.py` and `pricer_service2.py` you will find code like this near the top: \n",
"`secrets = [modal.Secret.from_name(\"hf-secret\")]` \n",
"You may need to change from `hf-secret` to `huggingface-secret` depending on how the Secret is configured in modal. \n",
"To check, visit this page and look in the first column: \n",
"https://modal.com/secrets/\n",
"\n",
"## Important note for Windows people:\n", "## Important note for Windows people:\n",
"\n", "\n",
"On the next line, I call `modal deploy` from within Jupyter lab; I've heard that on some versions of Windows this gives a strange unicode error because modal prints emojis to the output which can't be displayed. If that happens to you, simply use an Anaconda Prompt window or a Powershell instead, with your environment activated, and type `modal deploy pricer_service` there. Follow the same approach the next time we do `!modal deploy` too.\n", "On the next line, I call `modal deploy` from within Jupyter lab; I've heard that on some versions of Windows this gives a strange unicode error because modal prints emojis to the output which can't be displayed. If that happens to you, simply use an Anaconda Prompt window or a Powershell instead, with your environment activated, and type `modal deploy pricer_service` there. Follow the same approach the next time we do `!modal deploy` too.\n",

View File

@@ -5,6 +5,9 @@ from modal import App, Image
app = modal.App("pricer-service") app = modal.App("pricer-service")
image = Image.debian_slim().pip_install("torch", "transformers", "bitsandbytes", "accelerate", "peft") image = Image.debian_slim().pip_install("torch", "transformers", "bitsandbytes", "accelerate", "peft")
# This collects the secret from Modal.
# Depending on your Modal configuration, you may need to replace "hf-secret" with "huggingface-secret"
secrets = [modal.Secret.from_name("hf-secret")] secrets = [modal.Secret.from_name("hf-secret")]
# Constants # Constants

View File

@@ -4,6 +4,9 @@ from modal import App, Volume, Image
app = modal.App("pricer-service") app = modal.App("pricer-service")
image = Image.debian_slim().pip_install("huggingface", "torch", "transformers", "bitsandbytes", "accelerate", "peft") image = Image.debian_slim().pip_install("huggingface", "torch", "transformers", "bitsandbytes", "accelerate", "peft")
# This collects the secret from Modal.
# Depending on your Modal configuration, you may need to replace "hf-secret" with "huggingface-secret"
secrets = [modal.Secret.from_name("hf-secret")] secrets = [modal.Secret.from_name("hf-secret")]
# Constants # Constants
@@ -15,7 +18,10 @@ RUN_NAME = "2024-09-13_13.04.39"
PROJECT_RUN_NAME = f"{PROJECT_NAME}-{RUN_NAME}" PROJECT_RUN_NAME = f"{PROJECT_NAME}-{RUN_NAME}"
REVISION = "e8d637df551603dc86cd7a1598a8f44af4d7ae36" REVISION = "e8d637df551603dc86cd7a1598a8f44af4d7ae36"
FINETUNED_MODEL = f"{HF_USER}/{PROJECT_RUN_NAME}" FINETUNED_MODEL = f"{HF_USER}/{PROJECT_RUN_NAME}"
CACHE_DIR = "/cache" CACHE_DIR = "/cache"
# Change this to 1 if you want Modal to be always running, otherwise it will go cold after 2 mins
MIN_CONTAINERS = 0
QUESTION = "How much does this cost to the nearest dollar?" QUESTION = "How much does this cost to the nearest dollar?"
PREFIX = "Price is $" PREFIX = "Price is $"
@@ -27,6 +33,7 @@ hf_cache_volume = Volume.from_name("hf-hub-cache", create_if_missing=True)
secrets=secrets, secrets=secrets,
gpu=GPU, gpu=GPU,
timeout=1800, timeout=1800,
min_containers=MIN_CONTAINERS,
volumes={CACHE_DIR: hf_cache_volume} volumes={CACHE_DIR: hf_cache_volume}
) )
class Pricer: class Pricer:
@@ -74,8 +81,4 @@ class Pricer:
contents = result.split("Price is $")[1] contents = result.split("Price is $")[1]
contents = contents.replace(',','') contents = contents.replace(',','')
match = re.search(r"[-+]?\d*\.\d+|\d+", contents) match = re.search(r"[-+]?\d*\.\d+|\d+", contents)
return float(match.group()) if match else 0 return float(match.group()) if match else 0
@modal.method()
def wake_up(self) -> str:
return "ok"