Skip to content

Commit b3e5225

Browse files
committed
Simplify example
1 parent aafc6b9 commit b3e5225

File tree

1 file changed

+22
-54
lines changed

1 file changed

+22
-54
lines changed

python/example.py

Lines changed: 22 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -10,67 +10,35 @@
1010

1111

1212
code = """
13-
import psutil
14-
import os
13+
import matplotlib.pyplot as plt
14+
import numpy as np
1515
16-
def force_oom():
17-
# Get current memory usage
18-
mem_before = psutil.virtual_memory().used
19-
20-
# Start creating large lists
21-
size = 10000000 # Start with 10 million integers
22-
increment = 5000000 # Increase by 5 million integers each iteration
23-
24-
while True:
25-
# Create a large list of integers
26-
large_list = [i for i in range(size)]
27-
28-
# Get current memory usage
29-
mem_after = psutil.virtual_memory().used
30-
31-
# Calculate memory difference
32-
mem_diff = mem_after - mem_before
33-
34-
print(f"Created list of size {size} MB")
35-
print(f"Memory increase: {mem_diff / (1024 * 1024):.2f} GB")
36-
37-
# Reset memory usage tracking
38-
mem_before = mem_after
39-
40-
# Increment size for next iteration
41-
size += increment
42-
43-
# Sleep briefly to allow OS to respond
44-
import time
45-
time.sleep(0.1)
16+
# Step 1: Define the data for the pie chart
17+
categories = ["No", "No, in blue"]
18+
sizes = [90, 10]
4619
47-
# Run the function
48-
force_oom()
49-
"""
20+
# Step 2: Create the figure and axis objects
21+
fig, ax = plt.subplots(figsize=(8, 8))
5022
23+
plt.xlabel("x")
24+
plt.ylabel("y")
5125
52-
async def create_sbx(i: int):
53-
sbx = await AsyncCodeInterpreter.create(timeout=60, template="rth7a7wt20f3ymyr74zo")
54-
# with open('t2.csv') as f:
55-
# await sbx.files.write("/home/user/t.csv", f)
56-
print("executing cell")
57-
print(f"Created sandbox {sbx.sandbox_id}")
58-
x = time.time()
59-
r = await sbx.notebook.exec_cell(code)
60-
print(f"Executed in {time.time() - x}")
61-
print(r.logs.stdout)
62-
print(r.error)
26+
# Step 3: Create the pie chart
27+
ax.pie(sizes, labels=categories, autopct='%1.1f%%', startangle=90, colors=plt.cm.Pastel1.colors[:len(categories)])
6328
29+
# Step 4: Add title and legend
30+
ax.axis('equal') # Equal aspect ratio ensures that pie is drawn as a circle
31+
plt.title('Will I wake up early tomorrow?')
6432
65-
async def run():
66-
for j in range(1):
67-
print(f"Creating {j}. batch of sandboxes")
68-
futures = []
69-
for i in range(1):
70-
futures.append(create_sbx(i))
33+
# Step 5: Show the plot
34+
plt.show()
35+
"""
7136

72-
sbxs = await asyncio.gather(*futures)
73-
sleep(2)
37+
38+
async def run():
39+
sbx = await AsyncCodeInterpreter.create(timeout=60)
40+
e = await sbx.notebook.exec_cell(code)
41+
print(e.results[0].graph)
7442

7543

7644
asyncio.run(run())

0 commit comments

Comments
 (0)