Skip to content

Commit

Permalink
Added Large Word2Vec and updated project
Browse files Browse the repository at this point in the history
  • Loading branch information
jackshendrikov committed Apr 2, 2021
1 parent 65d33bb commit 4f35128
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 19 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -139,4 +139,7 @@ dmypy.json
.idea

# Media Dirs
media/
media/

# Large Word2Vect]
model/model-word2vec-300d.txt
2 changes: 1 addition & 1 deletion analyzer/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,6 @@ def prediction(self):
data = np.reshape(data, (1, 100, 300))

with graph.as_default():
model = load_model("model/LSTM-CNN-MODEL.h5") # load model
model = load_model("model/LSTM-CNN-Model.h5") # load model
print(model.predict(np.array(data)))
return model.predict(np.array(data))
32 changes: 23 additions & 9 deletions analyzer/templates/analyzer/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
</div>
</div>

<div class="app-content">
<div class="app-content" id="container">
<div class="app-sidebar">
<a href="" class="app-sidebar-link active">
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-home">
Expand Down Expand Up @@ -133,7 +133,6 @@
<div class="project-boxes jsGridView">
{% if documents %}
{% for document in documents %}
<!-- <li><a href="{{ document.docfile.url }}">{{ document.docfile.name }}</a></li>-->
<div class="project-box-wrapper">
<div class="project-box" style="background-color: #a0e989;">
<div class="project-box-header" style="margin: 0;">
Expand Down Expand Up @@ -185,25 +184,40 @@
function processData(link) {
jQuery.get(link, function(data) {
let Text = data;
console.log(Text)
console.log(Text);

let newDiv = document.createElement("div");
newDiv.className = "alert alert-success";
newDiv.role = "alert";
newDiv.innerHTML = "<button type=\"button\" class=\"close\" data-dismiss=\"alert\" aria-label=\"Close\"><span aria-hidden=\"true\">&times;</span></button>\n" +
"Wait a minute... Model analyze your text";

$("#container").before(newDiv);

$.ajax({
headers: { "X-CSRFToken": getCookie("csrftoken") },
type: "POST",
url: '/predict/',
data: {Text: Text},
success: function (data) {
console.log(data);
window.location.href = "{% url 'prediction' %}";

success: function() {
window.location = "{% url 'prediction' %}";
},

error: function (xhr, status) {
console.log(xhr);
window.location.href = "{% url 'prediction' %}";
error: function () {
let newDiv = document.createElement("div");
newDiv.className = "alert alert-danger";
newDiv.role = "alert";
newDiv.innerHTML = "<button type=\"button\" class=\"close\" data-dismiss=\"alert\" aria-label=\"Close\"><span aria-hidden=\"true\">&times;</span></button>\n" +
"An error occurred while trying to predict the result...";

$("#container").before(newDiv);
}
});
});
}
</script>
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.1/dist/umd/popper.min.js" integrity="sha384-9/reFTGAW83EW2RDu2S0VKaIzap3H66lZH81PoYlFhbGU+6BZp6G7niu735Sk7lN" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/js/bootstrap.min.js" integrity="sha384-+YQ4JLhjyBLPDQt//I+STsc9iw4uQqACwlvpslubQzn4u2UU2UFM80nGisd026JF" crossorigin="anonymous"></script>
</body>
</html>
2 changes: 2 additions & 0 deletions analyzer/urls.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from django.urls import path
from django.contrib.auth.decorators import login_required
from django.views.generic import TemplateView

from . import views
from .views import upload

Expand Down
16 changes: 11 additions & 5 deletions analyzer/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,20 @@ def upload(request):
return render(request, 'analyzer/upload.html', context)


VALID = []


def prediction(request):
text = request.POST.get('Text', False)
sent = Sentence(str(text))
predict = sent.prediction()

print(str(text))
if text != False:
sent = Sentence(str(text))
predict = sent.prediction()
VALID.append(predict)
else:
predict = VALID[-1]

print("Prediction is :", float(predict))
context = {'prediction': round(float(predict), 2) * 100, 'sent': sent}
context = {'prediction': round(float(predict), 2) * 100, 'sent': str(text)}

return render(request, 'analyzer/predict.html', context)
return render(request, 'analyzer/predict.html', context)
3 changes: 0 additions & 3 deletions model/model-word2vec-300d.txt

This file was deleted.

0 comments on commit 4f35128

Please sign in to comment.