File size: 1,557 Bytes
4ad819c
2ff96fe
4ad819c
987703d
4ad819c
2ff96fe
 
c89b216
4263014
4ad819c
987703d
8dad0e5
4ad819c
61cfb27
2ff96fe
 
 
 
11183d0
 
 
2ff96fe
4ad819c
8b6520a
 
4ad819c
8b6520a
4ad819c
8b6520a
 
 
 
 
 
 
 
 
 
 
 
 
 
37bcdfd
8b6520a
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
import os, threading

from multi_agent import run_multi_agent

lock = threading.Lock()

LLM_WHITE = "gpt-4.1"
LLM_BLACK = "gpt-4o"

def invoke(openai_api_key, num_moves = 10):
    if not openai_api_key:
        raise gr.Error("OpenAI API Key is required.")

    with lock:
        os.environ["OPENAI_API_KEY"] = openai_api_key
        result = run_multi_agent(LLM_WHITE, LLM_BLACK, num_moves)
        del os.environ["OPENAI_API_KEY"]
        print("===")
        print(result)
        print("===")
        return result

def clear():
    return ""

gr.close_all()

with gr.Blocks() as assistant:
    gr.Markdown("## Multi-Agent AI: Chess")
    gr.Markdown(os.environ.get("DESCRIPTION"))

    with gr.Row():
        with gr.Column(scale=1):
            with gr.Row():
                openai_api_key = gr.Textbox(label = "OpenAI API Key", type = "password", lines = 1)
                num_moves = gr.Number(label = "Number of Moves", value = 10, minimum = 1, maximum = 50)
            with gr.Row():
                clear_btn = gr.ClearButton(
                    components=[openai_api_key, num_moves]
                )
                submit_btn = gr.Button("Submit", variant="primary")
        with gr.Column(scale=2):
            game = gr.Markdown(label = "Game", value=os.environ["OUTPUT"], line_breaks=True, sanitize_html=False)

    clear_btn.click(
        fn=clear,
        outputs=game
    )
    
    submit_btn.click(
        fn=invoke,
        inputs=[openai_api_key, num_moves],
        outputs=game
    )

assistant.launch()