Johnniewhite commited on
Commit
994d7ce
1 Parent(s): 154bf20

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +126 -0
app.py ADDED
@@ -0,0 +1,126 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import gradio as gr
3
+ import time
4
+
5
+ from langchain.chat_models import ChatOpenAI
6
+
7
+ # Set your OpenAI API key
8
+ os.environ["OPENAI_API_KEY"] = "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"
9
+
10
+ # Initialize the ChatOpenAI model
11
+ chat_model = ChatOpenAI(model="gpt-3.5-turbo-1106", temperature=0.2)
12
+
13
+ # Define the apartment details dictionary
14
+ apartment_details = {
15
+ "1": {
16
+ "name": "Luxury Apartment in Downtown",
17
+ "address": "123 Main St, Anytown, USA",
18
+ "bedrooms": 2,
19
+ "bathrooms": 2,
20
+ "sqft": 1200,
21
+ "price": "$2000/month",
22
+ "description": "Beautiful luxury apartment in the heart of downtown. Spacious living area, modern kitchen, and stunning views."
23
+ },
24
+ "2": {
25
+ "name": "Cozy Studio near Park",
26
+ "address": "456 Elm St, Anytown, USA",
27
+ "bedrooms": 0,
28
+ "bathrooms": 1,
29
+ "sqft": 500,
30
+ "price": "$1000/month",
31
+ "description": "Charming studio apartment located near the park. Perfect for a single person or couple. Close to amenities."
32
+ },
33
+ "3": {
34
+ "name": "Family-Friendly Townhouse",
35
+ "address": "789 Oak St, Anytown, USA",
36
+ "bedrooms": 3,
37
+ "bathrooms": 2.5,
38
+ "sqft": 1800,
39
+ "price": "$2500/month",
40
+ "description": "Spacious townhouse with plenty of room for a family. Close to schools, parks, and shopping centers."
41
+ }
42
+ }
43
+
44
+ def provide_information(apartment_id=None):
45
+ if apartment_id:
46
+ apartment_info = apartment_details.get(apartment_id)
47
+ if apartment_info:
48
+ return (
49
+ f"Name: {apartment_info['name']}\n"
50
+ f"Address: {apartment_info['address']}\n"
51
+ f"Bedrooms: {apartment_info['bedrooms']}\n"
52
+ f"Bathrooms: {apartment_info['bathrooms']}\n"
53
+ f"Square Footage: {apartment_info['sqft']} sqft\n"
54
+ f"Price: {apartment_info['price']}\n"
55
+ f"Description: {apartment_info['description']}"
56
+ )
57
+ else:
58
+ return "Apartment not found"
59
+ else:
60
+ all_apartments_info = ""
61
+ for apartment_id, apartment_info in apartment_details.items():
62
+ all_apartments_info += (
63
+ f"Apartment ID: {apartment_id}\n"
64
+ f"Name: {apartment_info['name']}\n"
65
+ f"Address: {apartment_info['address']}\n"
66
+ f"Bedrooms: {apartment_info['bedrooms']}\n"
67
+ f"Bathrooms: {apartment_info['bathrooms']}\n"
68
+ f"Square Footage: {apartment_info['sqft']} sqft\n"
69
+ f"Price: {apartment_info['price']}\n"
70
+ f"Description: {apartment_info['description']}\n\n"
71
+ )
72
+ return all_apartments_info
73
+
74
+ def make_purchase_reservation(apartment_id: str, documents: dict):
75
+ # Print the provided data and a success message
76
+ print(f"Apartment ID: {apartment_id}, Documents: {documents}")
77
+ return "SUCCESS"
78
+
79
+ def execute_purchase(apartment_id, documents):
80
+ # For simplicity, let's just print the data provided and a success message
81
+ print(f"Apartment ID: {apartment_id}, Documents: {documents}")
82
+ return make_purchase_reservation(apartment_id, documents)
83
+
84
+ def update_owner_information(owner_id, new_number):
85
+ # For simplicity, let's just print the data provided and a success message
86
+ print(f"Owner ID: {owner_id}, New Number: {new_number}")
87
+ return "Owner information updated successfully."
88
+
89
+ def handle_message(message, history=None):
90
+ # Split message into parts
91
+ parts = message.split()
92
+
93
+ # Check for different categories of problems
94
+ if "provide information" in message:
95
+ if "on Apartment" in message:
96
+ apartment_id = parts[-1]
97
+ return provide_information(apartment_id)
98
+ else:
99
+ return provide_information()
100
+ elif "execute purchase" in message:
101
+ apartment_id, *documents = parts[-2:]
102
+ return execute_purchase(apartment_id, " ".join(documents))
103
+ elif "update owner information" in message:
104
+ owner_id, new_number = parts[-2:]
105
+ return update_owner_information(owner_id, new_number)
106
+ elif "list all houses" in message:
107
+ return provide_information()
108
+ else:
109
+ # Use the LangChain model for general chat
110
+ response = chat_model.predict(message)
111
+ return response
112
+
113
+ # Create a Gradio chat interface
114
+ gr.ChatInterface(
115
+ handle_message,
116
+ chatbot=gr.Chatbot(height=300),
117
+ textbox=gr.Textbox(placeholder="How can I help you today?", container=True, scale=8),
118
+ title="Joe's Real Estate Chatbot",
119
+ description="Ask D'Law any law related question",
120
+ theme="compact",
121
+ examples=["list all houses", "provide information on Apartment 2", "execute purchase on apartment 2", "update owner information on apartment"],
122
+ retry_btn=None,
123
+ submit_btn='Send',
124
+ undo_btn=False,
125
+ clear_btn="Clear",
126
+ ).launch(share=True)