Spaces:
Runtime error
Runtime error
File size: 2,325 Bytes
fd5da23 c82eb8a 7711652 c82eb8a 6b60852 c82eb8a 6b60852 c82eb8a 6b60852 c82eb8a fd5da23 c82eb8a |
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 |
import gradio as gr
import ai
import github_manager
import webbrowser
def main():
pre_prompt = """using pygame and no sprites, create: """
initial_prompt = """Conway's game of life, but the user controls one of the squares. If the square dies, the game is over."""
add_example = False
post_prompt = ""
if add_example:
example_code_file_path = "resources/main.py"
with open(example_code_file_path, "r") as file:
example_code = file.read()
post_prompt = example_code
with gr.Blocks() as app:
inp = gr.Textbox(label="Input Prompt",
value=initial_prompt)
with gr.Row():
model_choice = gr.Dropdown(label="Select Model",
choices=[m for m in ai.models],
value=ai.models[0],
type="index",
interactive=True)
no_tokens = gr.Number(label="Tokens", value=1000)
btn = gr.Button(value="Generate Game")
with gr.Column(visible=False) as save_col:
save_button = gr.Button("Build The Game")
with gr.Column(visible=False) as play_col:
play_button = gr.Button("Play The Game")
out = gr.Code(label="Generated Code")
def generate(prompt, model_index, max_tokens):
final_prompt = f"""{pre_prompt} {prompt}. {post_prompt}"""
generated_code = ai.generate_code(prompt=final_prompt,
model_index=model_index,
max_tokens=max_tokens)
return {
out: generated_code,
save_col: gr.Column(visible=True),
}
def save(text):
github_manager.update_repo(text)
return {
play_col: gr.Column(visible=True)
}
def play():
webbrowser.open(github_manager.game_link())
btn.click(generate, inputs=[inp, model_choice, no_tokens], outputs=[out, save_col], queue=True)
save_button.click(save, inputs=[out], outputs=[play_col])
play_button.click(play, inputs=[], outputs=[])
app.launch(share=True)
if __name__ == "__main__":
main()
|