fynn3003 commited on
Commit
651f3d7
·
1 Parent(s): 2f71f41
Files changed (1) hide show
  1. app.py +33 -0
app.py ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from langchain.llms.openai import OpenAI
3
+ import os
4
+ from langchain.agents import initialize_agent
5
+ from langchain.agents import load_tools
6
+
7
+ os.environ["OPENAI_API_KEY"] = "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"
8
+ os.environ["SERPAPI_API_KEY"] = "e109a79c9b6a844c889c8b3f65430f3ea17c4362de514eafeb6030414ec6f808"
9
+
10
+ llm = OpenAI(temperature=0, max_tokens=1000, model_name='text-davinci-003')
11
+
12
+ def answer_question(question):
13
+ agent_exe = initialize_agent(
14
+ llm=OpenAI(temperature=0),
15
+ tools=load_tools(["python_repl", "serpapi", "llm-math"], llm=llm),
16
+ return_intermediate_steps=True,
17
+ verbose=True,
18
+ )
19
+ response = agent_exe({"input": question})
20
+ answer = response["output"]
21
+ steps = response["intermediate_steps"]
22
+ return answer, steps
23
+
24
+ ifaces = gr.Interface(
25
+ fn=answer_question,
26
+ inputs=gr.Textbox(label="Question",
27
+ placeholder="What's the square root, of the age, of Leonardo DiCaprio's latest girlfriend"),
28
+ outputs=[gr.Textbox(label="Answer"), gr.JSON(label="Steps", show_label=False)],
29
+ title="Helpful Agent",
30
+ description="This is an Agent, which uses OpenAI's text-davinci-003 model, and the tools: SerpAPI, Python REPL, and Language Learning Machine Math, depending on your request"
31
+ )
32
+ ifaces.launch()
33
+