leandro
commited on
Commit
·
90ad763
1
Parent(s):
ff98df2
index
Browse files- static/index.html +66 -0
- test.py +6 -1
static/index.html
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>Jupyter Kernel Execution API</title>
|
| 7 |
+
<style>
|
| 8 |
+
body {
|
| 9 |
+
font-family: Arial, sans-serif;
|
| 10 |
+
line-height: 1.6;
|
| 11 |
+
color: #333;
|
| 12 |
+
max-width: 800px;
|
| 13 |
+
margin: 0 auto;
|
| 14 |
+
padding: 20px;
|
| 15 |
+
}
|
| 16 |
+
h1 {
|
| 17 |
+
color: #2c3e50;
|
| 18 |
+
}
|
| 19 |
+
h2 {
|
| 20 |
+
color: #34495e;
|
| 21 |
+
}
|
| 22 |
+
pre {
|
| 23 |
+
background-color: #f4f4f4;
|
| 24 |
+
border: 1px solid #ddd;
|
| 25 |
+
border-radius: 4px;
|
| 26 |
+
padding: 15px;
|
| 27 |
+
overflow-x: auto;
|
| 28 |
+
}
|
| 29 |
+
code {
|
| 30 |
+
font-family: 'Courier New', Courier, monospace;
|
| 31 |
+
}
|
| 32 |
+
</style>
|
| 33 |
+
</head>
|
| 34 |
+
<body>
|
| 35 |
+
<h1>Jupyter Kernel Execution API</h1>
|
| 36 |
+
|
| 37 |
+
<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>
|
| 38 |
+
|
| 39 |
+
<h2>Key Features</h2>
|
| 40 |
+
<ul>
|
| 41 |
+
<li>Execute Python code via HTTP POST request</li>
|
| 42 |
+
<li>Timeout mechanism to prevent long-running code</li>
|
| 43 |
+
<li>Error handling for various scenarios</li>
|
| 44 |
+
<li>Support for displaying figures and handling output streams</li>
|
| 45 |
+
<li>Kernel restart functionality</li>
|
| 46 |
+
<li>Health check endpoint</li>
|
| 47 |
+
</ul>
|
| 48 |
+
|
| 49 |
+
<h2>Endpoints</h2>
|
| 50 |
+
<h3>Execution Endpoint</h3>
|
| 51 |
+
<pre><code>import requests
|
| 52 |
+
|
| 53 |
+
url = "https://lvwerra-executor.hf.space/execute"
|
| 54 |
+
print(requests.post(url, json={'code': 'x=10'}).json())
|
| 55 |
+
print(requests.post(url, json={'code': 'y=20'}).json())
|
| 56 |
+
print(requests.post(url, json={'code': 'print(y*x)'}).json())</code></pre>
|
| 57 |
+
|
| 58 |
+
<h3>Kernel Restart Endpoint</h3>
|
| 59 |
+
<pre><code>url = "https://lvwerra-executor.hf.space/restart"
|
| 60 |
+
print(requests.post(url).json())</code></pre>
|
| 61 |
+
|
| 62 |
+
<h3>Health Check Endpoint</h3>
|
| 63 |
+
<pre><code>url = "https://lvwerra-executor.hf.space/health"
|
| 64 |
+
print(requests.get(url).json())</code></pre>
|
| 65 |
+
</body>
|
| 66 |
+
</html>
|
test.py
CHANGED
|
@@ -6,5 +6,10 @@ space_name = "executor"
|
|
| 6 |
url = f"https://{org_or_user}-{space_name}.hf.space/health"
|
| 7 |
print(requests.get(url).json())
|
| 8 |
|
|
|
|
|
|
|
|
|
|
| 9 |
url = f"https://{org_or_user}-{space_name}.hf.space/execute"
|
| 10 |
-
print(requests.post(url, json={'code': '
|
|
|
|
|
|
|
|
|
| 6 |
url = f"https://{org_or_user}-{space_name}.hf.space/health"
|
| 7 |
print(requests.get(url).json())
|
| 8 |
|
| 9 |
+
url = f"https://{org_or_user}-{space_name}.hf.space/restart"
|
| 10 |
+
print(requests.post(url).json())
|
| 11 |
+
|
| 12 |
url = f"https://{org_or_user}-{space_name}.hf.space/execute"
|
| 13 |
+
print(requests.post(url, json={'code': 'x=10'}).json())
|
| 14 |
+
print(requests.post(url, json={'code': 'y=20'}).json())
|
| 15 |
+
print(requests.post(url, json={'code': 'print(y*x)'}).json())
|