Pablo276 commited on
Commit
395d031
1 Parent(s): 219fa94

Upload app_gradio.py

Browse files
Files changed (1) hide show
  1. app_gradio.py +88 -0
app_gradio.py ADDED
@@ -0,0 +1,88 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from langchain.agents import initialize_agent, Tool
3
+ from langchain.agents import AgentType
4
+ from langchain.chat_models import ChatOpenAI
5
+ from langchain.memory import ConversationBufferMemory
6
+ from langchain.schema import SystemMessage
7
+ import os
8
+ from langchain.agents import initialize_agent, Tool
9
+ from langchain.agents import AgentType
10
+ from langchain.chat_models import ChatOpenAI
11
+ from langchain.schema import SystemMessage
12
+ from langchain.memory import ConversationBufferMemory
13
+ import random
14
+ """"""
15
+ from langchain.prompts import MessagesPlaceholder
16
+ from langchain.memory import ConversationBufferMemory
17
+ import os
18
+
19
+ blacklist = []
20
+ OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
21
+
22
+ def Appointment_settler(parola):
23
+ return "tell the human: 'here is my link to the calendar of free moments, you choose when you want to make the appointment, appointment calendar link: " + str("https://calendly.com/pablorimoldi888/30min'")
24
+
25
+ def convince_the_human(parola):
26
+ global number
27
+ messages = ["ask the human: 'what are your long-term goals?' ", "ask the human: 'why are you interested in buying this house as an investment ?'",
28
+ "ask the human: 'do you think you will be able to honor the agreements made?'"]
29
+ number = random.randint(0, 2)
30
+ while number in blacklist:
31
+ number = random.randint(0, 2)
32
+ if number not in blacklist:
33
+ break
34
+ if number not in blacklist:
35
+ if len(blacklist) < 3:
36
+ blacklist.append(number)
37
+ if len(blacklist) == 3:
38
+ blacklist.clear()
39
+ return messages[number]
40
+
41
+ def house_website(parola):
42
+ return "tell the human: 'this is the link to the house in florida, website link: " + str("https://www.newhomesource.com/learn/how-to-build-house-in-california/'")
43
+
44
+ system_message = SystemMessage(
45
+ content="Your name is Albert, you are a very outgoing, original, likable, charismatic and convincing person. "
46
+ "You are a house salesman, the humans who write to you are potential clients for the purchase of a flat under construction in Florida. "
47
+ "Never say you are an AI, you have to empathize with the customer, you have to sound like a human being. Always use tools.")
48
+
49
+ tools = [
50
+ Tool(
51
+ name="Appointment_settler",
52
+ func=lambda word: Appointment_settler(word),
53
+ description="ALWAYS use when the user wants to set up any kind of appointment, transcribe or translate what is written, but do not omit anything "
54
+ ),
55
+ Tool(
56
+ name="convince_the_human",
57
+ func=lambda word: convince_the_human(word),
58
+ description="uses to convince the user, e.g., when he says: i'm not fully convinced, i'm not sure. DO NOT PARAPHRASE, JUST TRANSCRIBE"
59
+ ),
60
+ Tool(
61
+ name="house_website",
62
+ func=lambda word: house_website(word),
63
+ description="ALWAYS use when the user wants to ask for the house website, transcribe or translate what is written, but do not omit anything "
64
+ )
65
+ ]
66
+
67
+ agent_kwargs = {
68
+ "extra_prompt_messages": [MessagesPlaceholder(variable_name="memory")],
69
+ "system_message": system_message
70
+ }
71
+
72
+ llm = ChatOpenAI(temperature=0, openai_api_key="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", verbose=True, model="gpt-4-0613")
73
+ memory = ConversationBufferMemory(memory_key="memory", return_messages=True)
74
+ mrkl = initialize_agent(tools, llm, memory=memory, agent=AgentType.OPENAI_FUNCTIONS, verbose=True, agent_kwargs=agent_kwargs)
75
+
76
+ def chat_with_user(user_input):
77
+ return mrkl.run(input=user_input)
78
+
79
+ gr_interface = gr.Interface(fn=chat_with_user, inputs="text", outputs="text", live=True, capture_session=True)
80
+
81
+ # Uncomment the following line if you want to launch the app using Streamlit
82
+ # st.title("Nikhil's personal secretary :sunglasses:")
83
+ # st.text_input("You:")
84
+ # st.button("Submit")
85
+ # st.text("Output will appear here")
86
+
87
+ # Uncomment the following line if you want to launch the app using Gradio
88
+ gr_interface.launch()