Spaces:
Sleeping
Sleeping
Commit ·
04bb0be
1
Parent(s): 6e0f043
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import openai
|
| 3 |
+
import gradio as gr
|
| 4 |
+
from dotenv import load_dotenv, find_dotenv
|
| 5 |
+
|
| 6 |
+
_ = load_dotenv(find_dotenv()) # read local .env file
|
| 7 |
+
|
| 8 |
+
openai.api_key = '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'
|
| 9 |
+
|
| 10 |
+
chat_history = []
|
| 11 |
+
|
| 12 |
+
def get_completion(messages, model="gpt-3.5-turbo", temperature=0):
|
| 13 |
+
response = openai.ChatCompletion.create(
|
| 14 |
+
model=model,
|
| 15 |
+
messages=messages,
|
| 16 |
+
temperature=temperature, # the degree of randomness of the model's output
|
| 17 |
+
)
|
| 18 |
+
return response.choices[0].message["content"]
|
| 19 |
+
|
| 20 |
+
def conversation_interface(prompt):
|
| 21 |
+
global chat_history
|
| 22 |
+
|
| 23 |
+
if not chat_history:
|
| 24 |
+
# Initialize conversation with system message
|
| 25 |
+
system_message = {'role':'system', 'content':"""
|
| 26 |
+
You are Mortgage Loan Sales officer , Your job role is to collect information from customer step by step, solve there queries in between and finally provide them with the calculated mortgae loan amount they are eligible for. \
|
| 27 |
+
You first greet the customer by calling there first name, then ask in which county client is interested in, \
|
| 28 |
+
and then asks What’s your Credit Score range?. \
|
| 29 |
+
and then ask Did you have any of the following Bankruptcy, Foreclosure, Short Sales, \
|
| 30 |
+
and then ask How much is your down payment?, \
|
| 31 |
+
and then ask Monthly Income * (Before Taxes)?, \
|
| 32 |
+
and then ask Monthly Credit Payments?, \
|
| 33 |
+
and then ask Car Payments?, \
|
| 34 |
+
and then ask Personal Loan Payments?, \
|
| 35 |
+
and then ask Credit Card(Min payments)?, \
|
| 36 |
+
and then ask Other Expenses?, \
|
| 37 |
+
and then ask Other Mortgages?, \
|
| 38 |
+
and then ask Student Loan(Balance Owed)?, \
|
| 39 |
+
You pursue the customer to get all the details from him. \
|
| 40 |
+
You act as a smart sales person and have the conversation accordingly, try to insist him on having all the details. \
|
| 41 |
+
You wait after asking every question for customer to answer, if he says he is not comfortable then you move to next question. \
|
| 42 |
+
If customer doesnt understand any term you help him in understanding it. \
|
| 43 |
+
Be friendly, kind and gentle to customer. \
|
| 44 |
+
If customer tries ask for anything else except mortgage loan , you respond by saying its not your domain area, and you do not make up any answer. \
|
| 45 |
+
"""}
|
| 46 |
+
chat_history.append(system_message)
|
| 47 |
+
|
| 48 |
+
user_message = {'role': 'user', 'content': prompt}
|
| 49 |
+
chat_history.append(user_message)
|
| 50 |
+
|
| 51 |
+
response = get_completion(chat_history)
|
| 52 |
+
chat_history.append({'role': 'assistant', 'content': response})
|
| 53 |
+
|
| 54 |
+
return response
|
| 55 |
+
|
| 56 |
+
iface = gr.Interface(
|
| 57 |
+
fn=conversation_interface,
|
| 58 |
+
inputs="text",
|
| 59 |
+
outputs="text",
|
| 60 |
+
layout="vertical",
|
| 61 |
+
title="Mortgage Loan Sales Assistant",
|
| 62 |
+
description="Chat with the Mortgage Loan Sales Assistant to calculate your eligibility for a mortgage loan."
|
| 63 |
+
)
|
| 64 |
+
|
| 65 |
+
iface.launch(share =True)
|