Esempio n. 1
0
def post_view(request):
    user = check_validation(request)

    if user:
        if request.method == 'POST':
            form = PostForm(request.POST, request.FILES)
            if form.is_valid():
                image = form.cleaned_data.get('image')
                caption = form.cleaned_data.get('caption')
                post = PostModel(user=user, image=image, caption=caption)
                post.save()
                app = ClarifaiApp(api_key='45cd6978c866e241924d5fbbbdcc59145df93f70')
                path = str(BASE_DIR +'/'+ post.image.url)

                client = ImgurClient(Client_ID, Client_secret)
                post.image_url = client.upload_from_path(path, anon=True)['link']
                post.save()
                model = app.models.get("general-v1.3")
                response = model.predict_by_url(post.img_url)
                print response
                r = response['outputs'][0]['data']['concepts']
                for i in range(len(r)):
                    z = r[i]['name']
                    print z
                    temp = tags.objects.create(post=post, tag=z)
                    temp.save()
                return redirect('/feed/')
        else:
            form = PostForm()
            return render(request, 'post.html', {'form': form})
    else:
            return redirect('/login/')
Esempio n. 2
0
def PostView(request):
    user = CheckValidation(request)
    if user:
        if request.method == 'POST':
            form = PostForm(request.POST, request.FILES)
            if form.is_valid():
                image = form.cleaned_data.get('image')
                caption = form.cleaned_data.get('caption')

                # saving post in database

                post = PostModel(user=user, image=image, caption=caption)
                post.save()

                path = os.path.join(BASE_DIR, post.image.url)
                client = ImgurClient('32af2eae25eb458', 'a9c38afeb2cc39aadc9c408557ce3a98d87f2be0')
                post.image_url = client.upload_from_path(path, anon=True)['link']

                post.save()
                return redirect('/')

        else:
            form = PostForm()
        return render(request, 'post.html', {'form': form})
    else:

       return redirect('/login/')
Esempio n. 3
0
def post_view(request):
    user = check_validation(request)

    if user:
        if request.method == 'POST':
            form = PostForm(request.POST, request.FILES)
            if form.is_valid():
                image = form.cleaned_data.get('image')
                caption = form.cleaned_data.get('caption')
                post = PostModel(user=user, image=image, caption=caption)
                post.save()

                path = str(BASE_DIR + "//" + post.image.url)

                client = ImgurClient(
                    '3402b40cf104724',
                    '3c498635c7ea8cee8c9831927c8ebda6b9e69e18')
                post.image_url = client.upload_from_path(path,
                                                         anon=True)['link']
                post.save()

                return redirect('/feed/')
            else:
                return HttpResponse("From data is not valid.")

        else:
            form = PostForm()
        return render(request, 'post.html', {'form': form})
    else:
        return redirect('/login/')
Esempio n. 4
0
def post_view(request):
    user = check_validation(request)

    if user:
        if request.method == 'POST':
            form = PostForm(request.POST, request.FILES)
            if form.is_valid():
                image = form.cleaned_data.get('image')
                caption = form.cleaned_data.get('caption')
                post = PostModel(user=user, image=image, caption=caption)
                post.save()

                path = str(BASE_DIR + '/' + post.image.url)

                client = ImgurClient(
                    'e2dd69870de1f73',
                    '1b49cedd71bdbd818498a1c3434ed56bfb0ed676')
                post.image_url = client.upload_from_path(path,
                                                         anon=True)['link']
                post.save()

                return redirect('/feed/')

        else:
            form = PostForm()
        return render(request, 'post.html', {'form': form})
    else:
        return redirect('/login/')
Esempio n. 5
0
def post_view(request):
    user = check_validation(request)
    if user:
        if request.method == "GET":
            form = PostForm()
        elif request.method == "POST":
            form = PostForm(request.POST, request.FILES)
            if form.is_valid():
                image = form.cleaned_data.get("image")
                caption = form.cleaned_data.get("caption")
                post = PostModel(user=user, image=image, caption=caption)
                path = str(BASE_DIR + "\\user_images\\" + post.image.url)
                post.save()
                client = ImgurClient("58d5edc53832303", "d8a989c792b2e5a6cdd0fb0769a7326c4fe013a1")
                post.image_url = client.upload_from_path(path, anon=True)["link"]
                post.save()
                clarifai_data = []
                app = ClarifaiApp(api_key='a1b3910e08a4437b9fe85c5dbe967205')
                model = app.models.get("general-v1.3")
                result = model.predict_by_url(url=post.image_url)
                for x in range(0, len(result['outputs'][0]['data']['concepts'])):
                    model = result['outputs'][0]['data']['concepts'][x]['name']
                    clarifai_data.append(model)
                for z in range(0, len(clarifai_data)):
                    print clarifai_data[z]
                return redirect('/feed/')
        else:
            form = PostForm()
        return render(request, "post.html", {"form": form})

    else:
        return redirect("/login/")
