This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def get_acc_at_k(df: pd.DataFrame, rank_col: str, target_col: str, k: int) -> float: | |
| ''' | |
| rank_col: column of rank | |
| target_col: column of target metric (click, conversion, ctr, or cr) | |
| ''' | |
| # filter only positive target (when a subject is clicked or purchased) | |
| df = df[df[target_col]>0] | |
| return ((df[rank_col]<=k).astype(int).values * df[target_col].values).sum()\ | |
| / df[target_col].values.sum() * 100 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from flask import Flask, request, jsonify | |
| from flask_restful import Api, Resource, reqparse | |
| import pandas as pd | |
| import numpy as np | |
| import tensorflow_hub as hub | |
| import tensorflow_text | |
| import boto3 | |
| import json | |
| import os |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "intents": [ | |
| { | |
| "id": 1, | |
| "value": "product_query", | |
| "responses": [ | |
| { | |
| "id": 6, | |
| "value": "มีสินค้าครับ", | |
| "intent_id": 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from flask import request, abort | |
| from flask_restful import Resource, reqparse | |
| import requests | |
| from models.response import ResponseModel | |
| from numpy.random import choice | |
| from linebot import ( | |
| LineBotApi, WebhookHandler | |
| ) | |
| from linebot.exceptions import ( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from flask_restful import Resource, reqparse | |
| import requests | |
| from models.response import ResponseModel | |
| from numpy.random import choice | |
| class Chat(Resource): | |
| parser = reqparse.RequestParser() | |
| parser.add_argument('value', | |
| type=str, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from flask_restful import Resource, reqparse | |
| from models.phrase import PhraseModel | |
| class Phrase(Resource): | |
| post_parser = reqparse.RequestParser() | |
| post_parser.add_argument('value', | |
| type=str, | |
| required=True, | |
| help="Example phrase of corresponded intent cannot be empty." | |
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from flask_restful import Resource | |
| from models.intent import IntentModel | |
| import boto3 | |
| import os | |
| import json | |
| BUCKET_NAME = os.environ.get('S3_BUCKET_NAME') | |
| class Intent(Resource): | |
| model = IntentModel |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from db import db | |
| class PhraseModel(db.Model): | |
| __tablename__ = 'phrases' | |
| id = db.Column(db.Integer, primary_key=True) | |
| value = db.Column(db.String(200)) | |
| intent_id = db.Column(db.Integer, db.ForeignKey('intents.id')) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from db import db | |
| class IntentModel(db.Model): | |
| __tablename__ = 'intents' | |
| id = db.Column(db.Integer, primary_key=True) | |
| value = db.Column(db.String(100)) | |
| responses = db.relationship('ResponseModel', lazy='dynamic') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from flask import Flask | |
| from flask_restful import Api | |
| from db import db | |
| from resources.intent import Intent, IntentList, PutToS3 | |
| from resources.response import Response | |
| from resources.phrase import Phrase | |
| from resources.chat import Chat | |
| from resources.chat_line import LineChat |
NewerOlder