Skip to content

Commit

Permalink
Merge branch 'gssoc-master' into gssoc-master
Browse files Browse the repository at this point in the history
  • Loading branch information
Pihu1998 authored Apr 8, 2020
2 parents 1d0082d + 29654b1 commit 36524da
Show file tree
Hide file tree
Showing 29 changed files with 1,334 additions and 430 deletions.
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
__pycache__
.dockerignore
stanford-corenlp-full-2018-10-05/
24 changes: 24 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
name: Bug report
about: Create a report to help us improve
title: ''
labels: 'bug'
assignees: ''

---

**Describe the bug**
A clear and concise description of what the bug is.

**To Reproduce**
Steps to reproduce the behavior:
1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
4. See error

**Expected behavior**
A clear and concise description of what you expected to happen.

**Additional context**
Add any other context about the problem here.
20 changes: 20 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
name: Feature request
about: Suggest an idea for this project
title: ''
labels: 'enhancement'
assignees: ''

---

**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

**Describe the solution you'd like**
A clear and concise description of what you want to happen.

**Describe alternatives you've considered**
A clear and concise description of any alternative solutions or features you've considered.

**Additional context**
Add any other context or screenshots about the feature request here.
30 changes: 30 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<!-- The title of the PR should be of this format: <Title_of_Issue>_resolved -->
Fixes # <!-- Add the issue number that is fixed by this PR -->

<!-- Describe the PR as follows -->
## Description:

- Files changed:
- Dependencies if any: <!-- List the dependencies on other issues/PRs -->
- Basic tests done to validate:
- Conflicts if any: <!-- Describe the reason for conflict -->

<!-- Use '[x]' to indicate checked box in the list below -->
## Checklist:

- [ ] All coding conventions are followed
- [ ] Style guidelines for this project have been followed
- [ ] 4 space indentation is used
- [ ] Relevant comments are added
- [ ] The code has been tested
- [ ] No new warnings are generated

<!-- Add screenshots of locally tested code -->
## Screenshots:


<!-- Provide any other information that is relevant to this pull request -->
## Other Information:


@ <!-- Tag mentor/project admin to review and merge -->
126 changes: 125 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,127 @@
stanford-corenlp-full-2018-10-05/
__pycache__
config.py
# Editors
.vscode/
.idea/

# Vagrant
.vagrant/

# Mac/OSX
.DS_Store

# Windows
Thumbs.db

# Source for the following rules: https://raw.githubusercontent.com/github/gitignore/master/Python.gitignore
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
.python-version

# celery beat schedule file
celerybeat-schedule

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json
12 changes: 12 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
language: python
python:
- "3.6"
cache: pip
install:
- pip install -r requirements.txt
before_script:
- black --check . || true
script:
- flake8 . --count --select=E101,E722,E9,F4,F63,F7,F82,W191 --show-source --statistics
- flake8 . --count --exit-zero --max-line-length=127 --statistics
- pytest
11 changes: 7 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
FROM python:3.6
FROM python:3.6-slim-stretch

RUN apt-get update && apt-get install -y git wget unzip

COPY requirements.txt ./requirements.txt
RUN pip install -r requirements.txt

COPY . /usr/var/
WORKDIR /usr/var/
COPY docker-entrypoint.sh /usr/local/bin/
RUN chmod +x /usr/local/bin/docker-entrypoint.sh