Esempio n. 6
0
def post_view(
    request
):  # post view funtion is used to upload file or image that you want to add to the feed and also provide funtionality to add caption also
    user = check_validation(request)

    if user:
        if request.method == 'POST':
            form = PostForm(request.POST, request.FILES)
            if form.is_valid():
                image = form.cleaned_data.get('image')
                caption = form.cleaned_data.get('caption')
                post = PostModel(user=user, image=image, caption=caption)
                post.save()

                path = str(BASE_DIR + '\\' + post.image.url)

                client = ImgurClient(
                    '319feb40023adce',
                    '2a01664decd3b8b2439bfce7caae16d47b671837')
                post.image_url = client.upload_from_path(path,
                                                         anon=True)['link']
                post.save()

                add_category(post)
                ctypes.windll.user32.MessageBoxW(
                    0, u"post successsfully created", u"SUCCESS", 0)

                return redirect('/feed/')

        else:
            form = PostForm()
        return render(request, 'post.html', {'form': form})
    else:
        return redirect('/login/')
Esempio n. 7
0
def post_view(request):
    user = check_validation(request)

    if user:
        if request.method == 'POST':
            form = PostForm(request.POST, request.FILES)
            if form.is_valid():
                image = form.cleaned_data.get('image')
                caption = form.cleaned_data.get('caption')
                post = PostModel(image=image, caption=caption)
                post.save()

                path = str(BASE_DIR + post.image.url)

                client = ImgurClient(
                    '4cf5d8d98bef4a0',
                    '292b9342adb63a7aa1eb188c1a59068c2e51a2d5')
                post.image_url = client.upload_from_path(path,
                                                         anon=True)['link']
                post.save()

                return redirect('/feed/')

        else:
            form = PostForm()
        return render(request, 'PostForm.html', {'form': form})
    else:
        return redirect('/login/')
Esempio n. 8
0
def post_view(request):
    user = check_validation(request)

    if user:
        if request.method == 'POST':
            form = PostForm(request.POST, request.FILES)
            if form.is_valid():
                image = form.cleaned_data.get('image')
                caption = form.cleaned_data.get('caption')
                post = PostModel(user=user, image=image, caption=caption)
                post.save()

                path = str(BASE_DIR + post.image.url)

                client = ImgurClient(
                    'f7e1fe53d2e71e7',
                    '4f87a455291c79ff1caec48add2c3c4222116ef0')
                post.image_url = client.upload_from_path(path,
                                                         anon=True)['link']
                #saving to DB
                post.save()

                return redirect('/Feeds/')

        else:
            form = PostForm()
        return render(request, 'Post.html', {'form': form})
    else:
        return redirect('/Login/')
Esempio n. 9
0
def post_view(request):

    # checkinng if user is valid
    user = check_validation(request)

    if user:
        if request.method == 'POST':
            form = PostForm(request.POST, request.FILES)
            if form.is_valid():
                image = form.cleaned_data.get('image')
                caption = form.cleaned_data.get('caption')
                post = PostModel(user=user, image=image, caption=caption)
                post.save()

                path = str(BASE_DIR + "\\" + post.image.url)

                client = ImgurClient(
                    'b05a87fc2d9b16a',
                    'e40bae7fc06026074022bcac6b4f370fe4963cba')
                post.image_url = client.upload_from_path(path,
                                                         anon=True)['link']
                post.save()

                return redirect('/feed/')

        else:
            form = PostForm()
        return render(request, 'post.html', {'form': form})
    else:
        return redirect('/login/')
