Spaces:
Runtime error
Runtime error
Sasha Rush
commited on
Commit
•
972b53e
1
Parent(s):
a3d1b18
Create run.py
Browse files
run.py
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
def start(prompt):
|
2 |
+
out = ""
|
3 |
+
for chunk in openai.ChatCompletion.create(
|
4 |
+
model="gpt-4",
|
5 |
+
messages=[{
|
6 |
+
"role": "user",
|
7 |
+
"content": prompt,
|
8 |
+
|
9 |
+
}],
|
10 |
+
stream=True,
|
11 |
+
temperature= 0
|
12 |
+
):
|
13 |
+
|
14 |
+
content = chunk["choices"][0].get("delta", {}).get("content")
|
15 |
+
if content is not None:
|
16 |
+
out += content
|
17 |
+
print(content, end="")
|
18 |
+
return out
|
19 |
+
|
20 |
+
def animate_chalk(board, actions):
|
21 |
+
outs = [draw_board(board.grid)]
|
22 |
+
for action in actions:
|
23 |
+
board, _ = board.move(action)
|
24 |
+
outs.append(draw_board(board.grid))
|
25 |
+
for i, v in enumerate(outs):
|
26 |
+
v.render(f"pic{i}.png", 500)
|
27 |
+
images = []
|
28 |
+
for i in range(len(outs)):
|
29 |
+
images.append(imageio.imread(f"pic{i}.png"))
|
30 |
+
return imageio.mimsave('movie.gif', images, **{ 'duration': 0.5 })
|
31 |
+
|
32 |
+
animate_chalk(out.original, out.actions)
|
33 |
+
from IPython.display import Image
|
34 |
+
Image("movie.gif")
|