CMD ["python", "./init.py"]
WORKDIR /usr/var/MapBot
ENTRYPOINT ["/bin/sh","/usr/local/bin/docker-entrypoint.sh"]
10 changes: 10 additions & 0 deletions ENV/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
DB_USER=root
DB_PASSWORD=<YOUR_MYSQL_ROOT_USER_PASSWORD_HERE>
DB_HOST=localhost
DATABASE=mapbot
DB_PORT=3306
GCLOUD_API_KEY=<YOUR_API_KEY_HERE>
JAVAHOME=<YOUR_JAVAHOME_PATH_HERE>
STANFORD_PATH_TO_JAR=<YOUR_STANFORD_PATH_TO_JAR_HERE>
STANFORD_PATH_TO_MODELS_JAR=<YOUR_STANFORD_PATH_TO_MODELS_JAR_HERE>
TELEGRAM_BOT_TOKEN=<YOUR_API_KEY_HERE>
8 changes: 8 additions & 0 deletions ENV/docker.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
DB_USER=root
DB_PASSWORD=root
DB_HOST=db
DATABASE=mapbot
DB_PORT=3306
JAVAHOME=/usr/local/openjdk-11/bin/java
STANFORD_PATH_TO_JAR=./stanford-corenlp-full-2018-10-05/stanford-corenlp-3.9.2.jar
STANFORD_PATH_TO_MODELS_JAR=./stanford-corenlp-full-2018-10-05/stanford-corenlp-3.9.2-models.jar
70 changes: 45 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# MapBot
<p align="center">
<img src="https://forthebadge.com/images/badges/made-with-python.svg">
</p>

# MapBot [![Build Status](https://travis-ci.com/vishakha-lall/MapBot.svg?branch=gssoc-master)](https://travis-ci.com/vishakha-lall/MapBot)

#### Hey! I'm your friendly navigator bot! Try me out, not to brag but I'm FUN!

Expand Down Expand Up @@ -48,18 +52,9 @@ Check out all related information [here](GSSoC.md)
- Enter root password when prompted
- `create database mapbot;`
- Verify creation of the database `show databases;`
- Unzip the StanfordCoreNLP package in the repository and keep the file names `stanford-corenlp-x.x.x.jar` and `stanford-corenlp-x.x.x-models.jar` handy.
- Add config.py file to .gitignore to avoid pushing changes made to config
- Run `git rm --cached config.py`
- Edit the `config.py` file with the corresponding values
- user = "root"
- password = <your_root_password>
- host = "localhost"
- database = "mapbot"
- key = <your_Google_Cloud_API_key>
- stanford_path_to_jar = <your_path_to_stanford-corenlp-x.x.x.jar>
- stanford_path_to_models_jar = <your_path_to_stanford-corenlp-x.x.x-models.jar>
- javahome = <your_path_to_jdk_bin_java.exe>
- Unzip the StanfordCoreNLP package in the repository and keep the file paths `stanford-corenlp-x.x.x.jar` and `stanford-corenlp-x.x.x-models.jar` handy.
- Run `git update-index --assume-unchanged ENV/.env`
- Fill the existing template in `ENV/.env` with the corresponding values following the `KEY=VALUE` format
- Install dependencies from `requirements.txt` file. Run `pip install -r requirements.txt`
- You're all set up, run the `init.py` file. `python init.py`
- It is recommended that you set this project up in a virtual environment to keep the dependencies separated and for easier debugging. Here's how you can do that -
Expand All @@ -70,28 +65,53 @@ Check out all related information [here](GSSoC.md)

#### What are some pre-requisites? (with Docker)

