iShare commited on
Commit
729f397
·
1 Parent(s): ebf11ca

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -0
app.py ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ from langchain.agents import Tool
3
+ from langchain.memory import ConversationBufferMemory
4
+ from langchain.chat_models import ChatOpenAI
5
+ from langchain.utilities import GoogleSearchAPIWrapper
6
+ from langchain.agents import initialize_agent
7
+ import gradio as gr
8
+
9
+ from dotenv import load_dotenv
10
+ load_dotenv()
11
+
12
+ OPENAI_API_KEY =os.getenv("OPENAI_API_KEY")
13
+ GOOGLE_API_KEY =os.getenv("GOOGLE_API_KEY")
14
+ GOOGLE_CSE_ID =os.getenv("GOOGLE_CSE_ID")
15
+
16
+
17
+ search = GoogleSearchAPIWrapper()
18
+ tools = [
19
+ Tool(
20
+ name ="Search" ,
21
+ func=search.run,
22
+ description="useful when you need to answer questions about current events"
23
+ ),
24
+ ]
25
+
26
+ memory = ConversationBufferMemory(memory_key="chat_history", return_messages=True)
27
+
28
+ llm=ChatOpenAI(temperature=0)
29
+ agent_chain = initialize_agent(tools, llm, agent="chat-conversational-react-description",
30
+ verbose=True, memory=memory)
31
+
32
+ def chat_response(input_text):
33
+ response = agent_chain.run(input=input_text)
34
+ return response
35
+
36
+ interface = gr.Interface(fn=chat_response, inputs="text", outputs="text", description="Chat with a conversational agent")
37
+
38
+ interface.launch(share=True)