Skip to content

Instantly share code, notes, and snippets.

@rish-16
Created May 24, 2019 05:12
Show Gist options
  • Select an option

  • Save rish-16/2d498ca60a848e6015bd13d36368d3b5 to your computer and use it in GitHub Desktop.

Select an option

Save rish-16/2d498ca60a848e6015bd13d36368d3b5 to your computer and use it in GitHub Desktop.
Our GPT-2 model server
#!/usr/bin/env python3
import os
from flask import Flask, request
from interactive_conditional_samples import interact_model
app = Flask(__name__)
@app.route('/', methods=['GET'])
def hello():
return "Hello from GPT-2 model server!"
"""
This is where the raw text is sent
The `interact_model` can be found under the `gpt-2/src` directory
in the `interactive_conditional_samples.py` code
"""
@app.route('/generate', methods=['POST'])
def generate():
text = request.data.decode('utf-8')
model_path = './models/'
final_text = interact_model(raw_text=text, models_dir=model_path)
return final_text
if __name__ == '__main__':
app.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment