File size: 1,090 Bytes
f122d9d
965981d
a4583a7
a67fae1
9bcfd60
965981d
 
9bcfd60
 
f122d9d
06d9c7d
 
4b0a157
0db12d1
f122d9d
0db12d1
844f26f
f122d9d
965981d
 
10a0568
965981d
10a0568
f122d9d
 
 
 
 
4b0a157
9659409
ac98399
2462f34
f122d9d
 
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
import gradio as gr
import os, threading

from multi_agent import run_multi_agent

lock = threading.Lock()

os.environ["LANGCHAIN_TRACING_V2"] = "true"
os.environ["LANGCHAIN_PROJECT"] = "langgraph-multi-agent"

LLM = "gpt-4o"

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.")
        
    with lock:
        os.environ["OPENAI_API_KEY"] = openai_api_key
        article = run_multi_agent(LLM, topic)
        del os.environ["OPENAI_API_KEY"]
        return article

gr.close_all()

demo = gr.Interface(fn = invoke, 
                    inputs = [gr.Textbox(label = "OpenAI API Key", type = "password", lines = 1),
                              gr.Textbox(label = "Topic", value=os.environ["TOPIC"], lines = 1)],
                    outputs = [gr.Markdown(label = "Generated Article", value=os.environ["OUTPUT"])],
                    title = "Multi-Agent AI: Article Generation",
                    description = os.environ["DESCRIPTION"])

demo.launch()