Преглед на файлове

add two function to find actual intent and predicted intent

Mohidul Islam преди 5 години
родител
ревизия
7834e5f5dc
променени са 2 файла, в които са добавени 41 реда и са изтрити 2 реда
  1. 38 0
      review/model_pred_report.py
  2. 3 2
      review_automation/settings.py

+ 38 - 0
review/model_pred_report.py

@@ -0,0 +1,38 @@
+import json
+import requests
+import csv
+from difflib import SequenceMatcher
+from django.utils import timezone
+
+from .models import Review, CustomReply
+
+
+# constants
+nlu_server_url = 'http://localhost:5005'
+replies = CustomReply.objects.all()
+
+
+def model_inference(text):
+    url = nlu_server_url + '/model/parse'
+    payload = {'text': text}
+    headers = {'content-type': 'application/json'}
+    response = requests.post(url, data=json.dumps(payload), headers=headers)
+    if response.status_code == 200:
+        res = response.json()
+    intents_rankings = res.get('intent_ranking')
+    intents = []
+    for intent in intents_rankings:
+        if intent.get('confidence') > 0.2:
+            intents.append(intent['name'])
+
+    return intents
+
+
+def get_review_actual_intent(review):
+    actual_reply = review.reply.replied_text
+    for c_r in replies:
+        replied_text = c_r.reply
+        similarity = SequenceMatcher(None, actual_reply, replied_text).ratio()
+        if similarity > 0.7:
+            return c_r.reply_category
+    return None

+ 3 - 2
review_automation/settings.py

@@ -10,7 +10,7 @@ SECRET_KEY = '0t@j@klm8b@2rdl@po$$24pirh$&cg#p6f#)@$@n8^kn7k2%9b'
 # SECURITY WARNING: don't run with debug turned on in production!
 DEBUG = True
 
-ALLOWED_HOSTS = ['10.0.0.25', '127.0.0.1']
+ALLOWED_HOSTS = []
 
 
 # Application definition
@@ -71,7 +71,7 @@ DATABASES = {
     'default': {
         'ENGINE': 'django.db.backends.mysql',
         'NAME': 'review_automation',
-        'USER': 'root',
+        'USER': 'bytetrek',
         'PASSWORD': 'sad2002S1',
         'HOST': 'localhost',
         'PORT': '3306',
@@ -79,6 +79,7 @@ DATABASES = {
 }
 
 
+
 # Password validation
 
 AUTH_PASSWORD_VALIDATORS = [