File size: 1,461 Bytes
ec9ef8b
54210ca
 
f24bed6
d002017
d087072
d002017
 
436b052
 
d002017
54210ca
 
e030ac0
54210ca
 
 
 
 
e030ac0
54210ca
 
7c29a25
 
54210ca
 
 
 
e030ac0
 
abad0fd
 
e030ac0
 
 
 
 
4f6e66f
e030ac0
 
f24bed6
abad0fd
23432db
abad0fd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import gradio as gr
from transformers import TapexTokenizer, BartForConditionalGeneration
import pandas as pd

#wikisql take longer to process
#model_name = "microsoft/tapex-large-finetuned-wikisql"  # You can change this to any other model from the list above
#model_name = "microsoft/tapex-base-finetuned-wikisql"

model_name = "microsoft/tapex-large-finetuned-wtq"
#model_name = "microsoft/tapex-base-finetuned-wtq"

tokenizer = TapexTokenizer.from_pretrained(model_name)
model = BartForConditionalGeneration.from_pretrained(model_name)

data = {
    "year": [1896, 1900, 1904, 2004, 2008, 2012],
    "city": ["athens", "paris", "st. louis", "athens", "beijing", "london"]
}
table = pd.DataFrame.from_dict(data)

def chatbot_response(user_message):
    
    #inputs = tokenizer.encode("User: " + user_message, return_tensors="pt")
    inputs = user_message
    encoding = tokenizer(table=table, query=inputs, return_tensors="pt")
    outputs = model.generate(**encoding)
    response = tokenizer.batch_decode(outputs, skip_special_tokens=True)
    
    return response

# Define the chatbot interface using Gradio
iface = gr.Interface(
    fn=chatbot_response,
    inputs=gr.Textbox(prompt="You:"),
    outputs=gr.Textbox(),
    live=True,
    capture_session=True,
    title="ST SQL Chatbot",
    description="Type your message in the box above, and the chatbot will respond.",
)

# Launch the Gradio interface
if __name__ == "__main__":
    iface.launch()