Spaces:
Sleeping
Sleeping
# import os | |
import openai | |
import gradio as gr | |
# from dotenv import load_dotenv, find_dotenv | |
# _ = load_dotenv(find_dotenv()) # read local .env file | |
# def get_openai_api_key(api_key): | |
# openai.api_key = api_key | |
# return openai.api_key | |
chat_history = [] | |
def get_completion(messages, model="gpt-3.5-turbo", temperature=0): | |
response = openai.ChatCompletion.create( | |
model=model, | |
messages=messages, | |
temperature=temperature, # the degree of randomness of the model's output | |
) | |
return response.choices[0].message["content"] | |
def conversation_interface(api_key,prompt): | |
openai.api_key = api_key | |
global chat_history | |
if not chat_history: | |
# Initialize conversation with system message | |
system_message = {'role':'system', 'content':""" | |
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. \ | |
You first greet the customer by calling there first name, then ask in which county client is interested in, \ | |
and if customer says city in US you capture which county it belongs, reconfirm from customer is this is the county he mean, \ | |
and then asks What’s your Credit Score range?. \ | |
and then ask Did you have any of the following Bankruptcy, Foreclosure, Short Sales, \ | |
and then ask How much is your down payment?, \ | |
and then ask Monthly Income * (Before Taxes)?, \ | |
and then ask Monthly Credit Payments?, \ | |
and then ask Car Payments?, \ | |
and then ask Personal Loan Payments?, \ | |
and then ask Credit Card(Min payments)?, \ | |
and then ask Other Expenses?, \ | |
and then ask Other Mortgages?, \ | |
and then ask Student Loan(Balance Owed)?. \ | |
After getting all details from customer you reconfirm all inputs in tabular format, if customer wants to update you let them update, \ | |
and atlast you calculate the loan amount he is eligible for. \ | |
You pursue the customer to get all the details from him. \ | |
You act as a smart sales person and have the conversation accordingly, try to insist him on having all the details. \ | |
You wait after asking every question for customer to answer, if he says he is not comfortable then you move to next question. \ | |
If customer doesnt understand any term you help him in understanding it. \ | |
Be friendly, kind and gentle to customer. \ | |
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. \ | |
"""} | |
chat_history.append(system_message) | |
user_message = {'role': 'user', 'content': prompt} | |
chat_history.append(user_message) | |
response = get_completion(chat_history) | |
chat_history.append({'role': 'assistant', 'content': response}) | |
return response | |
gr.Interface( | |
fn=conversation_interface, | |
inputs=["text", "text"], | |
outputs="text", | |
layout="vertical", | |
title="Mortgage Loan Sales Assistant", | |
description="Chat with the Mortgage Loan Sales Assistant to calculate your eligibility for a mortgage loan." | |
).launch() | |