├── README.md ├── db.sqlite3 ├── main.py ├── static └── style.css └── templates └── index.html /README.md: -------------------------------------------------------------------------------- 1 | # ChatBot-FastAPI 2 | ChatBot using FastAPI for faster processing 3 | 4 | ## Description 5 | This project was created as a part of workshop "Creating ChatBot's in Python using ChatterBot and FastAPI". 6 | 7 | ## Language Used 8 | - Python 9 | 10 | ## Frameworks Used 11 | ``` 12 | 1. FastAPI for creating rest api 13 | 2. ChatterBot for creating chatbot 14 | ``` 15 | 16 | ## About Us 17 | We are a bunch of tech guys working on AI, Mobile and Web Development/Training. Like this repository, don't forget to give us a star. 18 | 19 | ## Queries 20 | In case you find out any issue, feel free to open ticket or inform us at trainings@societyofai.in. Visit us at [Society of AI](https://societyofai.in/) 21 | -------------------------------------------------------------------------------- /db.sqlite3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/societyofai/ChatBot-FastAPI/3d5dc425e02e7b304bd4bb39cf98646cb4c5979c/db.sqlite3 -------------------------------------------------------------------------------- /main.py: -------------------------------------------------------------------------------- 1 | from fastapi import FastAPI, Request 2 | from fastapi.responses import HTMLResponse 3 | from fastapi.templating import Jinja2Templates 4 | import uvicorn 5 | from chatterbot import ChatBot 6 | from chatterbot.trainers import ChatterBotCorpusTrainer 7 | 8 | app = FastAPI() 9 | 10 | templates = Jinja2Templates(directory="templates") 11 | 12 | english_bot = ChatBot("Chatterbot") 13 | trainer = ChatterBotCorpusTrainer(english_bot) 14 | trainer.train("chatterbot.corpus.english") 15 | 16 | @app.get("/", response_class=HTMLResponse) 17 | def home(request: Request): 18 | return templates.TemplateResponse("index.html", {"request": request}) 19 | 20 | @app.get("/getChatBotResponse") 21 | def get_bot_response(msg: str): 22 | return str(english_bot.get_response(msg)) 23 | 24 | if __name__ == "__main__": 25 | uvicorn.run("main:app") -------------------------------------------------------------------------------- /static/style.css: -------------------------------------------------------------------------------- 1 | body{ 2 | font-family: Garamond; 3 | background-color: white; 4 | } 5 | h1{ 6 | color: black; 7 | margin-bottom: 0; 8 | margin-top: 0; 9 | text-align: center; 10 | font-size: 40px; 11 | } 12 | h3{ 13 | color: black; 14 | font-size: 20px; 15 | margin-top: 3px; 16 | text-align: center; 17 | } 18 | #chatbox{ 19 | background-color: black; 20 | margin-left: auto; 21 | margin-right: auto; 22 | width: 40%; 23 | margin-top: 60px; 24 | } 25 | #userInput { 26 | margin-left: auto; 27 | margin-right: auto; 28 | width: 40%; 29 | } 30 | #textInput { 31 | width: 87%; 32 | border: none; 33 | border-bottom: 3px solid #009688; 34 | font-family: monospace; 35 | font-size: 17px; 36 | } 37 | #buttonInput { 38 | padding: 3px; 39 | font-family: monospace; 40 | font-size: 17px; 41 | } 42 | .userText { 43 | color: white; 44 | font-family: monospace; 45 | font-size: 17px; 46 | text-align: right; 47 | line-height: 30px; 48 | } 49 | .userText span { 50 | background-color: #009688; 51 | padding: 2px; 52 | border-radius: 2px; 53 | margin-right: 2px; 54 | } 55 | .botText { 56 | color: white; 57 | font-family: monospace; 58 | font-size: 17px; 59 | text-align: left; 60 | line-height: 30px; 61 | } 62 | .botText span { 63 | background-color: #EF5350; 64 | padding: 2px; 65 | border-radius: 2px; 66 | margin-left: 2px; 67 | } 68 | #tidbit { 69 | position:absolute; 70 | bottom:0; 71 | right:0; 72 | width: 300px; 73 | } -------------------------------------------------------------------------------- /templates/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |

FastAPI Chatterbot - 10 | 11 | SOAI 12 | 13 |

14 |
15 |
16 |

17 | Hi!. I'm a chatbot. 18 |

19 |
20 |
21 | 22 | 23 |
24 | 48 |
49 | 50 | --------------------------------------------------------------------------------