Update app.py
Browse files
app.py
CHANGED
@@ -30,7 +30,6 @@ Our main method first asks the user for their openai key. Then we have some test
|
|
30 |
|
31 |
#imports
|
32 |
import pandas as pd
|
33 |
-
from textblob import TextBlob
|
34 |
import spacy
|
35 |
import tensorflow_hub as hub
|
36 |
from scipy.spatial import distance
|
@@ -51,11 +50,6 @@ customer = pd.read_csv('customer_data.csv')
|
|
51 |
order = pd.read_csv('order_data.csv')
|
52 |
service = pd.read_csv('cust_service_data.csv')
|
53 |
|
54 |
-
"""# Spelling correction"""
|
55 |
-
|
56 |
-
def correctSpelling(sentence):
|
57 |
-
return str(TextBlob(sentence).correct())
|
58 |
-
|
59 |
"""# Entity Extraction"""
|
60 |
|
61 |
# extract entities, label, label definition from natural language questions and append to dataframe
|
@@ -144,97 +138,6 @@ def query_to_SQL_to_MongoDB(query, key, organization):
|
|
144 |
SQL = response['choices'][0]['text'] # extract the outputted SQL Query
|
145 |
return complex_SQL_to_MongoDB(SQL)
|
146 |
|
147 |
-
#Example:
|
148 |
-
|
149 |
-
'''
|
150 |
-
db.Customer.aggregate(
|
151 |
-
|
152 |
-
{
|
153 |
-
|
154 |
-
$lookup:
|
155 |
-
|
156 |
-
{
|
157 |
-
|
158 |
-
from: "Orders",
|
159 |
-
localField: "cust_id",
|
160 |
-
foreignField: "cust_id",
|
161 |
-
as: "Customer"
|
162 |
-
|
163 |
-
}
|
164 |
-
|
165 |
-
},
|
166 |
-
|
167 |
-
{
|
168 |
-
|
169 |
-
$group:
|
170 |
-
|
171 |
-
{
|
172 |
-
|
173 |
-
_id: "cust_name",
|
174 |
-
count: {$count : {}}
|
175 |
-
|
176 |
-
}
|
177 |
-
|
178 |
-
},
|
179 |
-
|
180 |
-
{
|
181 |
-
|
182 |
-
$sort:{count : -1}
|
183 |
-
|
184 |
-
},
|
185 |
-
|
186 |
-
{
|
187 |
-
|
188 |
-
$limit: 1
|
189 |
-
|
190 |
-
}
|
191 |
-
|
192 |
-
)
|
193 |
-
|
194 |
-
|
195 |
-
'''
|
196 |
-
|
197 |
-
'''
|
198 |
-
db.Customer.aggregate(
|
199 |
-
{
|
200 |
-
$lookup:
|
201 |
-
{
|
202 |
-
from : "Orders",
|
203 |
-
localField: "cust_id",
|
204 |
-
foreignField: "cust_id",
|
205 |
-
as: "Customer"
|
206 |
-
|
207 |
-
}
|
208 |
-
},
|
209 |
-
{
|
210 |
-
$lookup:
|
211 |
-
{
|
212 |
-
from : "Driver",
|
213 |
-
localField: "driver_id",
|
214 |
-
foreignField: "driver_id",
|
215 |
-
as: "Customer"
|
216 |
-
}
|
217 |
-
},
|
218 |
-
|
219 |
-
{
|
220 |
-
$match:
|
221 |
-
{
|
222 |
-
|
223 |
-
$group:
|
224 |
-
{
|
225 |
-
_id: "c.cust_name",
|
226 |
-
count: {$count: {order_id}
|
227 |
-
}
|
228 |
-
}
|
229 |
-
|
230 |
-
},
|
231 |
-
{
|
232 |
-
$sort: {count : -1}
|
233 |
-
},
|
234 |
-
{ $limit : 1 }
|
235 |
-
|
236 |
-
)
|
237 |
-
'''
|
238 |
|
239 |
keywords = {'INNER', 'FROM', 'WHERE', 'GROUP', 'BY', 'ON', 'SELECT', 'BETWEEN', 'LIMIT', 'AND', 'ORDER'}
|
240 |
|
|
|
30 |
|
31 |
#imports
|
32 |
import pandas as pd
|
|
|
33 |
import spacy
|
34 |
import tensorflow_hub as hub
|
35 |
from scipy.spatial import distance
|
|
|
50 |
order = pd.read_csv('order_data.csv')
|
51 |
service = pd.read_csv('cust_service_data.csv')
|
52 |
|
|
|
|
|
|
|
|
|
|
|
53 |
"""# Entity Extraction"""
|
54 |
|
55 |
# extract entities, label, label definition from natural language questions and append to dataframe
|
|
|
138 |
SQL = response['choices'][0]['text'] # extract the outputted SQL Query
|
139 |
return complex_SQL_to_MongoDB(SQL)
|
140 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
141 |
|
142 |
keywords = {'INNER', 'FROM', 'WHERE', 'GROUP', 'BY', 'ON', 'SELECT', 'BETWEEN', 'LIMIT', 'AND', 'ORDER'}
|
143 |
|