Esempio n. 10
0
def post_view(request):
    user = check_validation(request)
    if user:
        if request.method == 'GET':
            form = PostForm()
        elif request.method == 'POST':
            form = PostForm(request.POST, request.FILES)
            if form.is_valid():
                image = form.cleaned_data.get('image')
                caption = form.cleaned_data.get('caption')
                post = PostModel(user=user, image=image, caption=caption)
                path = str(BASE_DIR + "/user_images/" + post.image.url)
                post.save()
                client = ImgurClient(
                    "48b3c07ebcf5ecb",
                    "af316e94ac2544c61623ed0fe4a80f2ce928ce33")
                post.image_url = client.upload_from_path(path,
                                                         anon=True)['link']
                post.save()
                app = ClarifaiApp(api_key='dc676a84b0334de7a430b805c57332f4')

                model = app.models.get('food-items v1.0')

                response = model.product_by_url('url = post.image_url')

                print response

                return redirect('/feed/')
        return render(request, 'post.html', {'form': form})
    else:
        return redirect('/login/')
Esempio n. 11
0
def post_view(request):
    user = check_validation(request)

    if user:

        if request.method == 'POST':
            form = PostForm(request.POST, request.FILES)

            if form.is_valid():
                image = form.cleaned_data.get('image')
                caption = form.cleaned_data.get('caption')
                post = PostModel(user=user, image=image, caption=caption)
                post.save()
                ctypes.windll.user32.MessageBoxW(0,u"Post has been created.",u"congrulation", 0)

                path = str(BASE_DIR + post.image.url)

                client = ImgurClient(ci, cs)
                post.image_url = client.upload_from_path(path, anon=True)['link']
                post.save()
                return redirect('/feed/')
            else:
                ctypes.windll.user32.MessageBoxW(0, u"Invalid Post", u"Error", 0)
                form = PostForm()
            return render(request, 'post.html', {'form': form})

        else:
            return redirect('/login/')
Esempio n. 12
0
def post_view(request):
    user = check_validation(request)

    if user:
        if request.method == 'POST':
            form = PostForm(request.POST, request.FILES)
            if form.is_valid():
                image = form.cleaned_data.get('image')
                caption = form.cleaned_data.get('caption')
                post = PostModel(user=user, image=image, caption=caption)
                post.save()

                path = str(BASE_DIR + "\\" + post.image.url)

                client = ImgurClient(
                    '3885ef5f1212538',
                    'b607a83fb4e5d62d3e936075755e3a40eccc7326')
                post.image_url = client.upload_from_path(path,
                                                         anon=True)['link']
                post.save()

                return redirect('/feed/')

        else:
            form = PostForm()
        return render(request, 'post.html', {'form': form})
    else:
        return redirect('/login/')
Esempio n. 13
0
def post_view(request):
    user = check_validation(request)
    if user:
        if request.method == 'POST':
            form = PostForm(request.POST, request.FILES)
            if form.is_valid():
                image = form.cleaned_data.get('image')
                caption = form.cleaned_data.get('caption')
                post = PostModel(user=user, image=image, caption=caption)
                post.save()
                path = str(BASE_DIR +'/'+ post.image.url)
                client = ImgurClient(YOUR_CLIENT_ID, YOUR_CLIENT_SECRET)
                post.image_url = client.upload_from_path(path, anon=True)['link']
                post.save()
                concepts = model.predict_by_url(url=post.image_url)['outputs'][0]['data']['concepts']
                for concept in concepts[:5]:
                    tag = concept['name']
                    hash = HashTag.objects.filter(name  = tag)
                    if(hash.__len__() == 0):
                        hash = HashTag(name = tag)
                        hash.save()
                    else:
                        hash = hash[0]
                    Hash2Post(id_of_hashtag = hash, id_of_post = post).save()
                return redirect('/feed/')
        else:
            form = PostForm()
        return render(request, 'post.html', {'form': form})
    else:
        return redirect('/login/')
Esempio n. 14
0
def post_view(request):
    user = check_validation(request)

    if user:
        if request.method == 'POST':
            form = PostForm(request.POST, request.FILES)
            if form.is_valid():
                image = form.cleaned_data.get('image')
                caption = form.cleaned_data.get('caption')
                post = PostModel(user=user, image=image, caption=caption)
                post.save()

                path = str(BASE_DIR + post.image.url)

                client = ImgurClient(
                    '309da390c4f405d',
                    '0b1e627021ab1fee1c9ae9ed90eaf1565ee0e0f1')
                post.image_url = client.upload_from_path(path,
                                                         anon=True)['link']
                post.save()

                return redirect('/feed/')

        else:
            form = PostForm()
        return render(request, 'post.html', {'form': form})
    else:
        return redirect('/login/')
