Skip to content
This repository has been archived by the owner on Nov 3, 2023. It is now read-only.

Flask Server #4433

Merged
merged 27 commits into from
Mar 21, 2022
Merged
Changes from 26 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
778e217
Flask Demo Added
khushaljethava Jan 25, 2022
1a6122d
Update README.md
khushaljethava Jan 25, 2022
e2dbf7d
Revert "Update README.md"
khushaljethava Jan 26, 2022
95ae29a
Revert "Flask Demo Added"
khushaljethava Jan 26, 2022
a81ff9c
one the necessary changes as per suggestions
khushaljethava Jan 26, 2022
4c7ac44
Update requirements.txt
khushaljethava Jan 26, 2022
29eff3b
Update index.md
khushaljethava Jan 26, 2022
1fab18b
Revert "Update index.md"
khushaljethava Feb 3, 2022
471f0eb
Revert "Update requirements.txt"
khushaljethava Feb 3, 2022
4693d25
Revert "one the necessary changes as per suggestions"
khushaljethava Feb 3, 2022
0c9b9fc
Deleted flask_demo.py
khushaljethava Feb 3, 2022
d363fae
Merge branch 'facebookresearch:main' into main
khushaljethava Feb 3, 2022
8426189
Flask_demo added
khushaljethava Feb 3, 2022
c987caf
Remove Model as global model
khushaljethava Feb 3, 2022
ec5aeed
update tutorial_flask
khushaljethava Feb 3, 2022
05d22d0
Merge branch 'facebookresearch:main' into main
khushaljethava Feb 6, 2022
7116158
Updated tutorial_flask.md
khushaljethava Feb 6, 2022
0fd475d
updated flask_demo.py
khushaljethava Feb 6, 2022
2fd90b9
Lint.
stephenroller Feb 6, 2022
4844dd0
Update parlai/scripts/flask_demo.py
stephenroller Feb 6, 2022
5e254d3
Update parlai/scripts/flask_demo.py
stephenroller Feb 6, 2022
1a93fa1
Few Changes to Improve script
khushaljethava Feb 23, 2022
9df2ff5
Wrap in a proper script.
stephenroller Mar 21, 2022
63ee0fe
Merge branch 'main' into khushaljethava/main
stephenroller Mar 21, 2022
b68067c
Merge branch 'main' into khushaljethava/main
stephenroller Mar 21, 2022
5cf1de2
Whoops
stephenroller Mar 21, 2022
75f2d44
Lint.
stephenroller Mar 21, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions parlai/scripts/flask_demo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/usr/bin/env python3

# Copyright (c) Facebook, Inc. and its affiliates.
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.

"""
Example Flask server which hosts a model.

## Examples
**Serving the model**
```shell
parlai flask -m repeat_query
parlai flask -mf zoo:blender/blender_90M/model
```

**Hitting the API***
```shell
curl -k http://localhost:5000/response -H "Content-Type: application/json" -d '{"text": "foobar"}'
```
"""

from parlai.core.agents import create_agent
from parlai.core.params import ParlaiParser
from parlai.core.script import ParlaiScript, register_script


@register_script('flask', hidden=True)
class Flask(ParlaiScript):
@classmethod
def setup_args(cls):
parser = ParlaiParser(True, True)
return parser

def chatbot_response(self):
from flask import request

data = request.json
self.agent.observe({'text': data["text"], 'episode_done': False})
response = self.agent.act()
return {'response': response['text']}

def run(self):
from flask import Flask, request

stephenroller marked this conversation as resolved.
Show resolved Hide resolved
self.agent = create_agent(self.opt)
app = Flask("parlai_flask")
app.route("/response", methods=("GET", "POST"))(self.chatbot_response)
app.run()


if __name__ == "__main__":
Flask.main()