Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 3 additions & 0 deletions braggi-reactjs-frontend/backend/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ postMessage = (message, author) => {
data = {author : "Braggi", message : response.data.braggi_out}
io.emit('RECEIVE_MESSAGE', data);
})
.catch(function(err){
console.log(err);
})
}

io.on('connection', (socket) => {
Expand Down
Binary file not shown.
Binary file not shown.
7 changes: 6 additions & 1 deletion braggi-rest-api/braggi_rest_api/braggi_rest_api/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = ['192.168.56.1','192.168.1.94', '127.0.0.1']
ALLOWED_HOSTS = ['192.168.56.1','192.168.1.94', '127.0.0.1', 'null']

CORS_ORIGIN_WHITELIST = (
'192.168.56.1:3000',
'localhost:3000',
'localhost:5000',
'192.168.1.94:3000'
)

Expand All @@ -45,6 +46,8 @@

'corsheaders',
'rest_api',
'dashboard',
'djoser',
'rest_framework',
]

Expand Down Expand Up @@ -129,3 +132,5 @@
# https://docs.djangoproject.com/en/2.0/howto/static-files/

STATIC_URL = '/static/'

LOGIN_REDIRECT_URL = '/api-admin/'
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<<!DOCTYPE html>
<html>
<head>
<title>Login</title>
</head>
<body>
<h2>Login</h2>
<form method="post">
{% csrf_token %}
{{ form.as_p }}
<button type="submit">Login</button>
</form>
</body>
</html>
3 changes: 2 additions & 1 deletion braggi-rest-api/braggi_rest_api/braggi_rest_api/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@

urlpatterns = [
url(r'^', include('rest_api.urls')),
]
url(r'^api-admin/', include('dashboard.urls'))
]
Empty file.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
3 changes: 3 additions & 0 deletions braggi-rest-api/braggi_rest_api/dashboard/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.contrib import admin

# Register your models here.
5 changes: 5 additions & 0 deletions braggi-rest-api/braggi_rest_api/dashboard/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.apps import AppConfig


class DashboardConfig(AppConfig):
name = 'dashboard'
Empty file.
Binary file not shown.
3 changes: 3 additions & 0 deletions braggi-rest-api/braggi_rest_api/dashboard/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.db import models

# Create your models here.
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<!DOCTYPE html>
<html>

<head>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.3/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-table/1.10.1/bootstrap-table.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.3/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-table/1.10.1/bootstrap-table.min.js"></script>
<script>
$(document).ready(function () {
$.getJSON("http://127.0.0.1:8000/braggi/", function (data, status) {
console.log(data);
$('#table').bootstrapTable({
data: data
});
});
});
</script>
</head>

<body>
<div class="jumbotron m-2">
<h1 class="display-4">Braggi API Conversation List</h1>
<hr class="my-4" />
<div class="container">
<table id="table">
<thead>
<tr>
<th data-field="id">id</th>
<th data-field="username">username</th>
<th data-field="user_in">user_in</th>
<th data-field="braggi_out">braggi_out</th>
<th data-field="intent">intent</th>
<th data-field="invoked_event">invoked_event</th>
</tr>
</thead>
</table>
<hr/>
</div> <a class="btn btn-primary btn-lg" href="javascript:window.open('','_self').close();" role="button">Go Back</a>
</div>
</body>

</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
<html>
<head>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>

<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>

<meta name="viewport" content="width=device-width, initial-scale=1.0">

{% block head %}
<title>Braggi Admin Dashboard</title>
{% endblock %}


</head>

