Jelajahi Sumber

change on Model prediction report for new model

Mohidul Islam 4 tahun lalu
induk
melakukan
303304083e

+ 7 - 5
review/model_pred_report.py

@@ -4,6 +4,7 @@ import requests
 from difflib import SequenceMatcher
 from django.utils import timezone
 from django.conf import settings
+from nlu_job.nlu_utils import clean_text
 
 from .models import Review, CustomReply
 
@@ -14,17 +15,18 @@ replies = CustomReply.objects.all()
 
 
 def model_inference(text):
-    url = nlu_server_url + '/model/parse'
+    url = nlu_server_url + '/predict'
+    text = clean_text(text)
     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')
+    res_intents = res.get('response').get('intents')
     intents = []
-    for intent in intents_rankings:
-        if intent.get('confidence') > 0.3:
-            intents.append(intent['name'])
+    for k, v in res_intents:
+        if v <= 0.3:
+            intents.append(k)
     return intents
 
 

+ 1 - 1
review_automation/settings/config.py

@@ -1,6 +1,6 @@
 # Cron-Jobs of the project
 CRONJOBS = [
-    ('0 * * * *', 'review.background_job.background_task_6_hours_interval'),
+    ('0 * * * *', 'review.background_job.background_task_every_hour'),
     ('0 0 * * SUN', 'analytics.background_job.background_task_7_days_interval'),
     ('0 */12 * * *', 'facebook_app.background_job.schedule_task'),
     ('0 */12 * * *', 'yelp.background_job.scheduled_task')

+ 2 - 0
review_automation/settings/dev.py

@@ -25,6 +25,8 @@ DATABASES = {
 HOST_URI = "http://127.0.0.1:8000"
 NLU_SERVER_URI = 'http://localhost:1996'
 NER_SERVER_URI = 'http://localhost:2020'
+BROWSER_URI = 'http://localhost:2021'
+
 # selenium-firefox instance
 
 BROWSER = 'Bangladesh'

+ 2 - 1
review_automation/settings/prod.py

@@ -42,6 +42,7 @@ AUTH_PASSWORD_VALIDATORS = [
 HOST_URI = "http://10.0.0.36:5005"
 NLU_SERVER_URI = 'http://localhost:1996'
 NER_SERVER_URI = 'http://localhost:2020'
+BROWSER_URI = 'http://localhost:2021'
 
 # selenium-firefox instance
-BROWSER = get_firefox_browser()
+BROWSER = 'browser'

+ 1 - 1
yelp/analytics.py

@@ -17,7 +17,7 @@ def send_email_bad_reviews():
     locations = Location.objects.all()
     for location in locations:
         to = settings.ADMIN_MAINTAINER_EMAILS
-        date = timezone.now() - timezone.timedelta(hours=12)
+        date = timezone.now() - timezone.timedelta(days=1)
         reviews = YelpReview.objects.filter(
             location__location_id=location.location_id,
             date_posted__gte=date,

+ 1 - 0
yelp/scrapper.py

@@ -34,6 +34,7 @@ def scrape_reviews(location_url, max_date, n_pages):
 
         review_items = html_soup.findAll('li', class_='lemon--li__373c0__1r9wz margin-b3__373c0__q1DuY padding-b3__373c0__342DA border--bottom__373c0__3qNtD border-color--default__373c0__3-ifU')
 
+
         # A single review content
         if not review_items:
             return None

+ 4 - 0
yelp/store_reviews.py

@@ -1,7 +1,11 @@
+import requests
+from django.conf import settings
 from .scrapper import scrape_reviews
 from .utils import get_max_date, store_into_database
 from .models import YelpLocation
 
+BROWSER_URI = getattr(settings, 'BROWSER_URI')
+
 
 def store_yelp_reviews(location, n_pages):
     location_url = location.url