Esempio n. 15
0
def post_view(request):
    user = check_validation(request)

    if user:
        if request.method == 'POST':
            form = PostForm(request.POST, request.FILES)
            if form.is_valid():
                image = form.cleaned_data.get('image')
                caption = form.cleaned_data.get('caption')
                post = PostModel(user=user, image=image, caption=caption)
                post.save()

                path = str(BASE_DIR + '/' + post.image.url)

                client = ImgurClient(
                    '7a6b6f3c625804c',
                    'e8737b3a742e79b4ef2ee548d556b05893771eb0')
                post.image_url = client.upload_from_path(path,
                                                         anon=True)['link']
                post.save()

                return redirect('/feed/')

        else:
            form = PostForm()
        return render(request, 'post.html', {'form': form})
    else:
        return redirect('/login/')
Esempio n. 16
0
def post_view(request):
    user = check_validation(request)
    if user:
        # import pdb; pdb.set_trace()
        if request.method == 'POST':
            form = PostForm(request.POST, request.FILES)
            if form.is_valid():
                image = form.cleaned_data.get('image')
                caption = form.cleaned_data.get('caption')
                post = PostModel(user=user, image=image, caption=caption)
                post.save()
                path = str(BASE_DIR + '/' + post.image.url)
                client = ImgurClient(imgur_id, secret)
                post.image_url = client.upload_from_path(path,
                                                         anon=True)['link']
                # post.save()

                # classification of images

                app = ClarifaiApp(api_key=clarif_key)
                model = app.models.get('general-v1.3')
                response = model.predict_by_url(url=post.image_url)
                value = response['outputs'][0]['data']['concepts'][0]['value']
                if value > 0.9:  # if post is about garbage
                    post.save()

                return redirect('/feed/')

        else:
            form = PostForm()
        return render(request, 'post.html', {'form': form})
    else:
        return redirect('/login/')
Esempio n. 17
0
def post_view(request):
    user_valid = check_validation(request)
    if user_valid:
        if request.method == "GET":
            pform = PostForm()
        elif request.method == "POST":
            pform = PostForm(request.POST, request.FILES)
            if pform.is_valid():
                image_data = pform.cleaned_data.get('image')
                caption_data = pform.cleaned_data.get('caption')
                post_data = PostModel(user=user_valid,
                                      image=image_data,
                                      caption=caption_data)
                post_data.save()
                client = ImgurClient(
                    '42f5481cbd0457f',
                    '7bdf7000862e4cc52c8c320aa8fbb7437216c072')
                path = BASE_DIR + "/" + post_data.image.url
                image_url = client.upload_from_path(path, anon=True)['link']
                caption = post_data.caption
                type_nsfw = nsfw(image_url)
                if type_nsfw is 1:
                    post_data.image_url = image_url
                    post_data.save()
                else:
                    PostModel.objects.latest('created_on').delete()

                return redirect('/myapp/feed')
        return render(request, 'post.html', {'formdata': pform})
    else:
        return redirect('/myapp/login')
Esempio n. 18
0
def post_view(request):
    user = check_validation(request)

    if user:
        if request.method == 'POST':
            form = PostForm(request.POST, request.FILES)
            if form.is_valid():
                image = form.cleaned_data.get('image')
                caption = form.cleaned_data.get('caption')
                post = PostModel(user=user, image=image, caption=caption)
                post.save()

                path = str(BASE_DIR + '/' + post.image.url)

                client = ImgurClient(
                    '37e25d0cbc857c0',
                    'f7a8c883baef922700e185d6b987a607c7a56840')
                post.image_url = client.upload_from_path(path,
                                                         anon=True)['link']
                post.save()
                return redirect('/feed/')

        else:
            form = PostForm()
        return render(request, 'post.html', {'form': form})
    else:
        return redirect('/login/')
Esempio n. 19
0
def PostView(request):
    user = CheckValidation(request)
    if user:
        if request.method == 'POST':
            form = PostForm(request.POST, request.FILES)
            if form.is_valid():
                image = form.cleaned_data.get('image')
                caption = form.cleaned_data.get('caption')

                # saving post in database

                post = PostModel(user=user, image=image, caption=caption)
                post.save()

                path = os.path.join(BASE_DIR, post.image.url)

                client = ImgurClient(
                    'c83158842a9256e',
                    'ba219c35073b2a80347afaf222e1ebc28dcc8e1a')
                post.image_url = client.upload_from_path(path,
                                                         anon=True)['link']

                #post.image_url = cloudinary.uploader.upload(path)
                post.save()
                return redirect('/')

        else:
            form = PostForm()
        return render(request, 'post.html', {'form': form})
    else:

        return redirect('/login/')
