ParlAI
ParlAI copied to clipboard
Interactive mode with flask
Hi, I modified the scripts/interactive.py to make the demo using the flask. But, create_agent() not gonna call the existing model on the flask whenever I ran. It occurred 500 error on flask cuz the above issue. Here is the code pointed me:
Create model and assign it to the specified task
agent = create_agent(opt, requireModelExists=True)
human_agent = LocalHumanAgent(opt)
world = create_task(opt, [human_agent, agent])
I assumed create_agent() is third-party calling on the flask code. But I am not sure... I have no idea why...
Can you share the full stacktrace?
Here is the full stacktrace:
and when I traced the error part, it definitely not callable the create_agent().
agent = create_agent(opt, requireModelExists=True)
human_agent = LocalHumanAgent(opt)
world = create_task(opt, [human_agent, agent])
********************************************************************************
WARNING: This dialogue model is a research project that was trained on a
large amount of open-domain Twitter data. It may generate offensive content.
********************************************************************************
* Serving Flask app "interactiveDemo" (lazy loading)
* Environment: production
WARNING: Do not use the development server in a production environment.
Use a production WSGI server instead.
* Debug mode: on
2020-02-24 18:12:01,103 - werkzeug - INFO - * Running on http://0.0.0.0:5002/ (Press CTRL+C to quit)
!! hey
interact check 1 !!!!!!!
args check hey
[ warning: overriding opt['model_file'] to /home/ubuntu/ParlAI/data/models/controllable_dialogue/control_avgnidf10b10e (previously: /private/home/abisee/models/control_avgnidf10b10e_run0 )]
[ warning: overriding opt['weighted_decoding'] to extrep_2gram:-3.5,extrep_nonstopword:-1e20,intrep_nonstopword:-1e20 (previously: None )]
[ warning: overriding opt['set_controls'] to avg_nidf:7 (previously: )]
Loading up controllable features...
Loading word count stats from /home/ubuntu/ParlAI/data/controllable_dialogue/word2count.pkl...
num_sents: 5328706
Done loading word2nidf dictionary.
Loading Arora embedding info from /home/ubuntu/ParlAI/data/controllable_dialogue/arora.pkl...
Done loading arora info.
2020-02-24 18:12:51,627 - torchtext.vocab - INFO - Loading vectors from /home/ubuntu/ParlAI/data/models/glove_vectors/glove.840B.300d.txt.pt
[ Using CUDA ]
Dictionary: loading dictionary from /home/ubuntu/ParlAI/data/models/controllable_dialogue/control_avgnidf10b10e.dict
[ num words = 35213 ]
[ControllableSeq2seq: full interactive mode on.]
2020-02-24 18:12:54,642 - werkzeug - INFO - 35.195.199.75 - - [24/Feb/2020 18:12:54] "POST / HTTP/1.1" 500 -
Traceback (most recent call last):
File "/home/ubuntu/anaconda3/envs/pytorch_p36/lib/python3.6/site-packages/flask/app.py", line 2309, in __call__
return self.wsgi_app(environ, start_response)
File "/home/ubuntu/anaconda3/envs/pytorch_p36/lib/python3.6/site-packages/flask/app.py", line 2295, in wsgi_app
response = self.handle_exception(e)
File "/home/ubuntu/anaconda3/envs/pytorch_p36/lib/python3.6/site-packages/flask_restful/__init__.py", line 269, in error_router
return original_handler(e)
File "/home/ubuntu/anaconda3/envs/pytorch_p36/lib/python3.6/site-packages/flask/app.py", line 1741, in handle_exception
reraise(exc_type, exc_value, tb)
File "/home/ubuntu/anaconda3/envs/pytorch_p36/lib/python3.6/site-packages/flask/_compat.py", line 34, in reraise
raise value.with_traceback(tb)
File "/home/ubuntu/anaconda3/envs/pytorch_p36/lib/python3.6/site-packages/flask/app.py", line 2292, in wsgi_app
response = self.full_dispatch_request()
File "/home/ubuntu/anaconda3/envs/pytorch_p36/lib/python3.6/site-packages/flask/app.py", line 1815, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/home/ubuntu/anaconda3/envs/pytorch_p36/lib/python3.6/site-packages/flask_restful/__init__.py", line 269, in error_router
return original_handler(e)
File "/home/ubuntu/anaconda3/envs/pytorch_p36/lib/python3.6/site-packages/flask/app.py", line 1718, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/home/ubuntu/anaconda3/envs/pytorch_p36/lib/python3.6/site-packages/flask/_compat.py", line 34, in reraise
raise value.with_traceback(tb)
File "/home/ubuntu/anaconda3/envs/pytorch_p36/lib/python3.6/site-packages/flask/app.py", line 1813, in full_dispatch_request
rv = self.dispatch_request()
File "/home/ubuntu/anaconda3/envs/pytorch_p36/lib/python3.6/site-packages/flask/app.py", line 1799, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/home/ubuntu/anaconda3/envs/pytorch_p36/lib/python3.6/site-packages/flask_restful/__init__.py", line 458, in wrapper
resp = resource(*args, **kwargs)
File "/home/ubuntu/anaconda3/envs/pytorch_p36/lib/python3.6/site-packages/flask/views.py", line 88, in view
return self.dispatch_request(*args, **kwargs)
File "/home/ubuntu/anaconda3/envs/pytorch_p36/lib/python3.6/site-packages/flask_restful/__init__.py", line 573, in dispatch_request
resp = meth(*args, **kwargs)
File "/tmp/pycharm_project_890/projects/controllable_dialogue/interactiveDemo.py", line 106, in post
output = self.NLG(args_api['input'])
File "/tmp/pycharm_project_890/projects/controllable_dialogue/interactiveDemo.py", line 100, in NLG
return(output)
UnboundLocalError: local variable 'output' referenced before assignment
That looks like you have a bad variable name. If you want to submit a PR though, I'm happy to review.
This issue has not had activity in 30 days. Marking as stale.
@sseol11 I'd still very much welcome this PR if you have it anywhere.
Interesting. Were you hoping for a front end interface demo @stephenroller? I could put together a simple demo within ParlAI that uses Flask, socketio, and Bot.ui to talk with a model instead of through the terminal if this would be a valuable contribution? Thanks
A minimal flask demo would be quite nice. We get it requested with some frequency. I think its best if we could have a pedagogical example.
We do have the chat services, which include a full little web app demo, but many people find it too difficult to start with.
i am trying this code demo for flask
https://github.com/khushaljethava/parlai_flask
it's returned that from my model
Not Found The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again.
you may want to open an issue there
we have a flask implementation now, so closing this