File size: 1,162 Bytes
242965f
cfbcfed
e8da79a
fc7e5cb
5e8e222
cfbcfed
 
bb7709c
8606c0a
e8da79a
471fdf2
780dce9
e8da79a
780dce9
7cfc686
bf7f003
4afd97e
37d316b
cfbcfed
 
 
c896c7a
cfbcfed
 
 
 
 
 
 
 
e8da79a
 
 
 
 
471fdf2
69e71cd
30979c6
2dead2b
e8da79a
 
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
import gradio as gr
import agentops, os, threading

from crew import get_crew

lock = threading.Lock()

LLM = "gpt-4o"
TEMPERATURE = 0.7

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 = get_crew(LLM, TEMPERATURE).kickoff(inputs={"topic": topic})
    
        #print("===")
        #print(article)
        #print("===")

        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()