<body>
<ul class="nav nav-tabs" id="myTab" role="tablist">
<li class="nav-item">
<a class="nav-link active" id="home-tab" data-toggle="tab" href="#home" role="tab" aria-controls="home" aria-selected="true">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" id="tools-tab" data-toggle="tab" href="#tools" role="tab" aria-controls="tools" aria-selected="false">Tools</a>
</li>
<li class="nav-item">
<a class="nav-link" id="help-tab" data-toggle="tab" href="#help" role="tab" aria-controls="help" aria-selected="false">Help</a>
</li>
</ul>
<div class="tab-content" id="myTabContent">
<div class="tab-pane fade show active" id="home" role="tabpanel" aria-labelledby="home-tab">
<div class="jumbotron m-2">
<h1 class="display-4">Hello, there!</h1>
<p class="lead">This is Braggi's Admin Dashboard</p>
<hr class="my-4">
<p>Here, you can make carry out some simple tasks without restarting the server.</p>
<a class="btn btn-primary btn-lg" href="#help" role="button">Learn more</a>
</div>
</div>
<div class="tab-pane fade" id="tools" role="tabpanel" aria-labelledby="tools-tab">
<div class="card m-2">
<h5 class="card-header">Machine Learning Model Options</h5>
<div class="card-body">
<h5 class="card-title">Retrain Model</h5>
<p class="card-text">You can retrain the Model using this.</p>
<a target="_blank" href="retrain-model/" class="btn btn-primary">Retrain</a>
</div>
</div>
<div class="card m-2">
<h5 class="card-header">Chat Options</h5>
<div class="card-body">
<h5 class="card-title">View Conversations</h5>
<p class="card-text">Load and View all conversations carried out through Braggi's API</p>
<a target="_blank" href="see-chats/" class="btn btn-primary">View Chats</a>
<hr/>
<h5 class="card-title">Download Conversations</h5>
<p class="card-text">Download all conversations carried out through Braggi's API</p>
<a id="downloadbtn" href="#" class="btn btn-primary" >Download Chats</a>
<script>
var dataStore;
$("#downloadbtn").click(function () {
$.getJSON("http://127.0.0.1:8000/braggi/", function (data, status) {
console.log(data);

var csv = JSON2CSV(data);
var downloadLink = document.createElement("a");
var blob = new Blob(["\ufeff", csv]);
var url = URL.createObjectURL(blob);
downloadLink.href = url;
downloadLink.download = "data.csv";

document.body.appendChild(downloadLink);
downloadLink.click();
document.body.removeChild(downloadLink);
console.log(downloadLink);
});
});

