Commit
Β·
49655cc
1
Parent(s):
bb4811f
add api key input option
Browse files
app.py
CHANGED
@@ -14,12 +14,12 @@ OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
|
|
14 |
if TAVILY_API_KEY:
|
15 |
print("TAVILY_API_KEY found!")
|
16 |
else:
|
17 |
-
print("
|
18 |
|
19 |
if OPENAI_API_KEY:
|
20 |
print("OPENAI_API_KEY found!")
|
21 |
else:
|
22 |
-
print("
|
23 |
|
24 |
def extract_leaf_nodes(data, parent_key=''):
|
25 |
leaf_nodes = {}
|
@@ -77,6 +77,10 @@ with gr.Blocks() as demo:
|
|
77 |
with gr.Row():
|
78 |
with gr.Column(scale=1):
|
79 |
gr.Markdown("### π Input")
|
|
|
|
|
|
|
|
|
80 |
schema_input = gr.Textbox(
|
81 |
label="Extraction Schema (JSON)",
|
82 |
value=json.dumps({
|
@@ -99,10 +103,22 @@ with gr.Blocks() as demo:
|
|
99 |
output_display = gr.Markdown(label="Extracted Information")
|
100 |
time_display = gr.Textbox(label="Processing Time (seconds)", interactive=False)
|
101 |
|
102 |
-
def on_submit(schema, topic):
|
103 |
-
data, time_taken = agent_response(schema, topic)
|
104 |
-
return data, f"{time_taken:.2f}"
|
105 |
|
106 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
107 |
|
108 |
demo.launch(share=True)
|
|
|
14 |
if TAVILY_API_KEY:
|
15 |
print("TAVILY_API_KEY found!")
|
16 |
else:
|
17 |
+
print("Please provide your TAVILY_API_KEY.")
|
18 |
|
19 |
if OPENAI_API_KEY:
|
20 |
print("OPENAI_API_KEY found!")
|
21 |
else:
|
22 |
+
print("Please provide your OPENAI_API_KEY not found")
|
23 |
|
24 |
def extract_leaf_nodes(data, parent_key=''):
|
25 |
leaf_nodes = {}
|
|
|
77 |
with gr.Row():
|
78 |
with gr.Column(scale=1):
|
79 |
gr.Markdown("### π Input")
|
80 |
+
tavily_key_input = gr.Textbox(label="Tavily API Key", type="password",
|
81 |
+
placeholder="Enter your Tavily API Key")
|
82 |
+
openai_key_input = gr.Textbox(label="OpenAI API Key", type="password",
|
83 |
+
placeholder="Enter your OpenAI API Key")
|
84 |
schema_input = gr.Textbox(
|
85 |
label="Extraction Schema (JSON)",
|
86 |
value=json.dumps({
|
|
|
103 |
output_display = gr.Markdown(label="Extracted Information")
|
104 |
time_display = gr.Textbox(label="Processing Time (seconds)", interactive=False)
|
105 |
|
|
|
|
|
|
|
106 |
|
107 |
+
def on_submit(schema, topic, tavily_key, openai_key):
|
108 |
+
try:
|
109 |
+
# Set API keys as environment variables
|
110 |
+
os.environ["TAVILY_API_KEY"] = tavily_key
|
111 |
+
os.environ["OPENAI_API_KEY"] = openai_key
|
112 |
+
|
113 |
+
# Call agent_response
|
114 |
+
data, time_taken = agent_response(schema, topic)
|
115 |
+
return data, f"{time_taken:.2f}"
|
116 |
+
except Exception as e:
|
117 |
+
return f"β An error occurred: {str(e)}", "0.00"
|
118 |
+
|
119 |
+
|
120 |
+
submit_button.click(on_submit,
|
121 |
+
inputs=[schema_input, topic_input, tavily_key_input, openai_key_input],
|
122 |
+
outputs=[output_display, time_display])
|
123 |
|
124 |
demo.launch(share=True)
|