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.\n\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\n'
summarize_sentiment(text)

text = "Nearly all great ideas follow a similar creative process and this article explains how this process works. Understanding this is important because creative thinking is one of the most useful skills you can possess. Nearly every problem you face in work and in life can benefit from innovative solutions, lateral thinking, and creative ideas.\nAnyone can learn to be creative by using these five steps. That's not to say being creative is easy. Uncovering your creative genius requires courage and tons of practice. However, this five-step approach should help demystify the creative process and illuminate the path to more innovative thinking.\nTo explain how this process works, let me tell you a short story.\nA Problem in Need of a Creative Solution\nIn the 1870s, newspapers and printers faced a very specific and very costly problem. Photography was a new and exciting medium at the time. Readers wanted to see more pictures, but nobody could figure out how to print images quickly and cheaply.\nFor example, if a newspaper wanted to print an image in the 1870s, they had to commission an engraver to etch a copy of the photograph onto a steel plate by hand. These plates were used to press the image onto the page, but they often broke after just a few uses. This process of photoengraving, you can imagine, was remarkably time consuming and expensive.\nThe man who invented a solution to this problem was named Frederic Eugene Ives. He went on to become a trailblazer in the field of photography and held over 70 patents by the end of his career. His story of creativity and innovation, which I will share now, is a useful case study for understanding the 5 key steps of the creative process.\nA Flash of Insight\nIves got his start as a printer’s apprentice in Ithaca, New York. After two years of learning the ins and outs of the printing process, he began managing the photographic laboratory at nearby Cornell University. He spent the rest of the decade experimenting with new photography techniques and learning about cameras, printers, and optics.\nIn 1881, Ives had a flash of insight regarding a better printing technique.\n“While operating my photostereotype process in Ithaca, I studied the problem of halftone process,” Ives said. “I went to bed one night in a state of brain fog over the problem, and the instant I woke in the morning saw before me, apparently projected on the ceiling, the completely worked out process and equipment in operation.”\nIves quickly translated his vision into reality and patented his printing approach in 1881. He spent the remainder of the decade improving upon it. By 1885, he had developed a simplified process that delivered even better results. The Ives Process, as it came to be known, reduced the cost of printing images by 15x and remained the standard printing technique for the next 80 years.\nAlright, now let's discuss what lessons we can learn from Ives about the creative process.\nIn some circles, Ben Hogan is credited with “inventing practice.”\nHogan was one of the greatest golfers of the 20th century, an accomplishment he achieved through tireless repetition. He simply loved to practice. Hogan said, “I couldn't wait to get up in the morning so I could hit balls. I'd be at the practice tee at the crack of dawn, hit balls for a few hours, then take a break and get right back to it.”\nFor Hogan, every practice session had a purpose. He reportedly spent years breaking down each phase of the golf swing and testing new methods for each segment. The result was near perfection. He developed one of the most finely-tuned golf swings in the history of the game.\nHis precision made him more like a surgeon than a golfer. During the 1953 Masters, for example, Hogan hit the flagstick on back-to-back holes. A few days later, he broke the tournament scoring record.\nAudrey Hepburn was an icon.\nRising to fame in the 1950s, she was one of the greatest actresses of her era. In 1953, Hepburn became the first actress to win an Academy Award, a Golden Globe Award, and a BAFTA Award for a single performance: her leading role in the romantic comedy Roman Holiday.\nEven today, over half a century later, she remains one of just 15 people to earn an “EGOT” by winning all four major entertainment awards: Emmy, Grammy, Oscar, and Tony. By the 1960s, she was averaging more than one new film per year and, by everyone's estimation, she was on a trajectory to be a movie star for decades to come.\nBut then something funny happened: she stopped acting.\nDespite being in her 30s and at the height of her popularity, Hepburn basically stopped appearing in films after 1967. She would perform in television shows or movies just five times during the rest of her life.\nInstead, she switched careers. She spent the next 25 years working tirelessly for UNICEF, the arm of the United Nations that provides food and healthcare to children in war-torn countries. She performed volunteer work throughout Africa, South America, and Asia.\nHepburn's first act was on stage. Her next act was one of service. In December 1992, she was awarded the Presidential Medal of Freedom for her efforts, which is the highest civilian award of the United States.\nWe will return to her story in a moment.\nThe ultimate productivity hack is saying no.\nNot doing something will always be faster than doing it. This statement reminds me of the old computer programming saying, “Remember that there is no code faster than no code.”\nThe same philosophy applies in other areas of life. For example, there is no meeting that goes faster than not having a meeting at all.\nThis is not to say you should never attend another meeting, but the truth is that we say yes to many things we don't actually want to do. There are many meetings held that don't need to be held. There is a lot of code written that could be deleted.\nHow often do people ask you to do something and you just reply, “Sure thing.” Three days later, you're overwhelmed by how much is on your to-do list. We become frustrated by our obligations even though we were the ones who said yes to them in the first place.\nIt's worth asking if things are necessary. Many of them are not, and a simple “no” will be more productive than whatever work the most efficient person can muster.\nBut if the benefits of saying no are so obvious, then why do we say yes so often?"
summarize_sentiment(text)