Update app.py
Browse files
app.py
CHANGED
|
@@ -1,11 +1,44 @@
|
|
| 1 |
import torch
|
| 2 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
|
| 4 |
-
|
| 5 |
-
|
|
|
|
|
|
|
| 6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
def predict(input, history=[]):
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
# tokenize the new input sentence
|
| 10 |
new_user_input_ids = tokenizer.encode(input + tokenizer.eos_token, return_tensors='pt')
|
| 11 |
|
|
@@ -29,6 +62,8 @@ interface = gr.Interface(
|
|
| 29 |
css=".footer {display:none !important}",
|
| 30 |
inputs=["text", "state"],
|
| 31 |
outputs=["chatbot", "state"],
|
|
|
|
|
|
|
| 32 |
)
|
| 33 |
|
| 34 |
if __name__ == '__main__':
|
|
|
|
| 1 |
import torch
|
| 2 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 3 |
+
from transformers import TapexTokenizer, BartForConditionalGeneration
|
| 4 |
+
import pandas as pd
|
| 5 |
+
import torch
|
| 6 |
+
|
| 7 |
+
import numpy as np
|
| 8 |
+
import time
|
| 9 |
+
import os
|
| 10 |
+
#import pkg_resources
|
| 11 |
+
|
| 12 |
+
'''
|
| 13 |
+
# Get a list of installed packages and their versions
|
| 14 |
+
installed_packages = {pkg.key: pkg.version for pkg in pkg_resources.working_set}
|
| 15 |
|
| 16 |
+
# Print the list of packages
|
| 17 |
+
for package, version in installed_packages.items():
|
| 18 |
+
print(f"{package}=={version}")
|
| 19 |
+
'''
|
| 20 |
|
| 21 |
+
# Load the chatbot model
|
| 22 |
+
chatbot_model_name = "microsoft/DialoGPT-medium"
|
| 23 |
+
tokenizer = AutoTokenizer.from_pretrained(chatbot_model_name)
|
| 24 |
+
model = AutoModelForCausalLM.from_pretrained(chatbot_model_name)
|
| 25 |
+
|
| 26 |
+
# Load the SQL Model
|
| 27 |
+
model_name = "microsoft/tapex-large-finetuned-wtq"
|
| 28 |
+
sql_tokenizer = TapexTokenizer.from_pretrained(model_name)
|
| 29 |
+
sql_model = BartForConditionalGeneration.from_pretrained(model_name)
|
| 30 |
+
|
| 31 |
+
data = {
|
| 32 |
+
"year": [1896, 1900, 1904, 2004, 2008, 2012],
|
| 33 |
+
"city": ["athens", "paris", "st. louis", "athens", "beijing", "london"]
|
| 34 |
+
}
|
| 35 |
+
table = pd.DataFrame.from_dict(data)
|
| 36 |
|
| 37 |
def predict(input, history=[]):
|
| 38 |
+
|
| 39 |
+
# Check if the user input is a question
|
| 40 |
+
is_question = "?" in user_message
|
| 41 |
+
|
| 42 |
# tokenize the new input sentence
|
| 43 |
new_user_input_ids = tokenizer.encode(input + tokenizer.eos_token, return_tensors='pt')
|
| 44 |
|
|
|
|
| 62 |
css=".footer {display:none !important}",
|
| 63 |
inputs=["text", "state"],
|
| 64 |
outputs=["chatbot", "state"],
|
| 65 |
+
title="ST Chatbot",
|
| 66 |
+
description="Type your message in the box above, and the chatbot will respond.",
|
| 67 |
)
|
| 68 |
|
| 69 |
if __name__ == '__main__':
|