File size: 2,450 Bytes
90ad763
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
dc98e6a
 
 
 
90ad763
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
dc98e6a
 
 
90ad763
dc98e6a
 
 
90ad763
 
dc98e6a
 
90ad763
 
dc98e6a
 
90ad763
 
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
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Jupyter Kernel Execution API</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            line-height: 1.6;
            color: #333;
            max-width: 800px;
            margin: 0 auto;
            padding: 20px;
        }
        h1 {
            color: #2c3e50;
        }
        h2 {
            color: #34495e;
        }
        pre {
            background-color: #f4f4f4;
            border: 1px solid #ddd;
            border-radius: 4px;
            padding: 15px;
            overflow-x: auto;
        }
        code {
            font-family: 'Courier New', Courier, monospace;
        }
    </style>
    <link href="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/themes/prism.min.css" rel="stylesheet" />
    <script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/prism.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/components/prism-python.min.js"></script>

</head>
<body>
    <h1>Jupyter Kernel Execution API</h1>
    
    <p>This Flask application provides an API for executing Python code in a Jupyter kernel, with endpoints for code execution, kernel restart, and health checks.</p>
    
    <h2>Key Features</h2>
    <ul>
        <li>Execute Python code via HTTP POST request</li>
        <li>Timeout mechanism to prevent long-running code</li>
        <li>Error handling for various scenarios</li>
        <li>Support for displaying figures and handling output streams</li>
        <li>Kernel restart functionality</li>
        <li>Health check endpoint</li>
    </ul>
    
    <h2>Endpoints</h2>
    <h3>Execution Endpoint</h3>
    <pre><code class="language-python">import requests

url = "https://lvwerra-executor.hf.space/execute"

print(requests.post(url, json={'code': 'x=10'}).json())
print(requests.post(url, json={'code': 'y=20'}).json())
print(requests.post(url, json={'code': 'print(y*x)'}).json())</code></pre>
    
    <h3>Kernel Restart Endpoint</h3>
    <pre><code class="language-python">url = "https://lvwerra-executor.hf.space/restart"
print(requests.post(url).json())</code></pre>
    
    <h3>Health Check Endpoint</h3>
    <pre><code class="language-python">url = "https://lvwerra-executor.hf.space/health"
print(requests.get(url).json())</code></pre>
</body>
</html>