-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* modal branch * Modal scheduler
- Loading branch information
Showing
4 changed files
with
119 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
from modal import App, Image | ||
|
||
# Create a stub for the Modal app | ||
modal_app = App("discord-bot-runner") | ||
|
||
@modal_app.function( | ||
gpu="T4", | ||
image=Image.debian_slim(python_version="3.10").pip_install(["torch"]) | ||
) | ||
def run_script(script_content: str) -> str: | ||
""" | ||
Executes the provided Python script in an isolated environment | ||
""" | ||
import sys | ||
from io import StringIO | ||
|
||
# Capture stdout | ||
output = StringIO() | ||
sys.stdout = output | ||
|
||
try: | ||
# Create a new dictionary for local variables to avoid polluting the global namespace | ||
local_vars = {} | ||
# Execute the script in the isolated namespace | ||
exec(script_content, {}, local_vars) | ||
return output.getvalue() | ||
except Exception as e: | ||
return f"Error executing script: {str(e)}" | ||
finally: | ||
sys.stdout = sys.__stdout__ | ||
|
||
# For testing the Modal function directly | ||
if __name__ == "__main__": | ||
with modal_app.run(): | ||
result = run_script.remote("print('Hello from Modal!')") | ||
print(result) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,5 @@ aiohttp | |
discord.py | ||
audioop-lts # discord.py imports using * syntax | ||
python-dotenv | ||
requests | ||
requests | ||
modal |