Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import os, threading
|
3 |
+
|
4 |
+
from multi_agent import run_multi_agent
|
5 |
+
|
6 |
+
lock = threading.Lock()
|
7 |
+
|
8 |
+
os.environ["LANGCHAIN_PROJECT"] = "langgraph-multi-agent"
|
9 |
+
os.environ["LANGCHAIN_TRACING_V2"] = "true"
|
10 |
+
|
11 |
+
LLM = "gpt-4o"
|
12 |
+
|
13 |
+
def invoke(openai_api_key, topic):
|
14 |
+
if not openai_api_key:
|
15 |
+
raise gr.Error("OpenAI API Key is required.")
|
16 |
+
if not topic:
|
17 |
+
raise gr.Error("Topic is required.")
|
18 |
+
|
19 |
+
with lock:
|
20 |
+
os.environ["OPENAI_API_KEY"] = openai_api_key
|
21 |
+
article = run_multi_agent(LLM, topic)
|
22 |
+
del os.environ["OPENAI_API_KEY"]
|
23 |
+
return article
|
24 |
+
|
25 |
+
gr.close_all()
|
26 |
+
|
27 |
+
demo = gr.Interface(fn = invoke,
|
28 |
+
inputs = [gr.Textbox(label = "OpenAI API Key", type = "password", lines = 1),
|
29 |
+
gr.Textbox(label = "Topic", value=os.environ["TOPIC"], lines = 1)],
|
30 |
+
outputs = [gr.Markdown(label = "Article", value=os.environ["OUTPUT"])],
|
31 |
+
title = "Multi-Agent AI: Article Writing",
|
32 |
+
description = os.environ["DESCRIPTION"])
|
33 |
+
|
34 |
+
demo.launch()
|