function JSON2CSV(objArray) {
var array = typeof objArray != 'object' ? JSON.parse(objArray) : objArray;
var str = '';
var line = '';

if ($("#labels").is(':checked')) {
var head = array[0];
if ($("#quote").is(':checked')) {
for (var index in array[0]) {
var value = index + "";
line += '"' + value.replace(/"/g, '""') + '",';
}
} else {
for (var index in array[0]) {
line += index + ',';
}
}

line = line.slice(0, -1);
str += line + '\r\n';
}

for (var i = 0; i < array.length; i++) {
var line = '';

if ($("#quote").is(':checked')) {
for (var index in array[i]) {
var value = array[i][index] + "";
line += '"' + value.replace(/"/g, '""') + '",';
}
} else {
for (var index in array[i]) {
line += array[i][index] + ',';
}
}

line = line.slice(0, -1);
str += line + '\r\n';
}
return str;
}
</script>
</div>
</div>
</div>
<div class="tab-pane fade" id="help" role="tabpanel" aria-labelledby="help-tab">
<div class="jumbotron m-2">
<h1 class="display-4">Having difficulties ?</h1>
<p class="lead">This is Braggi's Wiki for Developers</p>
<hr class="my-4">
<p>Here, you can find all information about the various tasks you can perfom using Braggi's Admin Dashboard</p>
<a class="btn btn-primary btn-lg" href="#help" role="button">Get Started</a>
</div>
</div>
</div>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<html>

<body>
<h2>Login</h2>
<form method="post">
{% csrf_token %}
{{ form.as_p }}
<button type="submit">Login</button>
</form>
</body>

</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<html>
<head>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">

<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>

<meta name="viewport" content="width=device-width, initial-scale=1.0">

{% block head %}
<title>Operation Successful</title>
{% endblock %}
</head>
<body>
<div class="jumbotron m-2">
<h1 class="display-4">{{ Operation }} completed Successfuly</h1>
<hr class="my-4">
<p>Click to go back and continue.</p>
<a class="btn btn-primary btn-lg" href="javascript:window.open('','_self').close();" role="button">Go Back</a>
</div>
</body>
</html>

3 changes: 3 additions & 0 deletions braggi-rest-api/braggi_rest_api/dashboard/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.test import TestCase

# Create your tests here.
12 changes: 12 additions & 0 deletions braggi-rest-api/braggi_rest_api/dashboard/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from django.conf.urls import url
from django.contrib import admin
from django.contrib.auth.views import LoginView, LogoutView
from django.views.generic import TemplateView
from dashboard.views import DashboardHomeView, TrainView, ChatListView

urlpatterns = [
url( r'^login/$', LoginView.as_view(template_name="dashboard/login.html"), name="login"),
url(r'^retrain-model/$', TrainView.as_view(), name="retrain-model"),
url(r'^see-chats/$', ChatListView.as_view(), name="see-chats"),
url( r'^', DashboardHomeView.as_view(template_name="dashboard/home.html")),
]
28 changes: 28 additions & 0 deletions braggi-rest-api/braggi_rest_api/dashboard/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from django.shortcuts import render
from django.contrib.auth.mixins import LoginRequiredMixin
from django.views.generic import TemplateView
from rest_api.Braggi_Engine import Run
from django.template import Context, loader
from django.http import HttpResponse


class DashboardHomeView(LoginRequiredMixin, TemplateView):
login_url = '/api-admin/login/'
redirect_field_name = '/api-admin/login/'

class TrainView(TemplateView):
template_name="dashboard/success.html"
login_url = '/api-admin/login/'
redirect_field_name = '/api-admin/login/'

def get(self, request):
self.train()
return render(request, 'dashboard/success.html', {'Operation': 'Training'})

def train(self):
Run.Run_Model('admin-override-input=null', Trained=False)

class ChatListView(TemplateView):
template_name="dashboard/chat_logs.html"
login_url = '/api-admin/login/'
redirect_field_name = '/api-admin/login/'
Binary file modified braggi-rest-api/braggi_rest_api/db.sqlite3
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def model_load():
def model_save(model, words, intent_classes, train_x, train_y):
'''Save our trained model to a 'pickle'(.pkl) file.'''
model.save('./rest_api/Braggi_Engine/model.tflearn')
pickle.dump( {'words':words, 'classes':intent_classes, 'train_x':train_x, 'train_y':train_y}, open( "training_data", "wb" ) )
pickle.dump( {'words':words, 'classes':intent_classes, 'train_x':train_x, 'train_y':train_y}, open( "./rest_api/Braggi_Engine/training_data", "wb" ) )

def classify(model,sentence, words, intent_classes):
ERRORR_THRESHOLD = 0.25
Expand Down
6 changes: 4 additions & 2 deletions braggi-rest-api/braggi_rest_api/rest_api/Braggi_Engine/Run.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ def Run_Model(user_in, Trained=True):
model = Classifier.model(train_x, train_y)
model = Classifier.model_train(model, train_x, train_y)
Classifier.model_save(model, words, intent_classes, train_x, train_y)
response = Classifier.response(model, intents, words, intent_classes, user_in)
return response[0]

if user_in != 'admin-override-input=null':
response = Classifier.response(model, intents, words, intent_classes, user_in)
return response[0]

else:
intents = Text_Processing_Engine.intents_loader()
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
model_checkpoint_path: "E:\\Sushrit Teknologies\\Programming\\GitHub Repositories\\My Repositories\\Braggi-A-Python-Based-Contextual-Chatbot-Framework\\braggi-rest-api\\braggi_rest_api\\rest_api\\Braggi_Engine\\model.tflearn"
all_model_checkpoint_paths: "E:\\Sushrit Teknologies\\Programming\\GitHub Repositories\\My Repositories\\Braggi-A-Python-Based-Contextual-Chatbot-Framework\\braggi-rest-api\\braggi_rest_api\\rest_api\\Braggi_Engine\\model.tflearn"
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.