File size: 1,778 Bytes
242965f
cfbcfed
e8da79a
fc7e5cb
5e8e222
cfbcfed
 
dcb6054
 
890784c
e8da79a
471fdf2
780dce9
e8da79a
780dce9
7cfc686
bf7f003
4afd97e
37d316b
cfbcfed
 
 
2a2d23d
cfbcfed
a9f6bbd
 
 
cfbcfed
 
 
 
e8da79a
3b952d8
 
 
e8da79a
 
3b952d8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e8da79a
3b952d8
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 agentops, os, threading

from crew import get_crew

lock = threading.Lock()

LLM_MANAGER = "o3"
LLM_AGENTS = "gpt-4.5-preview"
VERBOSE = False

def invoke(openai_api_key, topic):
    if not openai_api_key:
        raise gr.Error("OpenAI API Key is required.")
    if not topic:
        raise gr.Error("Topic is required.")
        
    agentops.init(os.environ["AGENTOPS_API_KEY"])

    with lock:
        os.environ["OPENAI_API_KEY"] = openai_api_key
    
        article = str(get_crew(LLM_MANAGER, LLM_AGENTS, VERBOSE).kickoff(inputs={"topic": topic}))
    
        print("===")
        print(article)
        print("===")

        del os.environ["OPENAI_API_KEY"]
    
        return article

def clear():
    return ""

gr.close_all()

with gr.Blocks(title="Multi-Agent AI") as assistant:
    gr.Markdown("## Multi-Agent AI: Article Writing")
    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)
                topic = gr.Textbox(label = "Topic", value=os.environ["TOPIC"], lines = 1)            
            with gr.Row():
                clear_btn = gr.ClearButton(
                    components=[openai_api_key, topic]
                )
                submit_btn = gr.Button("Submit", variant="primary")
        with gr.Column(scale=3):
            article = gr.Markdown(label = "Article", value=os.environ["OUTPUT"], line_breaks = True, sanitize_html = False)

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

assistant.launch()