Esempio n. 20
0
def post_view(request):
    user = check_validation(request)

    if user:
        if request.method == 'POST':
            form = PostForm(request.POST, request.FILES)
            if form.is_valid():
                image = form.cleaned_data.get('image')
                caption = form.cleaned_data.get('caption')
                post = PostModel(user=user, image=image, caption=caption)
                post.save()

                path = str(BASE_DIR + post.image.url)

                client = ImgurClient(
                    '9c9bf0c17f4ac16',
                    'cd2f3f14d28677368f0c26ee558ff6841e6e098a')
                post.image_url = client.upload_from_path(path,
                                                         anon=True)['link']
                post.save()

                return redirect('/feed/')

        else:
            form = PostForm()
        return render(request, 'post.html', {'form': form})
    else:
        return redirect('/login/')
Esempio n. 21
0
 def post_view(request):
     user = check_validation(request)
     if user == None:
         return redirect('/login/')
     elif request.method == 'GET':
         post_form = PostForm()
         return render(request, 'post.html', {'post_form': post_form})
     elif request.method == "POST":
         form = PostForm(request.POST, request.FILES)
         if form.is_valid():
             image = form.cleaned_data.get('image')
             caption = form.cleaned_data.get('caption')
             post = PostModel(user=user, image=image, caption=caption)
             post.save()
             client = ImgurClient(
                 '13aab932636aa80',
                 '5d78c0178cb9258255982d328f803d536413f567')
             path = str(BASE_DIR + "\\" + post.image.url)
             post.image_url = client.upload_from_path(path,
                                                      anon=True)['link']
             post.save()
             return redirect("/feed/")
         else:
             return HttpResponse("Form data is not valid.")
     else:
         return HttpResponse("Invalid request.")
Esempio n. 22
0
def post_view(request):
    user = check_validation(request)

    if user:
        if request.method == 'POST':
            form = PostForm(request.POST, request.FILES)
            if form.is_valid():
                image = form.cleaned_data.get('image')
                caption = form.cleaned_data.get('caption')
                post = PostModel(user=user, image=image, caption=caption)
                post.save()

                path = str(BASE_DIR + '/' +post.image.url)

                client = ImgurClient(YOUR_CLIENT_ID, YOUR_CLIENT_SECRET)
                post.image_url = client.upload_from_path(path, anon=True)['link']
                post.save()

                return redirect('/feed/')

        else:
            form = PostForm()
        return render(request, 'post.html', {'form': form})
    else:
        return redirect('/login/')
Esempio n. 23
0
def post_view(request):
    user = check_validation(request)

    if user:
        if request.method == 'POST':
            form = PostForm(request.POST, request.FILES)
            if form.is_valid():
                image = form.cleaned_data.get('image')
                caption = form.cleaned_data.get('caption')
                post = PostModel(user=user, image=image, caption=caption)
                post.save()

                path = str(BASE_DIR + '//' + post.image.url)

                client = ImgurClient(
                    '4bede6ccfad6060',
                    'c598dc22ffa6f6521d905311f2fab28b89098885')

                post.image_url = client.upload_from_path(path,
                                                         anon=True)['link']
                post.save()
                app = ClarifaiApp(api_key="c106317b6810482599634b443a8e01d8")
                model = app.models.get('general-v1.3')
                response = model.predict_by_url(url=post.image_url)
                print response

                return redirect('/feed/')

        else:
            form = PostForm()
        return render(request, 'post.html', {'form': form})
    else:
        return redirect('/login/')
Esempio n. 24
0
def post_view(request):
    user = check_validation(request)

    if user:
        if request.method == 'POST':
            form = PostForm(request.POST, request.FILES)
            if form.is_valid():
                image = form.cleaned_data.get('image')
                #caption = form.cleaned_data.get('caption')
                post = PostModel(user=user, image=image)
                post.save()

                path = str(BASE_DIR + post.image.url)

                client = ImgurClient(YOUR_CLIENT_ID, YOUR_CLIENT_SECRET)
                post.image_url = client.upload_from_path(path,
                                                         anon=True)['link']
                post.save()
                ctypes.windll.user32.MessageBoxW(
                    0, u"post successsfully created", u"SUCCESS", 0)
                return redirect('/feed/')

        else:
            form = PostForm()
        return render(request, 'post.html', {'form': form})
    else:
        return redirect('/login/')
