alejandrods / cover-letter-generator-gpt2 Goto Github PK
View Code? Open in Web Editor NEWService for generating cover letter using GPT-2 model, deployed on Google Cloud.
Home Page: https://cover-letter-generator-gpt2-app-6q7gvhilqq-lz.a.run.app
Service for generating cover letter using GPT-2 model, deployed on Google Cloud.
Home Page: https://cover-letter-generator-gpt2-app-6q7gvhilqq-lz.a.run.app
Do you know how I can run this on Google Colab?
`# -*- coding: utf-8 -*-
import os
import json
import flask
import logging
from textblob import TextBlob
from generate import generate
from flask_cors import CORS, cross_origin
from flask_ngrok import run_with_ngrok
from flask import Flask, render_template, url_for
from flask_wtf import FlaskForm
from wtforms import StringField, SubmitField, TextAreaField
from wtforms.validators import DataRequired
import torch
from transformers import GPT2LMHeadModel, GPT2Tokenizer
from flask import Flask, request, render_template
import json
app = flask.Flask(__name__)
CORS(app)
app.config['PROPAGATE_EXCEPTIONS'] = True
app = Flask(__name__, root_path='/content/cover-letter-generator-gpt2')
app.config['SECRET_KEY'] = '9bad6913d4358ac1395c5c94370ed090'
run_with_ngrok(app)
print(app.root_path)
# Logs
logging.basicConfig(level=logging.INFO,
format='%(asctime)s :: %(levelname)s :: %(message)s')
# Load Environment Variables
ROUTE_GENERATE = os.environ.get('ROUTE_GENERATE', 'generate')
N_TOKENS = int(os.environ.get('N_TOKENS', 20))
# This create a json file with the environment variables for javascript script
data_env = {
"APP_URL": "{}:{}".format(HOST, PORT) if 'localhost' in HOST
else "{}".format(HOST),
"ROUTE": "/{}".format(ROUTE_GENERATE),
}
# Save env.json file
with open(os.path.join("/content/cover-letter-generator-gpt2/src/static", "env.json"), 'w') as f:
json.dump(data_env, f)
@app.route('/content/cover-letter-generator-gpt2/src/templates/main.html')
@cross_origin()
def index():
"""
Function to render the html file
:return:
"""
return flask.render_template('main.html')
@app.route('/generate', methods=['POST'])
@cross_origin()
def prediction():
"""
Function to receive an user query and return generated text
:return: Generated text
"""
income_query = json.loads(flask.request.data)['input']
logging.info('Query received: {}'.format(income_query))
arg_lang = TextBlob(income_query)
lang = arg_lang.detect_language()
logging.info('Lang detected: {}'.format(lang))
if lang == 'en':
res = generate(income_query, size=N_TOKENS)
generated = res.split(income_query)[-1]
else:
res = "lang_det_err"
generated = "lang_det_err"
logging.info('Result: {}'.format(res))
return flask.jsonify({
'version': 'v1.0.0',
'body': {'query': income_query,
'generated': generated,
'result': res}
}), 200
@app.route('/health_liveness')
@cross_origin()
def health_check():
"""
Check status code
:return:
"""
return flask.jsonify({'status': 'success'}), 200
if __name__ == "__main__":
app.run()
`
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.