|
import gradio as gr |
|
import os, threading |
|
|
|
from multi_agent import run_multi_agent |
|
|
|
lock = threading.Lock() |
|
|
|
LLM = "gpt-4o" |
|
|
|
def invoke(openai_api_key, message): |
|
if not openai_api_key: |
|
raise gr.Error("OpenAI API Key is required.") |
|
|
|
if not message: |
|
raise gr.Error("Message is required.") |
|
|
|
with lock: |
|
os.environ["OPENAI_API_KEY"] = openai_api_key |
|
result = run_multi_agent(LLM, message) |
|
del os.environ["OPENAI_API_KEY"] |
|
return result |
|
|
|
gr.close_all() |
|
|
|
demo = gr.Interface(fn = invoke, |
|
inputs = [gr.Textbox(label = "OpenAI API Key", type = "password", lines = 1), |
|
gr.Textbox(label = "Message", value = "Today is 06/03/2024. Create a plot showing stock gain YTD for NVDA and TLSA. Make sure the code is in markdown code block and save the figure to a file ytd_stock_gains.png.")], |
|
outputs = [gr.Markdown(label = "Result", value=os.environ["OUTPUT"])], |
|
title = "Multi-Agent AI: Financial Analysis", |
|
description = os.environ["DESCRIPTION"]) |
|
|
|
demo.launch() |