Esempio n. 25
0
def post_view(request):
    #check if user is valid
    user = check_validation(request)
    #check if user exists
    if user:
        #check if request is post
        if request.method == 'POST':

            form = PostForm(request.POST, request.FILES)
            #check if form is valid
        if form.is_valid():
            #accept image
            image = form.cleaned_data.get('image')
            #accept caption
            caption = form.cleaned_data.get('caption')
            post = PostModel(user=user, image=image, caption=caption)
            #post is  save
            post.save()
            path = str(BASE_DIR + "/" + post.image.url)
            #define client
            client = ImgurClient('8fd0103958ccceb',
                                 'aa73c860636e25e381ec473bd76fb4f2d3ca1adb')
            #define image url
            post.image_url = client.upload_from_path(path, anon=True)['link']
            #save the image url
            post.save()
            #redirect to feed page
            return redirect('/feed/')
        else:
            form = PostForm()
        #load post page
        return render(request, 'post.html', {'form': form})
    else:
        return redirect('/login/')
Esempio n. 26
0
def post_view(request):
    user = check_validation(request)

    if user:

        if request.method == 'POST':
            form = PostForm(request.POST, request.FILES)
            if form.is_valid():
                image = form.cleaned_data.get('image')
                caption = form.cleaned_data.get('caption')

                post = PostModel(user=user, image=image, caption=caption)
                post.save()

                client = ImgurClient(
                    '0c6d3f3ca84e472',
                    'cd7fc1fabc96a5ade35cdcebcb6b77c3a6f21670')
                path = str(BASE_DIR + '//' + post.image.url)
                post.image_url = client.upload_from_path(path,
                                                         anon=True)['link']
                print(post.image_url)
                post.save()
                app = ClarifaiApp(api_key='c68ba2b17ce44ecdb42d94117d48a4ca')
                model = app.models.get('general-v1.3')
                response = model.predict_by_url(url=post.image_url)

                arr = response['outputs'][0]['data']['concepts']
                print arr
                for i in range(0, 10):
                    category = arr[i]['name']
                    print category
                    if category == 'nature':
                        post.category_post = category

                        break
                    elif category == 'technology':
                        post.category_post = category

                        break
                    elif category == 'food':
                        post.category_post = category
                        break
                    elif category == 'sports':
                        post.category_post = category

                        break
                    elif category == 'vehicle':
                        post.category_post = category

                post.save()

                return redirect('/feed/')
        else:
            form = PostForm()
        return render(request, 'post.html', {'form': form})
    else:
        return redirect('/login/')
Esempio n. 27
0
def post_view(request):
    user = check_validation(request)
    if user:
        if request.method == 'POST':
            form = PostForm(request.POST, request.FILES)
            #fetching image and caption from the form...................................................................
            if form.is_valid():
                image = form.cleaned_data.get('image')
                caption = form.cleaned_data.get('caption')
                post = PostModel(image=image, caption=caption, user=user)
                post.save()

                #uploading image on imgur cloud.........................................................................
                client = ImgurClient(client_id, client_secret)
                path = str(BASE_DIR + '/' + post.image.url)
                post.image_url = client.upload_from_path(path, anon=True)['link']
                post.save()

                #uploding image on cloudinary cloud.....................................................................
                #path = str(BASE_DIR + '/' + post.image.url)
                #upload = cloudinary.uploader.upload(path)
                #pdb.set_trace()
                #post.image_url = upload['url']
                #post.save()

                #doing the image analysis with the clarifai api.........................................................
                response = model.predict_by_url(post.image_url)
                response = response['outputs'][0]['data']['concepts']
                is_dirty = False
                for word in dirty:
                    for imgword in response:
                        image_word = imgword['name']
                        image_word = image_word.upper()
                        if image_word == word:
                            is_dirty = True
                            break

                if is_dirty:
                    post.dirty = True
                    post.save()

                #redirecting again to feed..............................................................................
                return redirect('/feed/')
        #handling get request...........................................................................................
        else:
            form = PostForm()
            return render(request, 'post.html', {'form': form})
    #if user is not logged in...........................................................................................
    else:
        return redirect('/login/')
