Py.Cafe

maartenbreddels/

modal-experiment

Try to see how far modal can be imported/run

DocsPricing
  • app.py
  • requirements.txt
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# check out https://dash.plotly.com/ for documentation
# And check out https://py.cafe/maartenbreddels for more examples
from dash import Dash, Input, Output, callback, dcc, html
import sys
import sysconfig
import site



site.getusersitepackages = lambda: "/"

print(        sys.prefix,
        sys.base_prefix,
        sys.exec_prefix,
        sys.base_exec_prefix,sysconfig.get_paths().values(),
        *site.getsitepackages(),
        site.getusersitepackages())

# check out https://solara.dev/ for documentation
# or https://github.com/widgetti/solara/
# And check out https://py.cafe/maartenbreddels for more examples
import sys
import grpclib

sys.modules['grpclib'] = grpclib
sys.modules['grpclib.client'] = grpclib
sys.modules['grpclib.const'] = grpclib
sys.modules['grpclib.config'] = grpclib
sys.modules['grpclib.events'] = grpclib
sys.modules['grpclib.exceptions'] = grpclib
sys.modules['grpclib.protocol'] = grpclib


import synchronicity.synchronizer

synchronicity.synchronizer.Synchronizer._start_loop = lambda self: None
import asyncio
# loop = asyncio.get_event_loop()
# synchronicity.synchronizer.Synchronizer._get_loop = lambda self, start=False: loop

# def _run_function_sync(self, coro, interface, original_func):
#     print(coro, interface, original_func)

# synchronicity.synchronizer.Synchronizer._run_function_sync = _run_function_sync

# from synchronicity import Synchronizer

# synchronizer = Synchronizer()

# @synchronizer.create_blocking
# async def f(x):
#     await asyncio.sleep(1.0)
#     return x**2


# # Running f in a synchronous context blocks until the result is available
# print("call it")
# ret = f(42)  # Blocks
# print('f(42) =', ret)


import modal

import modal

app = modal.App("example-get-started")


@app.function()
def square(x):
    print("This code is running on a remote worker!")
    return x**2


@app.local_entrypoint()
def main():
    print("the square is", square.remote(42))

app = Dash(__name__)
md = """
# Dash demo

See [The dash examples index](https://dash-example-index.herokuapp.com/) for more examples.
"""

app.layout = html.Div(
    children=[
        dcc.Markdown(children=md, link_target="_blank"),
        dcc.Dropdown(id="dropdown", options=["red", "green", "blue", "orange"]),
        dcc.Markdown(id="markdown", children=["## Hello World"]),
    ]
)


@callback(
    Output("markdown", "style"),
    Input("dropdown", "value"),
)
def update_markdown_style(color):
    print(square.remote(2))
    return {"color": color}