Update app.py
Browse files
app.py
CHANGED
@@ -49,6 +49,7 @@ conn.close()
|
|
49 |
|
50 |
|
51 |
# Create a sample DataFrame with 3,000 records and 20 columns
|
|
|
52 |
num_records = 3000
|
53 |
num_columns = 20
|
54 |
|
@@ -64,7 +65,7 @@ data["year"] = [random.choice(years) for _ in range(num_records)]
|
|
64 |
data["city"] = [random.choice(cities) for _ in range(num_records)]
|
65 |
|
66 |
table = pd.DataFrame(data)
|
67 |
-
|
68 |
#table = pd.read_csv(csv_file.name, delimiter=",")
|
69 |
#table.fillna(0, inplace=True)
|
70 |
#table = table.astype(str)
|
@@ -73,7 +74,7 @@ data = {
|
|
73 |
"year": [1896, 1900, 1904, 2004, 2008, 2012],
|
74 |
"city": ["athens", "paris", "st. louis", "athens", "beijing", "london"]
|
75 |
}
|
76 |
-
|
77 |
|
78 |
|
79 |
# Load the chatbot model
|
@@ -132,6 +133,7 @@ def sqlquery(input): #, history=[]):
|
|
132 |
global conversation_history
|
133 |
|
134 |
#======================================================================
|
|
|
135 |
batch_size = 10 # Number of records in each batch
|
136 |
num_records = 3000 # Total number of records in the dataset
|
137 |
for start_idx in range(0, num_records, batch_size):
|
@@ -160,7 +162,7 @@ def sqlquery(input): #, history=[]):
|
|
160 |
for response in enumerate(responses):
|
161 |
# Update conversation history
|
162 |
conversation_history.append("Bot: " + response)
|
163 |
-
|
164 |
'''
|
165 |
|
166 |
= []
|
@@ -194,7 +196,7 @@ def sqlquery(input): #, history=[]):
|
|
194 |
'''
|
195 |
|
196 |
# ==========================================================================
|
197 |
-
|
198 |
inputs = [input]
|
199 |
sql_encoding = sql_tokenizer(table=table, query=input, return_tensors="pt")
|
200 |
sql_outputs = sql_model.generate(**sql_encoding)
|
@@ -203,7 +205,7 @@ def sqlquery(input): #, history=[]):
|
|
203 |
#history.append((input, sql_response))
|
204 |
conversation_history.append(("User", input))
|
205 |
conversation_history.append(("Bot", sql_response))
|
206 |
-
|
207 |
# Build conversation string
|
208 |
#conversation = "\n".join([f"User: {user_msg}\nBot: {resp_msg}" for user_msg, resp_msg in conversation_history])
|
209 |
conversation = "\n".join([f"{sender}: {msg}" for sender, msg in conversation_history])
|
@@ -266,36 +268,3 @@ combine_interface = gr.TabbedInterface(
|
|
266 |
if __name__ == '__main__':
|
267 |
combine_interface.launch()
|
268 |
#iface.launch(debug=True)
|
269 |
-
|
270 |
-
|
271 |
-
'''
|
272 |
-
batch_size = 10 # Number of records in each batch
|
273 |
-
num_records = 3000 # Total number of records in the dataset
|
274 |
-
|
275 |
-
for start_idx in range(0, num_records, batch_size):
|
276 |
-
end_idx = min(start_idx + batch_size, num_records)
|
277 |
-
|
278 |
-
# Get a batch of records
|
279 |
-
batch_data = dataset[start_idx:end_idx] # Replace with your dataset
|
280 |
-
|
281 |
-
# Tokenize the batch
|
282 |
-
tokenized_batch = tokenizer.batch_encode_plus(
|
283 |
-
batch_data, padding=True, truncation=True, return_tensors="pt"
|
284 |
-
)
|
285 |
-
|
286 |
-
# Perform inference
|
287 |
-
with torch.no_grad():
|
288 |
-
output = model.generate(
|
289 |
-
input_ids=tokenized_batch["input_ids"],
|
290 |
-
max_length=1024,
|
291 |
-
pad_token_id=tokenizer.eos_token_id,
|
292 |
-
)
|
293 |
-
|
294 |
-
# Decode the output and process the responses
|
295 |
-
responses = [tokenizer.decode(ids, skip_special_tokens=True) for ids in output]
|
296 |
-
|
297 |
-
# Process responses and maintain conversation context
|
298 |
-
# ...
|
299 |
-
|
300 |
-
|
301 |
-
'''
|
|
|
49 |
|
50 |
|
51 |
# Create a sample DataFrame with 3,000 records and 20 columns
|
52 |
+
'''
|
53 |
num_records = 3000
|
54 |
num_columns = 20
|
55 |
|
|
|
65 |
data["city"] = [random.choice(cities) for _ in range(num_records)]
|
66 |
|
67 |
table = pd.DataFrame(data)
|
68 |
+
'''
|
69 |
#table = pd.read_csv(csv_file.name, delimiter=",")
|
70 |
#table.fillna(0, inplace=True)
|
71 |
#table = table.astype(str)
|
|
|
74 |
"year": [1896, 1900, 1904, 2004, 2008, 2012],
|
75 |
"city": ["athens", "paris", "st. louis", "athens", "beijing", "london"]
|
76 |
}
|
77 |
+
table = pd.DataFrame.from_dict(data)
|
78 |
|
79 |
|
80 |
# Load the chatbot model
|
|
|
133 |
global conversation_history
|
134 |
|
135 |
#======================================================================
|
136 |
+
'''
|
137 |
batch_size = 10 # Number of records in each batch
|
138 |
num_records = 3000 # Total number of records in the dataset
|
139 |
for start_idx in range(0, num_records, batch_size):
|
|
|
162 |
for response in enumerate(responses):
|
163 |
# Update conversation history
|
164 |
conversation_history.append("Bot: " + response)
|
165 |
+
'''
|
166 |
'''
|
167 |
|
168 |
= []
|
|
|
196 |
'''
|
197 |
|
198 |
# ==========================================================================
|
199 |
+
|
200 |
inputs = [input]
|
201 |
sql_encoding = sql_tokenizer(table=table, query=input, return_tensors="pt")
|
202 |
sql_outputs = sql_model.generate(**sql_encoding)
|
|
|
205 |
#history.append((input, sql_response))
|
206 |
conversation_history.append(("User", input))
|
207 |
conversation_history.append(("Bot", sql_response))
|
208 |
+
|
209 |
# Build conversation string
|
210 |
#conversation = "\n".join([f"User: {user_msg}\nBot: {resp_msg}" for user_msg, resp_msg in conversation_history])
|
211 |
conversation = "\n".join([f"{sender}: {msg}" for sender, msg in conversation_history])
|
|
|
268 |
if __name__ == '__main__':
|
269 |
combine_interface.launch()
|
270 |
#iface.launch(debug=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|