Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
sahil-rajput authored Dec 1, 2018
1 parent b7ff540 commit 38f95a5
Show file tree
Hide file tree
Showing 2 changed files with 166 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from flask import Flask, render_template, request
from chatterbot import ChatBot
from chatterbot.trainers import ChatterBotCorpusTrainer
from chatterbot.trainers import ListTrainer

app = Flask(__name__)

bot = ChatBot("Candice")
bot.set_trainer(ListTrainer)
bot.train(['What is your name?', 'My name is Candice'])
bot.train(['Who are you?', 'I am a bot' ])
bot.train(['Do created you?', 'Tony Stark', 'Sahil Rajput', 'You?'])
bot.set_trainer(ChatterBotCorpusTrainer)
bot.train("chatterbot.corpus.english")

@app.route("/")
def home():
return render_template("home.html")

@app.route("/get")
def get_bot_response():
userText = request.args.get('msg')
return str(bot.get_response(userText))

if __name__ == "__main__":
app.run()
140 changes: 140 additions & 0 deletions src/templates/home.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
<!DOCTYPE html>
<html>
<title>Candice</title>
<head>
<link rel='shortcut icon' type='image/x-icon' href='https://user-images.githubusercontent.com/20112458/49326597-773b7280-f57a-11e8-853d-20ed61d18b0d.png' />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<style>
body
{
font-family: monospace;
}
h1
{
background-color:yellow;
display:inline-block;
font-size:3em;
margin:0;
padding:14px;
}
h3
{
color: black;
font-size: 20px;
margin-top: 3px;
text-align: center;
}
#chatbox
{
margin-left: auto;
margin-right: auto;
width: 40%;
margin-top: 60px;
}
#userInput
{
margin-left: auto;
margin-right: auto;
width: 40%;
margin-top: 60px;
}
#textInput
{
width: 90%;
border: none;
border-bottom: 3px solid black;
font-family: monospace;
font-size: 17px;
}
.userText
{
color: white;
font-family: monospace;
font-size: 17px;
text-align: right;
line-height: 30px;
}
.userText span
{
background-color: #808080;
padding: 10px;
border-radius: 2px;
}
.botText
{
color: white;
font-family: monospace;
font-size: 17px;
text-align: left;
line-height: 30px;
}
.botText span
{
background-color: #4169e1;
padding: 10px;
border-radius: 2px;
}
#tidbit
{
position:absolute;
bottom:0;
right:0;
width: 300px;
}
.boxed
{
margin-left: auto;
margin-right: auto;
width: 78%;
margin-top: 60px;
border: 1px solid green ;
}
.box
{
border: 2px solid black;
}
</style>
</head>
<body>
<img >
<center><h1><img src="https://user-images.githubusercontent.com/20112458/49326597-773b7280-f57a-11e8-853d-20ed61d18b0d.png" alt="CANDICE" style="width:40px;height:40px;">Your Personal ChatBot</h1></center>
<h3>
<p>Like this? ❤️ Tweet me 👉 <a href="https://twitter.com/_sahilrajput">@_sahilrajput</a>. Find this project on <a href="https://www.github.com/sahil-rajput/Candice">GitHub</a>.</p>
</h3>
<div class="box"></div>
<div class="boxed">
<div>
<div id="chatbox">
<img src="https://user-images.githubusercontent.com/20112458/49326597-773b7280-f57a-11e8-853d-20ed61d18b0d.png" alt="CANDICE" style="width:40px;height:40px;">
<p class="botText"><span>Hi! I'm Candice your personal ChatBot ❤️</span></p>
</div>
<div id="userInput">
<input id="textInput" type="text" name="msg" placeholder="Message">
</div>
</div>
<script>
function getBotResponse()
{
var rawText = $("#textInput").val();
var userHtml = '<p class="userText"><span>' + rawText + '</span></p>';
$("#textInput").val("");
$("#chatbox").append(userHtml);
document.getElementById('userInput').scrollIntoView({block: 'start', behavior: 'smooth'});
$.get("/get", { msg: rawText }).done(function(data)
{
var botHtml = '<p class="botText"><span>' + data + '</span></p>';
$("#chatbox").append(botHtml);
document.getElementById('userInput').scrollIntoView({block: 'start', behavior: 'smooth'});
});
}
$("#textInput").keypress(function(e)
{
if(e.which == 13)
{
getBotResponse();
}
});
</script>
</div>
</body>
</html>

0 comments on commit 38f95a5

Please sign in to comment.