Esempio n. 28
0
def post_view(request):
    user = check_validation(request)
    if user:
        if request.method == 'POST':
            form = PostForm(request.POST, request.FILES)
            if form.is_valid():
                image = form.cleaned_data.get('image')
                caption = form.cleaned_data.get('caption')
                post = PostModel(user=user, image=image, caption=caption)
                post.save()
                z = post.image.url
                path = str(BASE_DIR + '\\' + post.image.url)

                client = ImgurClient(
                    '0e144dffb567600',
                    '17ed6b09b6b16a35f32bfcd307e1b21cb132b21e')
                post.image_url = client.upload_from_path(path,
                                                         anon=True)['link']

                # using calrifai
                response = model.predict_by_url(url=post.image_url)
                right = response["outputs"][0]["data"]["concepts"][0]["value"]

                # using paralleldots
                set_api_key(PKEY)
                response = sentiment(str(caption))
                sentiment_score = response["sentiment"]

                if sentiment_score >= 0.6 and right > 0.5:
                    post.save()
                    saved_message = 'Post is successfully submitted'
                    return render(request, 'error.html',
                                  {'context': saved_message})
                else:
                    error_message = 'Post cannot be submitted'
                    post.delete()
                    return render(request, 'error.html',
                                  {'context': error_message})

            return redirect('/post/')

        else:
            form = PostForm()
        return render(
            request,
            'post.html',
            {'form': form},
        )
    else:
        return redirect('/login/')
Esempio n. 29
0
def post_view(request):
    user = check_validation(request)
    client_id = ''
    client_secret = ''

    if user:
        if request.method == 'POST':
            form = PostForm(request.POST, request.FILES)
            if form.is_valid():
                image = form.cleaned_data['image']
                caption = form.cleaned_data['caption']
                if is_abusive(caption):
                    ctypes.windll.user32.MessageBoxW(
                        0, u"Your caption contain Abusive content", u"Warning",
                        0)
                    return redirect('/post/')
                else:
                    post = PostModel(user=user, image=image, caption=caption)
                    path = BASE_DIR + "\\" + str(post.image.url)
                    client = ImgurClient(client_id, client_secret)
                    post.image_url = client.upload_from_path(path,
                                                             anon=True)['link']
                    # using clarifai api
                    app = ClarifaiApp(api_key='')
                    model = app.models.get('nsfw-v1.0')
                    img_type = model.predict_by_url(post.image_url)

                    if img_type['outputs'][0]['data']['concepts'][0][
                            'name'] == 'nsfw':
                        if img_type['outputs'][0]['data']['concepts'][0][
                                'value'] > img_type['outputs'][0]['data'][
                                    'concepts'][1]['value']:
                            post.delete()
                        else:
                            post.save()
                    else:
                        if img_type['outputs'][0]['data']['concepts'][0][
                                'value'] < img_type['outputs'][0]['data'][
                                    'concepts'][1]['value']:
                            post.delete()
                        else:
                            post.save()
                    post.save()
                return redirect('/feed/')
        else:
            form = PostForm()
        return render(request, 'post.html', {'form': form})
    else:
        return redirect('/login/')
Esempio n. 30
0
def post_view(request):
    user = check_validation(request)
    if user:
        if request.method == 'POST':
            form = PostForm(request.POST, request.FILES)
            if form.is_valid():
                image = form.cleaned_data.get('image')
                caption = form.cleaned_data.get('caption')
                post = PostModel(user=user, image=image, caption=caption)
                post.save()
                z = post.image.url
                path = str(BASE_DIR + '\\' + post.image.url)

                client = ImgurClient(
                    '4127d9468ed87d3',
                    '2ee021fa920430bbd6d998ce47d483e6f4408c63')
                post.image_url = client.upload_from_path(path,
                                                         anon=True)['link']

                # using paralleldots

                set_api_key(PKEY)
                response = sentiment(str(caption))
                sentiment_score = response['sentiment']

                if sentiment_score >= 0.6:
                    post.save()
                    saved_message = 'Post is successfully submitted'
                    return render(request, 'error.html',
                                  {'context': saved_message})
                else:
                    error_message = 'Post cannot be submitted'
                    post.delete()
                    return render(request, 'error.html',
                                  {'context': error_message})

            return redirect('/post/')

        else:
            form = PostForm()
        return render(
            request,
            'post.html',
            {'form': form},
        )
    else:
        return redirect('/login/')