Commit ·
5316b1a
1
Parent(s): 782e90b
Upload attainai.py
Browse files- attainai.py +46 -0
attainai.py
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# -*- coding: utf-8 -*-
|
| 2 |
+
"""AttainAI.ipynb
|
| 3 |
+
|
| 4 |
+
Automatically generated by Colaboratory.
|
| 5 |
+
|
| 6 |
+
Original file is located at
|
| 7 |
+
https://colab.research.google.com/drive/1MoiLy70a_YFQTyXsZ3GWNI5l3qNXd6lp
|
| 8 |
+
"""
|
| 9 |
+
pip
|
| 10 |
+
|
| 11 |
+
"""Importing libraries"""
|
| 12 |
+
|
| 13 |
+
from transformers import AutoModelForTableQuestionAnswering, AutoTokenizer, pipeline
|
| 14 |
+
import pandas as pd
|
| 15 |
+
|
| 16 |
+
data= pd.read_csv("/content/app_subscription.csv")
|
| 17 |
+
|
| 18 |
+
"""Download the data."""
|
| 19 |
+
|
| 20 |
+
data
|
| 21 |
+
|
| 22 |
+
data = data.astype(str)
|
| 23 |
+
|
| 24 |
+
# Load model & tokenizer
|
| 25 |
+
model = 'google/tapas-base-finetuned-wtq'
|
| 26 |
+
tapas_model = AutoModelForTableQuestionAnswering.from_pretrained(model)
|
| 27 |
+
tapas_tokenizer = AutoTokenizer.from_pretrained(model)
|
| 28 |
+
|
| 29 |
+
# Initializing pipeline
|
| 30 |
+
nlp = pipeline('table-question-answering', model=tapas_model, tokenizer=tapas_tokenizer)
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
def qa(query,data):
|
| 34 |
+
print('>>>>>')
|
| 35 |
+
print(query)
|
| 36 |
+
result = nlp({'table': data,'query':query})
|
| 37 |
+
answer = result['cells']
|
| 38 |
+
print(answer)
|
| 39 |
+
|
| 40 |
+
prediction = qa('What is the subscription type of id 1',data)
|
| 41 |
+
|
| 42 |
+
prediction = qa('What is the subscription status of id 1',data)
|
| 43 |
+
|
| 44 |
+
prediction = qa('What is the price of id 4',data)
|
| 45 |
+
|
| 46 |
+
prediction = qa('Which city has the highest speed score?',data)
|