- StanfordCoreNLP
- StanfordCoreNLP has a dependency on Java 8. `java -version` should complete successfully with version 1.8 or higher.
- Windows- Download as a .zip file from [here](https://stanfordnlp.github.io/CoreNLP/download.html).
- Linux and MacOS- Follow the instructions to download the file from [here](https://stanfordnlp.github.io/CoreNLP/download.html).
- Docker
- Take a look at [this](https://docs.docker.com/install/) for detailed installation instructions for Docker on Windows, Linux and Mac systems.
- Verify the installations by `docker --version` and `docker-compose --version`
- You won't need to download MySQL locally to make Docker work, but it's recommended as a pre-requisite to be able to debug programs outside Docker.

#### How to set me up Docker style?
- Clone the repository
- Unzip the StanfordCoreNLP package in the repository. Make sure the StanfordCoreNLP folder you downloaded in the prerequisite steps are in the cloned repository folder.
- Add config.py file to .gitignore to avoid pushing changes made to config
- Run `git rm --cached config.py`
- Modify *only* the following fields in `config.py` file with the corresponding values:
- key = <your_Google_Cloud_API_key>
- Download the `start.sh` and modify it appropriately:
- `git clone <GITHUB_LINK_OF_REPO_TO_CLONE> -b <BRANCH_NAME_TO_CHECKOUT>`
- `export GCLOUD_API_KEY=<YOUR_API_KEY_HERE>`
- You're all set up, kick off with `start.sh` file by running `bash start.sh`.

------

#### What are some pre-requisites? (with Telegram Bot)

- MySQL
- Install the community version of mySQL from the [official mySQL documentation page](https://dev.mysql.com/doc/mysql-installation-excerpt/5.7/en/).
- Create root user credentials during installation.
- Verify the installation, running the command `mysql -uroot -p -hlocalhost` should open the mySQL monitor. (Enter the root password when prompted)
- StanfordCoreNLP
- StanfordCoreNLP has a dependency on Java 8. `java -version` should complete successfully with version 1.8 or higher.
- Windows- Download as a .zip file from [here](https://stanfordnlp.github.io/CoreNLP/download.html).
- Linux and MacOS- Follow the instructions to download the file from [here](https://stanfordnlp.github.io/CoreNLP/download.html).
- Telegram
- Download the [Telegram](https://telegram.org/apps) for your chosen platform.

#### How to set me up on Telegram?

- Clone the repository
- Create the **mapbot** database in mySQL
- `mysql -uroot -p -hlocalhost`
- Enter root password when prompted
- `create database mapbot;`
- Verify creation of the database `show databases;`
- Unzip the StanfordCoreNLP package in the repository and keep the file paths `stanford-corenlp-x.x.x.jar` and `stanford-corenlp-x.x.x-models.jar` handy.
- Run `git update-index --assume-unchanged ENV/.env`
- Fill the existing template in `ENV/.env` with the corresponding values following the `KEY=VALUE` format
- For `TELEGRAM_BOT_TOKEN=<YOUR_API_KEY_HERE>`, open your Telegram app and follow [this](https://core.telegram.org/bots#creating-a-new-bot) tutorial on how to create a new bot on Telegram and get your own bot token. Once your token is generated, update the `.env` file in `/ENV` with it.
- Find your bot on Telegram using `@bot_username` that you chose, and send the first text to your new bot. Nothing is supposed to happen for now. No worries.
- Install dependencies from `requirements.txt` file. Run `pip install -r requirements.txt`
- You're all set up, run the `telegram.py` file. `python telegram.py` and converse with your bot in real time.
- It is recommended that you set this project up in a virtual environment to keep the dependencies separated and for easier debugging. Here's how you can do that -
1. [Python](https://realpython.com/python-virtual-environments-a-primer/#why-the-need-for-virtual-environments)
2. [Conda](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html)
------
#### How do I work?

The analysis folder contains data files for the project. The sentences.csv contains the base training dataset which is used to classify the user's input into three classes - Statement, Question, and Chat. Going through some examples would clarify the difference between statement and chat. The featuresDump.csv is the result of text pre-processing done using the code in features.py and featuresDump.py.
The `/analysis` folder contains data files for the project. The `sentences.csv` contains the base training dataset which is used to classify the user's input into three classes - *Statement*, *Question*, and *Chat*. Going through some examples would clarify the difference between statement and chat. The `featuresDump.csv` is the result of text pre-processing done using the code in `features.py` and `featuresDump.py`.

------
#### Want to see me in action?
Expand Down
19 changes: 19 additions & 0 deletions app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from flask import Flask, jsonify
from chatbot import message_to_bot, setup

app = Flask(__name__)


@app.route("/chatbot/<user_input>", methods=["GET"])
def chat(user_input):
try:
response = message_to_bot(user_input, clf, learn_response)
except Exception:
return jsonify({"message": ("Unable to get response", learn_response)}, 500)

return jsonify({"message": response}, 200)


if __name__ == "__main__":
clf, learn_response = setup()
app.run(debug=False)
Loading

0 comments on commit 36524da

Please sign in to comment.