File size: 1,522 Bytes
c885d23
 
 
59fbfad
c885d23
 
 
3f9aaab
c8117c7
c885d23
 
 
3f9aaab
 
 
 
 
5000b70
 
c885d23
 
 
 
3f9aaab
c885d23
 
 
 
 
3f9aaab
c8117c7
5000b70
c8117c7
59fbfad
5000b70
59fbfad
5000b70
59fbfad
 
 
 
 
 
3f9aaab
59fbfad
 
 
5000b70
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
import gradio as gr
import os, threading

from multi_agent import run_multi_agent  

lock = threading.Lock()

# Set environment variables for Hugging Face Spaces
os.environ["LANGCHAIN_PROJECT"] = os.getenv("LANGCHAIN_PROJECT", "langgraph-multi-agent")

LLM = "gpt-4o"

# Fetch the OpenAI API key from the environment
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
if not OPENAI_API_KEY:
    raise EnvironmentError("The environment variable 'OPENAI_API_KEY' is not set. Please configure it in your deployment.")

# Function to invoke the multi-agent process
def invoke(topic):
    if not topic:
        raise gr.Error("Topic is required.")
        
    with lock:
        os.environ["OPENAI_API_KEY"] = OPENAI_API_KEY  # Set the API key from the environment
        article = run_multi_agent(LLM, topic)
        return article

gr.close_all()

# Fetch other environment variables with fallback defaults
default_topic = os.getenv("TOPIC", "Write an article about Artificial Intelligence.")
default_output = os.getenv("OUTPUT", "Your article will appear here after processing.")
default_description = os.getenv("DESCRIPTION", "Generate AI-written articles using Multi-Agent collaboration.")

# Gradio interface without API key input
demo = gr.Interface(
    fn=invoke, 
    inputs=[
        gr.Textbox(label="Topic", value=default_topic, lines=1)
    ],
    outputs=[
        gr.Markdown(label="Article", value=default_output)
    ],
    title="Multi-Agent Article Writing",
    description=default_description
)

demo.launch()