text_plain_output_1.png
from happytransformer import HappyTextToText

from heapq import nlargest

from spacy.lang.en.stop_words import STOP_WORDS

from string import punctuation

from transformers import pipeline

import spacy

happy_tt1 = HappyTextToText('BERT', 'sshleifer/distilbart-cnn-12-6')

text = '\nIn light of recent news from Apple, facial recognition technology is now the talk of the town. Ranging from privacy concerns to a curious boyfriend unlocking his girlfriend’s phone while she sleeps. The first commercial application of 3D facial recognition means that biometric technology is advancing at a staggering rate but so is the ability to hack or fool facial recognition tech.\n\nToday, 99% of the infrastructure scattered around the world consists of 2D cameras capable of running advanced facial recognition software and it will likely be years before a physical overhaul to 3D cameras takes place. Hackers, hobbyists, educators and the like have been developing creative ways to either fool or hide from 2D face recognition in a perpetually innovative game of cat and mouse.\n\nThe introduction of 3D recognition will give way to an entirely new thought process of how to beat an incredibly advanced technology, and also raise some questions as to how and by whom it will be used. The fight is futile as the effort exerted to trick this technology is better spent working with the facial recognition companies to enforce acceptable regulations.\n\nFirst, I question the intention of these types of face recognition-fooling solutions. Are they for bad actors hoping to sneak away undetected? Are they for people who are concerned about their picture being stored in a massive database (I’d worry more about posting a picture to Facebook…)? Are they to demonstrate the inherent risk of biometric information?\n\nThe variations that humans have designed to deceive the machine are more likely to make you stand out than blend in. Such as custom makeup, hairstyles, masks, a pair of glasses designed at Carnegie Melon consisting of camouflage patterns or simply wearing a box over your head. Some of them are realistic, but most are just for fun\n\nAs these techniques improve, so does the technology capable of identifying and training against them resulting in more robust face recognition software. These solutions seem like a great way to protect individuals who are looking to keep their identity hidden for nefarious reasons.\nA further concern would be detecting an attempt to impersonate an individual by using a picture of their face. With 3D cameras, this type of hack is very difficult to achieve due to the complexity of depth measurements. Facial recognition technology can run liveness detection or use additional hardware for heat sensing, both of which are capable of being tricked to a degree as seen with Samsung and Google.\n\nThe availability of public facial images is far more concerning due to the ease of which you would be able to render a 3D model from a small set of images and use virtual reality tools to project a face.\n\nOn the surface, these types of hacks would seem alarming but if gaining access to your phone now is as easy as guessing a 4-digit passcode, society should deem these tolerable risks.\n\nUltimately it is on facial recognition companies and Trueface to mitigate this risk by being more innovative, detecting consistencies in attacks and training the technology to identify when hacks occur. This game will continue to be played and become significantly more sophisticated with the adoption of 3D facial recognition.\n\n'

result1 = happy_tt1.generate_text(text)

string = str(result1)

sentiment_analyzer = pipeline('sentiment-analysis')

result = sentiment_analyzer(string)

def sum_sent(text):
    result1 = happy_tt1.generate_text(text)
    string = str(result1)
    result = sentiment_analyzer(string)

text = 'Smoking is a practice in which a substance is burned and the resulting smoke is typically breathed in to be tasted and absorbed into the bloodstream. \nMost commonly, the substance used is the dried leaves of the tobacco plant, which have been rolled into a small rectangle of rolling paper to create a small, round cylinder called a cigarette. \nSmoking is primarily practised as a route of administration for recreational drug use because the combustion of the dried plant leaves vaporizes and delivers active substances into the lungs where they are rapidly absorbed into the bloodstream and reach bodily tissue. \nIn the case of cigarette smoking these substances are contained in a mixture of aerosol particles and gases and include the pharmacologically active alkaloid nicotine; the vaporization creates heated aerosol and gas into a form that allows inhalation and deep penetration into the lungs where absorption into the bloodstream of the active substances occurs. In some cultures, smoking is also carried out as a part of various rituals, where participants use it to help induce trance-like states that, they believe, can lead them to spiritual enlightenment.\n\n'

def summarize_sentiment(text):
    stopwords = list(STOP_WORDS)
    nlp = spacy.load('en_core_web_sm')
    doc = nlp(text)
    tokens = [token.text for token in doc]
    word_freq = {}
    for word in doc:
        if word.text.lower() not in stopwords:
            if word.text.lower() not in punctuation:
                if word.text not in word_freq.keys():
                    word_freq[word.text] = 1
                else:
                    word_freq[word.text] += 1
    max_freq = max(word_freq.values())
    for word in word_freq.keys():
        word_freq[word] = word_freq[word] / max_freq
    sentence_tok = [sent for sent in doc.sents]
    sent_scores = {}
    for sent in sentence_tok:
        for word in sent:
            if word.text.lower() in word_freq.keys():
                if sent not in sent_scores.keys():
                    sent_scores[sent] = word_freq[word.text.lower()]
                else:
                    sent_scores[sent] += word_freq[word.text.lower()]
    select_len = int(len(sentence_tok) * 0.3)
    summary = nlargest(select_len, sent_scores, key=sent_scores.get)
    final_sum = [word.text for word in summary]
    summary = ' '.join(final_sum)
    result = sentiment_analyzer(summary)

text = 'Have you ever found yourself dwelling on an insult or fixating on your mistakes? Criticisms often have a greater impact than compliments, and bad news frequently draws more attention than good.\n\nThe reason for this is that negative events have a greater impact on our brains than positive ones. \nPsychologists refer to this as the negative bias (also called the negativity bias), and it can have a powerful effect on your behavior, your decisions, and even your relationships.\nThe negative bias is our tendency not only to register negative stimuli more readily but also to dwell on these events. Also known as positive-negative asymmetry, this negativity bias means that we feel the sting of a rebuke more powerfully than we feel the joy of praise.\n\nThis psychological phenomenon explains why bad first impressions can be so difficult to overcome and why past traumas can have such long lingering effects. In almost any interaction, we are more likely to notice negative things and later remember them more vividly.1\ufeff\n\nAs humans, we tend to:\n\nRemember traumatic experiences better than positive ones.\nRecall insults better than praise.\nReact more strongly to negative stimuli.\nThink about negative things more frequently than positive ones.\nRespond more strongly to negative events than to equally positive ones.\nFor example, you might be having a great day at work when a coworker makes an offhand\ncomment that you find irritating. \nYou then find yourself stewing over his words for the rest of the workday.'
summarize_sentiment(text)

text = 'Friendship is a bond between two or more people. These people are called friends. Friends need each other for fun and help. Without friendship, life would be lonely and sad. Friendship is like happiness gifted to us by God. We can share so many things with friends. We can share joy, sorrow, and your feelings. Just being with friends feels so good.\nFriends support you and give you advice. Friends will always be there for you in need. You can trust them and have faith in them. They never judge you or put you down. If a friendship is a garden, friends are flowers. Together they make your life smell like flowers. We must always hold onto friendship and friends.\n'
summarize_sentiment(text)