AttainAI / attainai.py
CodesAndVibes's picture
Upload attainai.py
5316b1a
Raw History Blame Contribute Delete
1.15 kB
# -*- coding: utf-8 -*-
"""AttainAI.ipynb
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/drive/1MoiLy70a_YFQTyXsZ3GWNI5l3qNXd6lp
"""
pip
"""Importing libraries"""
from transformers import AutoModelForTableQuestionAnswering, AutoTokenizer, pipeline
import pandas as pd
data= pd.read_csv("/content/app_subscription.csv")
"""Download the data."""
data
data = data.astype(str)
# Load model & tokenizer
model = 'google/tapas-base-finetuned-wtq'
tapas_model = AutoModelForTableQuestionAnswering.from_pretrained(model)
tapas_tokenizer = AutoTokenizer.from_pretrained(model)
# Initializing pipeline
nlp = pipeline('table-question-answering', model=tapas_model, tokenizer=tapas_tokenizer)
def qa(query,data):
print('>>>>>')
print(query)
result = nlp({'table': data,'query':query})
answer = result['cells']
print(answer)
prediction = qa('What is the subscription type of id 1',data)
prediction = qa('What is the subscription status of id 1',data)
prediction = qa('What is the price of id 4',data)
prediction = qa('Which city has the highest speed score?',data)