BP2024/annotation_app/initial.py
2024-04-09 15:39:11 +02:00

27 lines
613 B
Python

from models import db, Samples
from app import app
import json
import os
if __name__ == '__main__':
with app.app_context():
# db.init_app(app)
# creating database
db.create_all()
try:
with open(os.path.join('dataset', 'final_id_v2.jsonl'), encoding='utf-8') as file:
data = [json.loads(line) for line in file]
for sample in data:
db.session.add(Samples(sample['text']))
db.session.commit()
print('Data sucessfully inserted')
except FileNotFoundError as err:
print(err)