Views
No views yet
1from transformers import T5Tokenizer, T5ForConditionalGeneration, pipeline
2
3table_columns = "Transaction_ID, Platform, Product_ID, User_ID, Transaction_Amount, Region, Transaction_Time, Transaction_Unit, User_Comments"
4
5table_name = "my_data"
6
7PROMPT_INPUT = f"""
8Given a SQL table named '{table_name}' with the following columns:
9{table_columns}
10
11Construct a SQL query to answer the following question:
12Q: {{question}}.
13"""
14
15model_id = "kevinng77/chat-table-flan-t5"
16tokenizer = T5Tokenizer.from_pretrained(model_id)
17model = T5ForConditionalGeneration.from_pretrained(model_id)
18
19input_text = PROMPT_INPUT.format_map({"question": "How many rows are there in the table?"})
20
21pipe = pipeline(
22 "text2text-generation",
23 model=model, tokenizer=tokenizer, max_length=512
24)