Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Events
Videos
Audiobooks
Packt Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds

How-To Tutorials - ChatGPT

108 Articles
article-image-practical-vulnerability-scanning-made-easy-with-chatgpt
Clint Bodungen
13 Jun 2023
8 min read
Save for later

Practical Vulnerability Scanning Made Easy with ChatGPT

Clint Bodungen
13 Jun 2023
8 min read
This article is an excerpt from the book, ChatGPT for Cybersecurity Cookbook, by Clint Bodungen. This book will help you master ChatGPT and the OpenAI API, and harness the power of cutting-edge generative AI and large language models to revolutionize the way you perform penetration testing, threat detection, and risk assessment.Vulnerability scanning is crucial for identifying weaknesses before exploitation. Navigating tools like NMAP, OpenVAS, or Nessus can be complex, especially for newcomers. Our article uses ChatGPT to generate command strings based on user input, simplifying the process. By following this recipe, you can generate precise command strings for NMAP, OpenVAS, or Nessus, confidently navigating their functionalities. Whether you're a cybersecurity beginner or an expert, this recipe is a valuable tool for vulnerability assessments.Getting ready Before we begin this recipe, it's essential to ensure that you have properly set up your OpenAI account and obtained your API key. Additionally, you will require the following: Vulnerability Scanning Tools: It's crucial to have NMAP, OpenVAS, or Nessus installed on your system as the recipe generates command strings for these specific tools. Please refer to their official documentation for installation and setup guidelines.  Basic Understanding of the Tools: The more familiar you are with NMAP, OpenVAS, or Nessus, the better you will be able to utilize this recipe. If you're new to these tools, consider spending some time understanding their basic functionalities and command-line options. Command Line Environment: As the recipe generates command strings intended for command line interfaces, you should have access to a suitable command line environment where you can run these commands. Sample Network Configuration Data: Prepare some sample network data that the vulnerability scanning tools can use. This could include IP addresses, hostnames, or other relevant information about the systems you'd like to scan. How to do it… In this recipe, we'll show you how to use ChatGPT to create command strings for vulnerability scanning tools like NMAP, OpenVAS, and Nessus. We'll be providing ChatGPT with the necessary details and using a specific system role and prompt. This will allow you to generate the simplest form of the command necessary to complete your request. Start by logging in to your OpenAI account and go to the ChatGPT web UI. Begin a new conversation with ChatGPT by clicking on the "New Chat" button. Next, establish the system's role by entering the following: You are a professional cybersecurity red team specialist and an expert in penetration testing as well as vulnerability scanning tools such as NMap, OpenVAS, Nessus, Burpsuite, Metasploit, and more.  Now, prepare your request. This is the information that will replace the {user_input} in the next step. It should be a natural language request such as: Use the command line version of OpenVAS to scan my 192.168.20.0 class C network starting by identifying hosts that are up, then look for running web servers, and then perform a vulnerability scan of those web servers.  Once your request is ready, enter the following message text, replacing the {user_input} placeholder with your specific request from the previous step: Provide me with the Linux command necessary to complete the following request:  {user_input}  Assume I have all necessary apps, tools, and commands necessary to complete the request. Provide me with the command only and do not generate anything further. Do not provide any explanation. Provide the simplest form of the command possible unless I ask for special options, considerations, output, etc. If the request does require a compound command provide all necessary operators, pipes, etc. as a single one-line command. Do not provide me more than one variation or more than one line. ChatGPT will then generate the command string based on your request. Review the output. If it meets your requirements, you can proceed to copy the command and use it as needed. If it doesn't, you may need to refine your request and try again.  Once you've obtained a satisfactory command, you can copy it and paste it directly into your command line to perform the vulnerability scan as described in your request. Note Remember, it's important to review and understand any command before running it in your environment. While ChatGPT aims to provide accurate commands, you are ultimately responsible for ensuring the command's safety and appropriateness for your specific context. Figure 1 shows an example ChatGPT command generated from the prompt used in this recipe.  Figure 1 – Example ChatGPT Command Generation  How it works… The GPT-assisted vulnerability scanning recipe taps into the power of natural language processing (NLP) and the vast knowledge of machine learning algorithms to generate accurate and appropriate command strings for vulnerability scanning tools like NMAP, OpenVAS, and Nessus. When you provide a specific system role and a prompt that represents a user request, ChatGPT uses these inputs to understand the context and generate a response that aligns with the given role. System Role Definition: By defining ChatGPT's role as a professional cybersecurity red team specialist and an expert in penetration testing and vulnerability scanning tools, you're instructing the model to answer from a perspective of deep technical understanding and expertise in this field. This context helps in generating accurate and relevant command strings. Natural Language Prompt: The natural language prompt that simulates a user request allows ChatGPT to understand the task at hand in a human-like manner. Instead of needing structured data or specific keywords, ChatGPT can interpret the request as a human would and provide a suitable response. Command Generation: With the role and the prompt, ChatGPT generates the Linux command necessary to complete the request. The command is based on the specific details of the user input and the expertise of the assigned role. This is where the AI leverages its knowledge of cybersecurity and language understanding to construct the necessary command string. One-Line Command: The specification of providing a one-line command, including all necessary operators and pipes, compels ChatGPT to generate a command that's ready to be pasted into a command line for immediate execution. This removes the need for the user to manually combine or modify the command, saving time and potential errors. Simplicity and Clarity: By asking for the simplest form of the command and without any further explanation, the output is kept clear and concise, which is particularly helpful for those learning or in need of a quick reference. In summary, the GPT-assisted vulnerability scanning recipe harnesses the power of NLP and machine learning algorithms to generate precise, ready-to-run commands for vulnerability scanning. By using the defined system role and prompt, users can streamline the process of crafting commands for vulnerability assessments, save time, and improve accuracy. There’s more… The flexibility and capabilities of this GPT-assisted process extend beyond the example given. First is the versatility of the prompt. It's actually designed to accommodate virtually any request for any Linux command across any domain or task. This is a significant advantage as it enables you to leverage ChatGPT's capabilities across a wide range of scenarios. By assigning the role appropriately, such as "You are a Linux system administrator", and substituting your specific request in place of {user_input}, you can guide the AI to generate accurate and context-specific command strings for a plethora of Linux operations. Beyond simply generating command strings, the potential of this recipe is amplified when combined with the OpenAI API and Python. With the proper setup, you can not only generate the necessary Linux commands but also automate the execution of these commands. Essentially, this could turn ChatGPT into an active participant in your command-line operations, potentially saving you significant time and effort. This level of automation represents a substantial step forward in interacting with AI models, turning them into active assistants rather than passive information generators. In upcoming recipes in this book, we'll delve deeper into command automation. This is just the beginning of the possibilities opened up by the integration of AI with your operating system tasks.  Summary:This article highlights vulnerability assessment and the role of ChatGPT in simplifying the process. ChatGPT offers the ability to simulate attack scenarios, identify weaknesses, and generate reports. However, it is crucial to remember that vulnerability assessment requires human expertise and judgment. ChatGPT should be used as a supplementary tool alongside human analysis to enhance cybersecurity measures and mitigate emerging threatsAuthor BioClint Bodungen is a cybersecurity professional with 25+ years of experience and the author of Hacking Exposed: Industrial Control Systems. He began his career in the United States Air Force and has since many of the world's largest energy companies and organizations, working for notable cybersecurity companies such as Symantec, Kaspersky Lab, and Booz Allen Hamilton. He has published multiple articles, technical papers, and training courses on cybersecurity and aims to revolutionize cybersecurity education using computer gaming (“gamification”) and AI technology. His flagship product, ThreatGEN® Red vs. Blue, is the world’s first online multiplayer cybersecurity simulation game, designed to teach real-world cybersecurity.    Links - Twitter  LinkedIn  YouTubeClint has some exciting courses around ChatGPT for Cybersecurity 
Read more
  • 0
  • 0
  • 7601

article-image-building-etl-pipelines-in-no-time-using-chatgpt
Sagar Lad
11 Jun 2023
5 min read
Save for later

Building ETL Pipelines in no time using ChatGPT

Sagar Lad
11 Jun 2023
5 min read
Given the volume, velocity, and diversity of data expanding at an exponential rate in the modern era, it is crucial to utilize this data for data analytics and machine learning projects to generate business insights. Let's discuss in this post how to utilize ChatGPT to develop ETL pipelines considering the growing popularity of ChatGPT in recent years.What is an ETL (Extract, Transform, and Load) Pipeline Data must first be fetched from one or more sources, processed, or transformed in accordance with the requirements, and then loaded into a storage system that can be used directly by end users without the need for data validation or poor data quality. ETL Pipeline also known as a ‘Data Pipeline’ sometimes known as three phases. Image 1: ETL Process Flow (Extract, Transformation, and Load) During the ETL process, first, we fetch the data, and we perform data quality and validation checks on the extracted data. Once data is extracted then data pre and post-processing should be done to transform the data into a usable format. Once data processing is done, the last step is to store the data from where the end user can access this data. Let’s ask ChatGPT to build an ETL pipeline for data engineering.Problem StatementUsing Databricks and Pyspark build an ETL pipeline using 3 layered approaches: Raw, Bronze, and Gold Layers.  Data should be ingested incrementally automatically, and data should be stored in Azure SQL Database. Business Analysts can use this data to derive business insights.1. Input to ChatGPT with the programming language, and file information (location, format, delimiter, headers, output) Image 2 : Input to chatGPT to create ETL Pipeline Here, the input has been given to the ChatGPT to build an ETL pipeline with all the required input. 2. Prerequisites suggested by ChatGPT before using the code are as follows:  Image 3 : Prerequisite to setup ETL Flow Here, ChatGPT first lists down the prerequisites to set up the blob storage, azure data lake storage gen2, and Databricks workspace.3. Importing the necessary libraries and configuring the ADLS Gen2 storage credentials as shown in the preceding figure:Image 4 : ADLS Gen2 configuration for Pyspark NotebookThis code configures ADLS gen2 using the pyspark notebook to connect and use the data using the storage account key. Here, you should replace the storage account name and key with your storage account name and key details. 4. In this step, pyspark notebook creates the schema for the pyspark data frame based on the file information and we must replace adls container name with the actual container name of ADLS Gen2. Image 5 : Create Structured Schema for pyspark dataframe5. This piece of code renames the columns and once the data frame is ready, it will write the content of the dataframe to the delta format. Image 6 : Pyspark Notebook - Data Transformation Logic 6.  Finally, ChatGPT provides guidance on where to run this code and how to set up an automated pipeline using Databricks. Image 7 : Final ChatGPT Output  7. At a first glance, it looks like it worked like a charm. Generated code can be directly used in the Databricks workspace to build an ETL pipeline. But the limitation of this solution is that it is hard coding the file path so it is not a generic code.Image 8 : Pyspark Code Optimization - ChatGPT input  8.     ChatGPT creates a generic code that can be used to trigger the ETL pipeline whenever there is a new source file in the ADLS Gen2 container. Image 9 : ADLS Gen2 configuration for Pyspark Notebook9.     Next step is to configure the ADLS Gen2 to connect to Databricks using the storage account key.Image 10 : Schema Definition for CSV File 10.  Next step is to create a structured schema to use it while creating the pyspark dataframe in the next step: Image 11: Setting up a loop to check new files 11.  As a final step, we will work towards optimizing the PySpark code: Image 12: Optimised Pyspark Code for incremental data loadTo process any file using the ETL pipeline code, the suggestion is to loop the code to continuously poll the storage container location to check if there is any new file and execute the code to process the new file if any.So, we can use this code and set up Databricks notebooks in a couple of minutes to set up an automated data pipeline for the incremental data load.ConclusionIt is getting much easier and more efficient to build ETL data pipelines using the ChatGPT. ChatGPT can also assist to create a generic and optimized code as per our requirements promptly without spending development efforts. Author BioSagar Lad is a Cloud Data Solution Architect with a leading organization and has deep expertise in designing and building Enterprise-grade Intelligent Azure Data and Analytics Solutions. He is a published author, content writer, Microsoft Certified Trainer, and C# Corner MVP. Link - Medium , Amazon , LinkedIn 
Read more
  • 0
  • 0
  • 8350

article-image-using-gpt-4-for-offensive-security
Indrajeet Bhuyan
11 Jun 2023
7 min read
Save for later

Using GPT-4 for Offensive Security

Indrajeet Bhuyan
11 Jun 2023
7 min read
In this article, we will explore the cutting-edge capabilities of GPT-4, the latest advancement in language models, and discover how it can revolutionize offensive security strategies. This article delves into practical examples, demonstrating how GPT-4 can be leveraged for tasks such as vulnerability assessment, penetration testing, and threat intelligence gathering. Gain insights into its enhanced natural language understanding, automated exploit generation, and intelligent attack simulations, opening new avenues for proactive cybersecurity defenses. Harness the potential of GPT-4 to fortify your offensive security arsenal.Reminder: Generative AI is known for hallucinations where they give replies which are lies, and not true so always verify your information.Here are a few use cases where you can use GPT for Offensive Security tasks:Writing phishing mailsEarlier one of the ways to detect phishing emails was bad English. Often phishing emails have a history of having incorrect English as often attackers are from non-English speaking places. But now the availability of generative AI tools enables a broader range of users to create convincing phishing and spam messages, even if they lack the skills to do so manually.For instance, these tools can be used to generate social engineering drafts that impersonate an employee or a company, making it easier for individuals with little experience in crafting these messages to carry out these types of attacks.Example:Image 1: Example of Phishing EmailExploit developmentChatGPT can assist in identifying vulnerabilities, as demonstrated by Cybernews researchers who used the chatbot to exploit a vulnerability that was discovered. However, ChatGPT is programmed to not offer illicit services, like hacking. Therefore, carefully phrased queries are necessary. Merely asking the chatbot to create an exploit for a particular vulnerability will not suffice.The researchers informed the chatbot that they were conducting a 'Hack the Box' pen test challenge and required assistance in locating a vulnerability. Once discovered, they were given step-by-step instructions, exploit code examples, and samples to use. As a result, the security researchers were able to identify and write an exploit for a well-known application within 45 minutes. This once again showcases how ChatGPT has made a previously complicated and lengthy process accessible to everyone.Write scriptsGPT-4 can be used to write automation scripts that can make the work of a security professional easExample : Here I’m asking ChatGPT to write a Python script that will use httpx to see all the live web hosts from a list of text files containing URLs and then use nuclei on all the domains:Image 2: Python script outputSource Code reviewChatGPT now with GPT-4 can be used to do source code reviews. It can help security professionals iXn do source code reviews faster. Though sometimes it gives wrong answers it can be used to get a good suggestion which later the security professional can use to verify if the response is correct or not.Example: I asked GPT-4 to find a security vulnerability in this code <?php if( isset( $_POST[ 'Submit' ]  ) ) {            // Get input            $target = $_REQUEST[ 'ip' ];            // Determine OS and execute the ping command.            if( stristr( php_uname( 's' ), 'Windows NT' ) ) {                        // Windows                        $cmd = shell_exec( 'ping  ' . $target );            }            else {                        // *nix                        $cmd = shell_exec( 'ping  -c 4 ' . $target );            }            // Feedback for the end user            $html .= "<pre>{$cmd}</pre>"; } ?> Here is the response:Image 3: Code reviewHere the code was simple and it could find a flaw in the code correctly but with complex code, it often gives incorrect responses. But these responses can help security professionals in doing their tasks fast as they can get feedback from ChatGPT and can filter out incorrect information:Create your own Nuclei templateChatgpt can be used to create a Nuclei template which can later help in automating the task of finding flaws.Example: Image 4: Nuclei templateWrite reportsThis one is my favorite. As a penetration tester or security professional one needs to write a lot of reports. Reports for clients, reports for other team members, etc. Chatgpt can be extensively used for writing security reports. Though I don’t recommend using chatGPT to make the entire report it can be used for making the task of writing reports easyExample 1: Here I’m asking ChatGPT to help me write a bug bounty report for an SSRF flaw that I found in example.com along with how to fix the issue: Image 5: Bug Bounty ReportExample 2: Here I’m asking Chatgpt to write a report on OWASP's top 10 flaws along with how to fix those flaws which I need to send to the client:Image 6: OWASP top 10 flawsPrepare for interviews.Chatgpt can be used for preparing for technical interviews as it can show you common questions that are asked for your role and position.Example: Here I’m asking ChatGPT to suggest me 10 questions along with an answer for a penetration tester job with 3 years of experience:Image 10: Interview QuestionsWrite technical blogs and articlesChatgpt is now more powerful with GPt-4 and it can help you write technical articles by giving you valuable inputs and suggestions.Fun fact: GPT-4 is used intensively while writing this article that you are reading.ConclusionIn conclusion, GPT-4, together with Chatgpt, has the potential to simplify numerous tasks in offensive security, thereby offering valuable assistance to security professionals. Though there are concerns about the possibility of individuals misusing this technology, its positive use cases cannot be disregarded. However, it is unlikely that GPT-4 can replace security professionals soon. Nonetheless, security experts who incorporate AI in their work can certainly outperform those who do not leverage this technology. Ultimately, it is up to us to determine how we use this powerful tool and ensure that it is utilized for the greater good.Author BioIndrajeet Bhuyan is a security researcher from Assam, India. He holds a Bachelor of Technology (B.Tech.) focused on Computer Science from Assam Don Bosco University. He has contributed security to various companies and organizations like Whatsapp, HTC, Samsung, Photobucket, Reverbnation, TVF, ESET, etc. He got featured in multiple national and international news portals like International Business Times, Russia Today, Times of India, Digit, Kaspersky, The Independent, India Today, etc. for his work on cybersecurity. He created ‘WannaSmile’ a tool that was used to protect users from the world’s biggest ransomware attack ‘ WannaCry’ which was featured by various national and international media.LinkedIn 
Read more
  • 0
  • 0
  • 7003

article-image-infusing-old-school-powerpoint-presentations-with-gpt-powers
Andrei Gheorghiu
08 Jun 2023
9 min read
Save for later

Infusing Old-school PowerPoint Presentations with GPT Powers

Andrei Gheorghiu
08 Jun 2023
9 min read
IntroductionRumor has it that around 30 million PowerPoint presentations are being created each day. Oh, PowerPoint, the sturdy old friend in the world of presentations. You might ask, why, in this fast-paced, ever-evolving digital world, do people still reach out for PowerPoint? Well, let me break it down for you, because honestly, PowerPoint has still got game! It’s simple, universal (in the realm of presentations), easy to learn and pretty well integrated with the other two Microsoft musketeers (Word & Excel).So, sure, there are fancier new alternatives out there (like Prezi or Canva), each with their unique features and slick interfaces. But when it comes to a tried-and-true solution for your presentation needs, you might find that, like a well-loved pair of sneakers, PowerPoint fits just right.And here’s the news: the little AI based automation I am going to show you in this article might actually change your mind about the capabilities of PowerPoint and make you reconsider using much more modern alternatives for your presentations.Working as a trainer for the last 15 years, I’ve probably seen more PowerPoint than other people do. I used it daily both for studying and teaching, whether for 15-minute presentations or 5-day long courses. I’ve always thought the greatest power of PowerPoint was not in its UI, design features or the number of export formats but rather in the VBA (Visual Basic for Applications) core functionality it shares with the other tools in the Microsoft ecosystem. And yet, so much potential lays unused in this regard.Oh, did you think that VBA is dead? I’m going to prove you wrong.A key characteristic for any slide-based presentation is that the viewer only gets a glimpse of the actual knowledge in the slide. It’s more visually appealing that way, but you need a presenter to understand the story and connect the dots. And usually, the presenter needs to use some slide notes for a more cursive and natural presentation. Slide notes are like a secret teleprompter. They give you reminders, help you with the flow of your presentation, and keep you on point. They're your discreet cheat-sheet, making sure you never miss a beat during your presentation.In this article, I am going to show you how, with just a few lines of code, you can infuse your existing PowerPoint presentations with the ability to automatically generate slide notes based on your slide contents.How it worksMy approach might seem a bit crude but it is effective. Especially if your presentation contains general concepts that might fall within the knowledge span of GPT3.5 Turbo from OpenAI (or even GPT-4 if you have an API key). More niche topics, or a slide having just a single bullet of words without too much context, may not produce the best results. Afterall, it’s all automated and no matter how smart the AI model may be, it still needs context to understand the task.For those who might be unfamiliar with the GPT3.5 Turbo API: this API provides programmatic access to the same advanced language model used by ChatGPT. Its purpose in the script is to explain the concepts in a PowerPoint slide.So, the basic approach is to create a VBA macro in the presentation that performs the following:Extracts all text from the current slide.Formats the entire text and builds a specially designed prompt with it.Submits the prompt to OpenAI’s API for processing.Appends the AI answer received from the API to the current slide’s notes.Because it’s a macro, once you’ve created it you can assign a shortcut and repeat the process for each slide.Alternatively, with a bit of tweaking you could adjust the code to iterate through all the slides and create all slide notes in one go. But keep in mind there is a cost for every API call you make and for a large presentation, the cost might easily spin out of control. BeforeAfterImagine the amount of time you can save by starting with some quick AI-generated draft notes and then reviewing and adding more context instead of having to type everything in from scratch. This productivity hack can save you hours of your time or even help you make sense of presentations created by someone else that lack any explanations or trainer notes. Before you beginSome things you need to take care of before you start writing the code:Make sure you store your OpenAI API key in a local environment variable for secure and efficient access. The code works on the assumption that the API key is stored in your local environment (OPENAI_API_KEY).Enable the Developer tab on your PowerPoint. By default, this tab is not visible. To enable it and be able to create VBA code you need to go to File > Options > Customize Ribbon and select Main Tabs > Developer > Add. I know. That’s enough reason to hate PowerPoint. But at least, the good news is you only have to do it once. Once you’ve got that solved you may proceed with the next steps:Go to the Developer Tab and select Visual Basic.From the Insert menu choose Module.Add the code from the next section in the newly created module and save the file. You’ll probably be notified that the .PPTX extension does not support macros. No worries. Just click No, select .PPTM (Macro enabled presentation) as your file type and save. Make sure you customize the code first to provide the prompt with more context on your specific presentation (see the comments in the code).And that’s it. You’re good to go.Now, select Developer > Macros and you should see a new macro called QueryGpt.Just go to your desired slide and run the macro. Wait for a few seconds and you should have your notes populated with AI’s interpretation of your slide. Be mindful though, the code is simple. There’s no error checking and I haven’t tested it on hundreds of PPTs.You can download the .BAS source file for this article from here. Pro Tip: If you want to create an easy shortcut to your macro you can click on the last icon in the very top ribbon menu and select More commands and then from Choose commands from select Macros, choose the QueryGpt macro and Add. A new button for the macro will be permanently added on your ribbon.The codeNo more talking. Here’s the macro:Sub QueryGpt() Dim sld As Slide Dim shp As Shape Dim text As String Dim explanation As String Dim prompt As String Dim subject As String ' Extract and format the text from the current slide Set sld = ActiveWindow.View.Slide For Each shp In sld.Shapes If shp.HasTextFrame Then If shp.TextFrame.HasText Then text = text & " [" & Replace(shp.TextFrame.TextRange.text, vbCrLf, "/") & "] " End If End If Next shp text = Replace(Replace(Replace(text, vbCrLf, "\n"), vbCr, "\r"), vbLf, "\n") ' Prepare the prompt and call the function that queries the AI model subject = "The concept of Public Domain" prompt = "You are a useful assistant that explains the concepts from a presentation about " prompt = prompt & subject & ". Explain the following concepts: " explanation = CallOpenAI(prompt & text) ' Append the AI explanation to the slide notes sld.NotesPage.Shapes.Placeholders(2).TextFrame.TextRange.InsertAfter vbCrLf & explanation End Sub Take note of the variable called subject.That is the main topic of your presentation, and you should change that to the subject of your slides.That way the AI model gets more context about your slides and can provide better descriptions in the notes.You should be able to achieve better results by adding more details in that variable but consider the maximum context of the model (for GPT 3.5 Turbo that is around 3000 English words). The more you add to your initial input, the more you limit your result’s maximum length because the whole context cannot exceed ~3000 words.Next, here is the function responsible for making the API call and formatting the resulting answer:Function CallOpenAI(text As String) As String Dim httpRequest As Object Dim responseText As String Dim contentStartPos As Long Dim contentEndPos As Long ' Prepare the connection and send the request to the OpenAI API Set httpRequest = CreateObject("WinHttp.WinHttpRequest.5.1") httpRequest.Open "POST", "https://api.openai.com/v1/chat/completions", False httpRequest.setTimeouts 0, 60000, 30000, 120000 httpRequest.setRequestHeader "Content-Type", "application/json" httpRequest.setRequestHeader "Authorization", "Bearer " & Environ("OPENAI_API_KEY") httpRequest.Send "{""model"": ""gpt-3.5-turbo"", " _ & """messages"": [{""role"": ""user"", " _ & """content"": """ & text & """}]}" httpRequest.WaitForResponse responseText = httpRequest.responseText ' Extract the AI answer from the response string contentStartPos = InStr(1, responseText, """content"":""") + 11 responseText = Mid(responseText, contentStartPos) contentEndPos = InStr(1, responseText, """") - 1 responseText = Replace(Mid(responseText, 1, contentEndPos), "\n", vbCrLf) CallOpenAI = responseText End Function All you have to do to add this code to the presentation is to follow steps 3 to 5 above.Once you’ve created the module and saved the presentation, you’ll have the new macro called QueryGpt.If you’ve created the shortcut by following the pro tip, you’ll also have a neat way of calling the macro whenever you need to append some slide notes to the current slide.And there you go: Old-school PowerPoint presentations infused with AI super-powers.Feels like converting an old Diesel to an EV, doesn’t it? DisclaimerAs with any AI generated content do not forget to check the outputs for accuracy and potential hallucinations. (https://www.packtpub.com/page/4-ways-to-treat-a-hallucinating-AI-with-Prompt-Engineering_). Do not forget that any bias or inaccurate data in the slide content may get amplified in the outputs. Author BioAndrei Gheorghiu is an experienced trainer with a passion for helping learners achieve their maximum potential. He always strives to bring a high level of expertise and empathy to his teaching.With a background in IT audit, information security, and IT service management, Andrei has delivered training to over 10,000 students across different industries and countries. He is also a Certified Information Systems Security Professional and Certified Information Systems Auditor, with a keen interest in digital domains like Security Management and Artificial Intelligence.In his free time, Andrei enjoys trail running, photography, video editing and exploring the latest developments in technology.You can connect with Andrei on:LinkedIn: https://www.linkedin.com/in/gheorghiu/Twitter: https://twitter.com/aqg8017  
Read more
  • 0
  • 0
  • 1430

article-image-writing-unit-tests-in-c-with-ease-using-chatgpt
Jesse Liberty
08 Jun 2023
9 min read
Save for later

Writing Unit Tests in C# with ease using ChatGPT

Jesse Liberty
08 Jun 2023
9 min read
The world is abuzz with talk of large language model AI, especially its iconic ChatGPT. No one is more excited and perhaps threatened than programmers. Will ChatGPT soon write code well enough to change or even eliminate our jobs? In this article, I set such concerns aside and focus on how ChatGPT can enhance our programming today. One of the places I find ChatGPT most useful is in the writing of unit tests. To illustrate this, I'm going to dip into the source code used in my latest book: .NET MAUI For C# Developers. If you haven't read my book (actually, why not stop here and run out and buy it? I can wait here) it illustrates the creation of a helpful app that, among other things, requires you to create an account. Here is the code for doing so:  [RelayCommand] async Task SignUp() {    if (EnableButton)    {      AccountCreateRequest accountCreateRequest = new()      {        Email = this.Email,        FullName = Name,        PlainPassword = Password      };      try      {        CreateAccountIsRunning = true;        await accountService.CreateAccount(accountCreateRequest);        CreateAccountIsRunning = false;        await Application.Current.MainPage.DisplayAlert(         "Sign up completed",        "Your user has been created successfully", "Ok");        await Shell.Current.GoToAsync("..");      }      catch (Exception e)      {          CreateAccountIsRunning = false;        await Application.Current.MainPage.DisplayAlert(         "Sign up failed",        "We were not able to create an account with that user name",         "Ok");      }    } } The logic here is simple, I've selected it specifically so that you can easily imagine how you would write unit tests. Let's see how ChatGPT does when presented with this code. I opened ChatGPT and entered the following message:  Write two unit tests with xUnit and nSubstitute in C# for the following .NET MAUI code (I pasted in the code. It responded so quickly it took my breath away)Sure! Here are two unit tests using xUnit and NSubstitute for the SignUp() method: I particularly like the self-assured and friendly "Sure!" at the beginning, and the restatement of what it has been asked to do. Its results come flying out in a box that has a handy Copy Code button on the top right, and a reminder on the top left that the code is in C# as shown in the figure:   Figure 1 – top of ChatGPT response  Notice that it marks the first section. // Arrange As you'll see it uses and annotates the AAA approach to unit tests (Arrange, Act, Assert). Here are the two-unit tests it produced: public class YourViewModelTests {    [Fact]    public async Task SignUp_WhenEnableButtonIsFalse_DoesNotCallAccountServiceAndDisplaysNoAlert()    {        // Arrange        var accountService = Substitute.For<IAccountService>();        var applicationMock = Substitute.For<Application>();        var mainPageMock = Substitute.For<Page>();        var shellMock = Substitute.For<Shell>();        applicationMock.MainPage = mainPageMock;        Shell.Current = shellMock;        var viewModel = new YourViewModel(accountService)        {            Email = "test@example.com",            Name = "John Doe",            Password = "password",            EnableButton = false        };        // Act        await viewModel.SignUp();        // Assert        await accountService.DidNotReceive().CreateAccount(Arg.Any<AccountCreateRequest>());        await applicationMock.MainPage.DidNotReceive().DisplayAlert(Arg.Any<string>(), Arg.Any<string>(), Arg.Any<string>());        await shellMock.DidNotReceive().GoToAsync(Arg.Any<string>());    }    [Fact]    public async Task SignUp_WhenEnableButtonIsTrue_CallsAccountServiceAndDisplaysAlertOnError()    {        // Arrange        var accountService = Substitute.For<IAccountService>();        accountService            .When(x => x.CreateAccount(Arg.Any<AccountCreateRequest>()))            .Throw(new Exception("Failed to create account"));        var applicationMock = Substitute.For<Application>();        var mainPageMock = Substitute.For<Page>();        var shellMock = Substitute.For<Shell>();        applicationMock.MainPage = mainPageMock;        Shell.Current = shellMock;        var viewModel = new YourViewModel(accountService)        {            Email = "test@example.com",            Name = "John Doe",            Password = "password",            EnableButton = true        };        // Act        await viewModel.SignUp();        // Assert        await accountService.Received(1).CreateAccount(Arg.Is<AccountCreateRequest>(request =>            request.Email == viewModel.Email &&            request.FullName == viewModel.Name &&            request.PlainPassword == viewModel.Password));        await applicationMock.MainPage.Received(1).DisplayAlert("Sign up failed",            "We were not able to create an account with that user name", "Ok");        await shellMock.DidNotReceive().GoToAsync(Arg.Any<string>());    } }  After the code comes to these handy instructions and reminders: In the first test case, SignUp_WhenEnableButtonIsFalse_DoesNotCallAccountServiceAndDisplaysNoAlert(), we set EnableButton to false and verify that the SignUp() method does not call CreateAccount() on the accountService, and no alerts are displayed. In the second test case, SignUp_WhenEnableButtonIsTrue_CallsAccountServiceAndDisplaysAlertOnError(), we set EnableButton to true and configure the accountService to throw an exception when CreateAccount() is called. We verify that the method calls CreateAccount(), displays the appropriate alert for failure, and does not navigate to another page using GoToAsync(). By following those instructions, I had two working, useful unit tests, literally in seconds (well, a lot of seconds, but only because it took me a minute to read and understand (and verify) what it had done.) The first time I made the request, I forgot to say it in xUnit and it spits out the tests in nUnit. I then entered, Do it again using xUnit And it didn't hesitate, out came the code in xUnit along with modified instructions. Summary In sum, my pair-programming buddy, ChatGPT, saved me a lot of tedious work creating unit tests. I can attest that it works equally well on more complex logic. It doesn't always get it right the first time, but you can "tune" it with follow-up questions, and it remembers what it just did, so rather than repeating the entire command you can just say, as I do above, Do it again, but this time… We used to say, Coding by Google is not a problem as long as you know what you are doing. The problem only arose with very junior programmers who took what they found online as-is without checking that it made sense. The same can be true here: ChatGPT can get you going, and you can often use its code as-is, but you need to keep a cautious eye on it as it certainly can get things wrong.  Writing unit tests is a critical, though often overlooked part of writing code well. ChatGPT not only makes it relatively easy, but it also encourages creating tests because you can do so quickly. It is so good that I happily pay $20/month for a subscription entitling me to unrestricted use and access to the latest iteration.  Author Bio  Jesse Liberty is a full-time hands-on programmer, specializing in C#, git, and .NET MAUI. He hosts the popular Yet Another Podcast and is the author of more than a dozen best-selling programming books. Liberty is a Certified Xamarin Developer, a Xamarin MVP, and a Microsoft MVP. He was a Technical Evangelist for Microsoft, a Distinguished Software Engineer at AT&T; a Software Architect for PBS, and a Vice President of Information Technology at Citibank, and he was on the teaching staff at Brandeis University. Jesse is a recognized expert and has spoken at conferences worldwide.  Links - LinkedIn  .NET MAUI for C# Developers  
Read more
  • 0
  • 0
  • 10860

article-image-ab-testing-for-marketing-comparison-using-openai-chatgpt
Valentina Alto
08 Jun 2023
5 min read
Save for later

A/B testing for marketing comparison using OpenAI ChatGPT

Valentina Alto
08 Jun 2023
5 min read
This article is an excerpt from the book, Modern Generative AI with ChatGPT and OpenAI Models, by Valentina Alto. This book will help harness the power of AI with innovative, real-world applications, and unprecedented productivity boosts, powered by the latest advancements in AI technology like ChatGPT and OpenAI.A/B testing in marketing is a method of comparing two different versions of a marketing campaign, advertisement, or website to determine which one performs better. In A/B testing, two variations of the same campaign or element are created, with only one variable changed between the two versions. The goal is to see which version generates more clicks, conversions, or other desired outcomes.An example of A/B testing might be testing two versions of an email campaign, using different subject lines, or testing two versions of a website landing page, with different call-to-action buttons. By measuring the response rate of each version, marketers can determine which version performs better and make data-driven decisions about which version to use going forward. A/B testing allows marketers to optimize their campaigns and elements for maximum effectiveness, leading to better results and a higher return on investment.Since this method involves the process of generating many variations of the same content, the generative power of ChatGPT can definitely assist in that.Let’s consider the following example. I’m promoting a new product I developed: a new, light and thin climbing harness for speed climbers. I’ve already done some market research and I know my niche audience. I also know that one great channel of communication for that audience is publishing on an online climbing blog, of which most climbing gyms’ members are fellow readers.My goal is to create an outstanding blog post to share the launch of this new harness, and I want to test two different versions of it in two groups. The blog post I’m about to publish and that I want to be the object of my A/B testing is the following:  Figure 1– An example of a blog post to launch climbing gearHere, ChatGPT can help us on two levels:The first level is that of rewording the article, using different keywords or different attention-grabbing slogans. To do so, once this post is provided as context, we can ask ChatGPT to work on the article and slightly change some elements:Figure 2 – New version of the blog post generated by ChatGPT As per my request, ChatGPT was able to regenerate only those elements I asked for (title, subtitle, and closing sentence) so that I can monitor the effectiveness of those elements by monitoring the reaction of the two audience groups.The second level is working on the design of the web page, namely, changing the collocation of the image rather than the position of the buttons. For this purpose, I created a simple web page for the blog post published in the climbing blog (you can find the code in the book’s GitHub repository at https://github.com/PacktPublishing/The-Ultimate-Guide- to-ChatGPT-and-OpenAI/tree/main/Chapter%207%20-%20ChatGPT%20 for%20Marketers/Code):Figure 3 – Sample blog post published on the climbing blogWe can directly feed ChatGPT with the HTML code and ask it to change some layout elements, such as the position of the buttons or their wording. For example, rather than Buy Now, a reader might be more gripped by an I want one! button.So, let's feed ChatGPT with the HTML source code:Figure 4 – ChatGPT changing HTML code Let’s see what the output looks like:Figure 5 – New version of the websiteAs you can see, ChatGPT only intervened at the button level, slightly changing their layout, position, color, and wording.Indeed, inspecting the source code of the two versions of the web pages, we can see how it differs in the button sections:Figure 6 – Comparison between the source code of the two versions of the website ConclusionIn conclusion, ChatGPT is a valuable tool for A/B testing in marketing. Its ability to quickly generate different versions of the same content can reduce the time to market of new campaigns. By utilizing ChatGPT for A/B testing, you can optimize your marketing strategies and ultimately drive better results for your business.Author BioAfter completing her Bachelor's degree in Finance, Valentina Alto pursued a Master's degree in Data Science in 2021. She began her professional career at Microsoft as an Azure Solution Specialist, and since 2022, she has been primarily focused on working with Data & AI solutions in the Manufacturing and Pharmaceutical industries. Valentina collaborates closely with system integrators on customer projects, with a particular emphasis on deploying cloud architectures that incorporate modern data platforms, data mesh frameworks, and applications of Machine Learning and Artificial Intelligence. Alongside her academic journey, she has been actively writing technical articles on Statistics, Machine Learning, Deep Learning, and AI for various publications, driven by her passion for AI and Python programming.Link - Medium Modern Generative AI with ChatGPT and OpenAI Models
Read more
  • 0
  • 0
  • 5399
Unlock access to the largest independent learning library in Tech for FREE!
Get unlimited access to 7500+ expert-authored eBooks and video courses covering every tech area you can think of.
Renews at ₹800/month. Cancel anytime
article-image-integrating-chatgpt-api-with-microsoft-office
Martin Yanev
07 Jun 2023
6 min read
Save for later

Integrating ChatGPT API with Microsoft Office

Martin Yanev
07 Jun 2023
6 min read
In this article, we will explore how to set up a PyCharm project and install the docx Python library to extract text from Word documents. The docx library is a Python package that allows us to read and write Microsoft Word ( .docx) files and provides a convenient interface to access information stored in these files. The first step is to initiate your work by creating a new PyCharm project. This will enable you to have a dedicated area to craft and systematize your Translation app code.  Open PyCharm IDE on your systemClick on Create New Project from the welcome screen or go to File | New Project if you're already in the IDE Keep the default settingGive your project the name Translation AppClick on Create to create the project To run the language translation desktop app, you will need to install the following libraries:  openai: The  openai library allows you to interact with the OpenAI API and perform various natural language processing tasks.  docx: The  docx library allows you to read and write Microsoft Word files  .docx using Python.  tkinter: The  tkinter library is a built-in Python library that allows you to create graphical user interfaces (GUIs) for your desktop app.   As  tkinter is a built-in library, there is no need for installation since it already exists within your Python environment. To install the  openai and  docx libraries, access the PyCharm terminal by clicking on View | Tool Windows | Terminal, and then execute the following commands:  pip install openai pip install python-docx   To access and read the contents of a Word document, you will need to create a sample Word file inside your PyCharm project. Here are the steps to create a new Word file in PyCharm:  In PyCharm project create a new directory called files Right-click on the files folder and select New | File In the dialog box that appears, enter a file name with the extension .docx. For example, info.doc.  Select the Enter key to create the file Once the file is created, double-click on it to open it You can now add some text or content to this file, which we will later access and read using the docx library in Python. For this example, we have created an article about on New York City. However, you can choose any Word document containing text that you want to analyze.  The United States' most populous city, often referred to as New York City or NYC, is New York. In 2020, its population reached 8,804,190 people across 300.46 square miles, making it the most densely populated major city in the country and over two times more populous than the nation's second-largest city, Los Angeles. The city's population also exceeds that of 38 individual U.S. states. Situated at the southern end of New York State, New York City serves as the Northeast megalopolis and New York metropolitan area's geographic and demographic center - the largest metropolitan area in the country by both urban area and population. Over 58 million people also live within 250 miles of the city. A significant influencer on commerce, health care and life sciences, research, technology, education, politics, tourism, dining, art, fashion, and sports, New York City is a global cultural, financial, entertainment, and media hub. It houses the headquarters of the United Nations, making it a significant center for international diplomacy, and is often referred to as the world's capital.  Now that you have created the Word file inside your PyCharm project, you can move on to the next step, which is to create a new Python file called app.py inside the Translation App root directory. This file will contain the code to read and manipulate the contents of the Word file using the docx library. With the Word file and the Python file in place, you are ready to start writing the code to extract data from the document and use it in your application. To test if we can read word files with the docx Python library, we can implement the subsequent code in our app.py file:  Import docx  doc = docx.Document(“<full_path_to_docx_file>”)  text = “”  for para in doc.paragraphs:  text += para.text  print(text)  Make sure to replace the <full_path_to_docx_file> with the actual path to your Word document file. Obtaining the file path is a simple task, achieved by Right Click on your docx file in PyCharm and selecting the option Copy Path/Reference… from the drop-down menu.  Once you have done that, run the app.py file and verify the output. This code will read the contents of your Word document and print them to the Run Window console. If the text extraction works correctly, you should see the text of your document printed in the console (see figure below). The text variable now holds the data from the info.docx as a Python string.   Figure: Word text extraction console output SummaryThis section provided a step-by-step guide on how to set up a PyCharm project and install the docx Python library to extract text from Word documents. The section also included instructions on how to create a new Word file in PyCharm and use the docx library to read and manipulate its contents using Python.  Author BioMartin Yanev is an experienced Software Engineer who has worked in the aerospace and medical industries for over 8 years. He specializes in developing and integrating software solutions for air traffic control and chromatography systems. Martin is a well-respected instructor with over 280,000 students worldwide, and he is skilled in using frameworks like Flask, Django, Pytest, and TensorFlow. He is an expert in building, training, and fine-tuning AI systems with the full range of OpenAI APIs. Martin has dual master's degrees in Aerospace Systems and Software Engineering, which demonstrates his commitment to both practical and theoretical aspects of the industry. https://www.linkedin.com/in/martinyanev/https://www.udemy.com/user/martin-yanev-3/ 
Read more
  • 0
  • 0
  • 11102

article-image-audio-summarize-any-youtube-video-with-python-chatgpt-and-aws
Andrei Gheorghiu
07 Jun 2023
8 min read
Save for later

Audio Summarize Any YouTube Video with Python, ChatGPT, and AWS

Andrei Gheorghiu
07 Jun 2023
8 min read
IntroductionHave you ever wished you could just listen to the summary of a long YouTube video instead of watching the whole thing? Well, you're in luck! In this article, I’ll be showcasing a fun little Python project that I’ve been working on, which allows you to do just that.Don’t get me wrong: YouTube is a great resource for learning about new technologies and keeping you up to date with the latest news. And best of all: it’s free. But sometimes, I tend to lose track of time in the myriad of videos out there, fast forwarding through long talks only to find out in the end that the information I’m looking for is not in the video ☹Well, if you often find yourself in a similar situation, here’s a potential tool you might like. This little script downloads the audio from a YouTube video, transcribes it, summarizes it using AI and finally generates a new audio file with the summary. And all this magic is done using the OpenAI GPT-3.5-turbo API and some cool AWS services (S3, Transcribe, and Polly). In less than 80 lines of code.For those who might be unfamiliar with these APIs, here is their purpose in the script:OpenAI's GPT-3.5-turbo provides programmatic access to the same advanced language model used by ChatGPT. Its purpose in the script is summarizing the transcribed video content.AWS S3 is a storage service where we temporarily store the audio file from the YouTube video and the transcript. We have to use an S3 bucket because it is required by AWS Transcribe and AWS Polly.AWS Transcribe is used to convert the audio file into text.AWS Polly is a service that turns text into lifelike speech. We use it to generate an audio file of the summary.Logic Diagram DisclaimerBefore you start using these services, be aware that both AWS and OpenAI have usage quotas and costs associated with them. Make sure to familiarize yourself with these to avoid any unexpected charges. You’ll probably fall well within the limits of your Amazon account’s free tier unless you start summarizing hundreds of videos.Also, you might consider adding error handling in the code. To keep it short I’ve skipped it from this demo.You can download the Python file for this code from GitHub here.Configuring the APIsMake sure you store your OpenAI API Key and AWS Credentials in your local environment variables for secure and efficient access. The code works on the assumption that both the OpenAI API keys and AWS credentials are valid and have been already stored on your local environment variables. Alternatively, you can store your AWS ACCESS KEY and SECRET ACCESS KEY in %USERPROFILE%\.aws\credentialsMore info on that here: https://docs.aws.amazon.com/sdkref/latest/guide/creds-config-files.htmlFor the code to function properly make sure the AWS credentials you are using have the following permissions:AmazonS3FullAccess: This is required to create and delete S3 buckets, upload files to the buckets and delete objects within the buckets.AmazonTranscribeFullAccess: This is needed to start transcription jobs and get the transcription job results.AmazonPollyFullAccess: This is necessary to synthesize speech from text.The most convenient and safe approach to grant the necessary permissions is though the AWS Management Console by attaching the relevant policies to the user or role associated with the credentials. RequirementsI’ve used Python v3.11. Make sure you first install all the requirements or update them to the latest version if already installed.pip install pytube pip install openai pip install boto3 pip install requests pip install python-dotenvThe CodeLet’s break it down snippet by snippet. Setup and Import Statementsimport os import boto3 import requests import openai import uuid from pytube import YouTube Downloading the Audio from YouTubeThe download_audio function uses the pytube library to download the audio from a YouTube video. The audio file is saved locally before being uploaded to S3 by the main function. Here’s a complete documentation for pytube: https://pytube.io/en/latest/def download_audio(video_id): yt = YouTube(f'https://www.youtube.com/watch?v={video_id}') return yt.streams.get_audio_only().download(filename=video_id) Transcribing Audio to TextThe transcribe_audio function uses AWS Transcribe to convert the audio into text. The UUID (Universally Unique Identifier) module is used to generate a unique identifier for each transcription job. The benefit of using UUIDs here is that every time we run the function, a new unique job name is created. This is important because AWS Transcribe requires job names to be unique. Here’s the complete documentation of AWS Transcribe: https://docs.aws.amazon.com/transcribe/latest/dg/what-is.htmldef transcribe_audio(s3, bucket, file_name): transcribe = boto3.client('transcribe') job_name = f"TranscriptionJob-{uuid.uuid4()}" transcribe.start_transcription_job( TranscriptionJobName=job_name, Media={'MediaFileUri': f"s3://{bucket}/{file_name}"}, MediaFormat='mp4', LanguageCode='en-US' ) while True: status = transcribe.get_transcription_job(TranscriptionJobName=job_name) if status['TranscriptionJob']['TranscriptionJobStatus'] in ['COMPLETED', 'FAILED']: break return status['TranscriptionJob']['Transcript']['TranscriptFileUri'] if status['TranscriptionJob']['TranscriptionJobStatus'] == 'COMPLETED' else None Summarizing the TranscriptThe summarize_transcript function leverages OpenAI's GPT-3.5-turbo to summarize the transcript. Notice the simple prompt I’ve used for this task. I’ve tried to keep it very short in order to save more tokens for the actual transcript. It can definitely be improved and tweaked according to your preferences. For a complete documentation of the OpenAI API check out this link: https://platform.openai.com/docs/api-reference/introductiondef summarize_transcript(transcript): response = openai.ChatCompletion.create( model="gpt-3.5-turbo", messages=[ {"role": "system", "content": "You are a knowledge curator helping users to understand the contents of video transcripts."}, {"role": "user", "content": f"Please summarize the following transcript: '{transcript}'"} ] ) return response['choices'][0]['message']['content'].strip() Synthesizing Speech from TextThe synthesize_speech function uses AWS Polly to convert the summarized text back into audio. If you prefer other voices or want to tweak different parameters such as speed, language, or dialect, here’s the complete documentation on how to use Polly: https://docs.aws.amazon.com/polly/index.htmldef synthesize_speech(s3, bucket, transcript_uri): transcript_data = requests.get(transcript_uri).json() transcript = ' '.join(item['alternatives'][0]['content'] for item in transcript_data['results']['items'] if item['type'] == 'pronunciation') summary = summarize_transcript(transcript) summary_file_name = f"summary_{uuid.uuid4()}.txt" s3.put_object(Body=summary, Bucket=bucket, Key=summary_file_name) polly = boto3.client('polly') response = polly.synthesize_speech(OutputFormat='mp3', Text=summary, VoiceId='Matthew', Engine='neural') mp3_file_name = f"speech_{uuid.uuid4()}.mp3" with open(mp3_file_name, 'wb') as f: f.write(response['AudioStream'].read()) return mp3_file_name The Clean-up of the S3 BucketTo keep our storage in check and avoid littering the cloud, it’s best to clean up all objects from the bucket. We’ll be able to delete the bucket completely once the audio summary has been downloaded locally.Remember, we only needed the S3 bucket because it was required by AWS Transcribe and Polly.def delete_all_objects(bucket_name): s3 = boto3.resource('s3') bucket = s3.Bucket(bucket_name) bucket.objects.all().delete() The Main FunctionAnd finally, the main function, which ties everything together. It specifies the YouTube video to summarize (which you can obviously change to any another video ID), sets up the necessary AWS services and calls the functions defined above in the correct order. It also makes sure to clean up by deleting the S3 bucket after use.def main(): video_id = 'U3PiD-g7XJM' #change to any other Video ID from YouTube bucket = f"bucket-{uuid.uuid4()}" file_name = f"{video_id}.mp4" openai.api_key = os.getenv('OPENAI_API_KEY') s3 = boto3.client('s3') s3.create_bucket(Bucket=bucket) print ("Downloading audio stream from youtube video...") audio_file = download_audio(video_id) print ("Uploading video to S3 bucket...") s3.upload_file(audio_file, bucket, file_name) print("Transcribing audio...") transcript_uri = transcribe_audio(s3, bucket, file_name) print("Synthesizing speech...") mp3_file_name = synthesize_speech(s3, bucket, transcript_uri) print(f"Audio summary saved in: {mp3_file_name}\n") delete_all_objects(bucket) s3.delete_bucket(Bucket=bucket) if __name__ == "__main__": main() And that's it! With this simple tool you can now convert any YouTube video into a summarized audio file.So, sit back, relax and let AI do the work for you.Enjoy! About the AuthorAndrei Gheorghiu is an experienced trainer with a passion for helping learners achieve their maximum potential. He always strives to bring a high level of expertise and empathy to his teaching.With a background in IT audit, information security, and IT service management, Andrei has delivered training to over 10,000 students across different industries and countries. He is also a Certified Information Systems Security Professional and Certified Information Systems Auditor, with a keen interest in digital domains like Security Management and Artificial Intelligence.In his free time, Andrei enjoys trail running, photography, video editing and exploring the latest developments in technology.You can connect with Andrei on:LinkedIn: https://www.linkedin.com/in/gheorghiu/Twitter: https://twitter.com/aqg8017
Read more
  • 0
  • 0
  • 10798

article-image-creating-data-dictionary-using-chatgpt
Sagar Lad
04 Jun 2023
4 min read
Save for later

Creating Data Dictionary Using ChatGPT

Sagar Lad
04 Jun 2023
4 min read
This article highlights how ChatGPT can create data dictionaries within minutes, aiding data professionals in documenting data items. By leveraging ChatGPT's capabilities, professionals gain deeper insights, enhancing data management. A practical example demonstrates the efficiency and effectiveness of using ChatGPT in generating data dictionaries. What is a data dictionary? Data professionals, such as data engineers, data scientists, analysts, database administrators, and developers, face various data challenges, ranging from business requirement definition to data volume and speed management. To effectively tackle these difficulties, they require a comprehensive understanding of the data. Data dictionaries play a vital role in providing deeper insights into the data. A data dictionary serves as documentation for the data, encompassing names, definitions, and attributes of the database's data items. Its main purpose is to comprehend and describe the significance of data items in relation to the application, along with including data element metadata. Data dictionaries are indispensable in data projects as they contribute to success by offering valuable insights into the data. Benefits of creating a data dictionary: Conquer data discrepancies Facilitate data exploration and analysisMaintain data standards throughout the projectEstablish uniform and consistent standards for the projectEstablish data standards to control the gathered data and explain it across the project A typical data dictionary has below components:  ComponentDescriptionData ElementName of the data elementDescription Definition of the data elementData TypeType of data stored in the attribute (ex. text, number, date)LengthMaximum number of characters stored in the attributeFormatFormat  for the data (e.g. date/currency format) Valid ValuesList of allowed values for the data elementRelationshipsRelationships between different tables in the databaseSource Origin of the data (e.g. system, department)ConstraintsRules related to the use of the dataListing of data objectsNames and DefinitionsDetailed properties of data elementsData type, Size, nullability, optionality, indexesBusiness rulesSchema validation or Data Quality Image 1 : Sample Database Schema with Data Attribute Name, Data Type & Constraints     As demonstrated in the example above, each database has a basic set of data about the data dictionary, but this information is insufficient when working with a database that has numerous tables, each of which may have multiple columns.  Creating a practical data dictionary with ChatGPT Data and natural language processing can be used by ChatGPT to produce in-depth knowledge on any subject. As a result, ChatGPT may be used to build instructive data dictionaries for any dataset.       Image 2: ChatGPT to create Data Dictionary Let’s understand the step-by-step process to create a data dictionary using ChatGPT: Finding and copying the data               Let us ask ChatGPT for one of the public datasets to create a data dictionary:    List of Data Sources recommended by ChatGPT Now, I will download the csv file named Institutions.csv from the FDIC Bank Data API. Image 4: Downloaded CSV file for FDIC Bank DataLet’s use this data to create a data dictionary using ChatGPT. Prepare ChatGPT Let’s now prompt the GPT to create a raw data dictionary for the dataset that we picked above:Image 5: Output Data Dictionary Request Data Dictionary with additional information Additionally, we can request that ChatGPT add new columns and other pertinent data to the output of the data dictionary. For instance, in the sample below, I've asked ChatGPT to add a new column called Active Loan and to provide descriptions to the columns based on its knowledge of banking. Output Data Dictionary from ChatGPT with additional columns and informationWe can now see that the data dictionary is updated which can be shared within the organization.ConclusionIn conclusion, leveraging ChatGPT's capabilities expedites the creation of data dictionaries, enhancing data management for professionals. Its efficiency and insights empower successful data projects, making ChatGPT a valuable tool in the data professional's toolkit. Author BioSagar Lad is a Cloud Data Solution Architect with a leading organization and has deep expertise in designing and building Enterprise-grade Intelligent Azure Data and Analytics Solutions. He is a published author, content writer, Microsoft Certified Trainer, and C# Corner MVP. Link - Medium, Amazon, LinkedIn.
Read more
  • 0
  • 0
  • 23778

article-image-using-openai-python-library-to-interact-with-the-chatgpt-api
Martin Yanev
04 Jun 2023
7 min read
Save for later

Using OpenAI Python Library to Interact with the ChatGPT API

Martin Yanev
04 Jun 2023
7 min read
Using the ChatGPT API with Python is a relatively simple process. You'll first need to make sure you create a new PyCharm project called ChatGPTResponse as shown in the following screenshot: Fig 1: New Project Window in PyCharm Once you have that setup, you can use the OpenAI Python library to interact with the ChatGPT API. Open a new Terminal in PyCharm, make sure that you are in your project folder, and install the openai package: $ pip install openai Next, you need to create a new Python file in your PyCharm project on the left top corner perform a Right-click on the folder ChatGPTResponse | New | Python File. Name the file app.py and click hit Enter. You should now have a new Python file in your project directory: Fig 2: New Python File To get started, you'll need to import the openai library into your Python file. Also, you'll need to provide your OpenAI API Key. You can obtain an API Key from the OpenAI website by following the steps outlined in the previous sections of this book. Then you'll need to set it as a parameter in your Python code. Once your API Key is set up, you can start interacting with the ChatGPT API. import openaiopenai.api_key = "YOUR_API_KEY" Replace YOUR_API_KEY with the API key you obtained from the OpenAI platform page. Now, you can ask the user a question using the input() function: question = input("What would you like to ask ChatGPT? ") The input() function is used to prompt the user to input a question they would like to ask the ChatGPT API. The function takes a string as an argument, which is displayed to the user when the program is run. In this case, the question string is "What would you Like to ask ChatGPT?". When the user types their question and presses enter, the input() function will return the string that the user typed. This string is then assigned to the variable question. To pass the user question from your Python script to ChatGPT, you will need to use the ChatGPT API Completion function: response = openai.Completion.create(    engine="text-davinci-003",    prompt=question,    max_tokens=1024,    n=1,    stop=None,    temperature=0.8,) The openai.Completion.create() function in the code is used to send a request to the ChatGPT API to generate a completion of the user's input prompt. The engine parameter specifies the ChatGPT engine to use for the request, and in this case, it is set to "text-davinci-003". The prompt parameter specifies the text prompt for the API to complete, which is the user's input question in this case. The max_tokens parameter specifies the maximum number of tokens the response should contain.  The n parameter specifies the number of completions to generate for the prompt. The stop parameter specifies the sequence where the API should stop generating the response. The temperature parameter controls the creativity of the generated response. It ranges from 0 to 1. Higher values will result in more creative but potentially less coherent responses, while lower values will result in more predictable but potentially fewer interesting responses. Later in the book, we will delve into how these parameters impact the responses received from ChatGPT.The function returns a JSON object containing the generated response from the ChatGPT API, which then can be accessed and printed to the console in the next line of code.print(response)In the project pane on the left-hand side of the screen, locate the Python file you want to run. Right-click on the app.py file and select Run app.py from the context menu. You should receive a message in the Run window that asks you to write a question to the ChatGPT.  Fig 3: Run WindowOnce you have entered your question, press the Enter key to submit your request to the ChatGPT API. The response generated by the ChatGPT API model will be displayed in the Run window as a complete JSON object: {   "choices": [    {       "finish_reason": "stop",       "index": 0,       "logprobs": null,       "text": "\n\n1. Start by getting in the water. If you're swimming in a pool, you can enter the water from the side, ………….    }  ],   "created": 1681010983,   "id": "cmpl-73G2JJCyBTfwCdIyZ7v5CTjxMiS6W",   "model": "text-davinci-003",   "object": "text_completion",   "usage": {    "completion_tokens": 415,     "prompt_tokens": 4,     "total_tokens": 419  }} This JSON response produced by the OpenAI API contains information about the response generated by the GPT-3 model. This response consists of the following fields:The choices field contains an array of objects with the generated responses, which in this case only contains one response object. The text field within the response object contains the actual response generated by the GPT-3 model.The finish_reason field indicates the reason why the response was generated; in this case it was because the model reached the stop condition specified in the API request.The created field specifies the Unix timestamp of when the response was created. The id field is a unique identifier for the API request that generated this response.The model field specifies the GPT-3 model that was used to generate the response. The object field specifies the type of object that was returned, which in this case is text_completion.The usage field provides information about the resource usage of the API request. It contains information about the number of tokens used for the completion, the number of tokens in the prompt, and the total number of tokens used.The two most important parameter from the response is the text field, that contains the answer to the question asked to ChatGPT API. This is why most API users would like to access only that parameter from the JSON object. You can easily separate the text from the main body as follows: answer = response["choices"][0]["text"]print(answer)By following this approach, you can guarantee that the variable answer will hold the complete ChatGPT API text response, which you can then print to verify. Keep in mind that ChatGPT responses can significantly differ depending on the input, making each response unique.OpenAI:1. Start by getting in the water. If you're swimming in a pool, you can enter the water from the side, ladder, or diving board. If you are swimming in the ocean or lake, you can enter the water from the shore or a dock.2. Take a deep breath in and then exhale slowly. This will help you relax and prepare for swimming.Summary In this tutorial, you implemented a simple ChatGPT API response, by sending a request to generate a completion of a user's input prompt/question. You have also learned how to set up your API Key and how to prompt the user to input a question, and finally, how to access the generated response from ChatGPT in the form of a JSON object containing information about the response.  About the Author Martin Yanev is an experienced Software Engineer who has worked in the aerospace and medical industries for over 8 years. He specializes in developing and integrating software solutions for air traffic control and chromatography systems. Martin is a well-respected instructor with over 280,000 students worldwide, and he is skilled in using frameworks like Flask, Django, Pytest, and TensorFlow. He is an expert in building, training, and fine-tuning AI systems with the full range of OpenAI APIs. Martin has dual Master's degrees in Aerospace Systems and Software Engineering, which demonstrates his commitment to both practical and theoretical aspects of the industry.https://www.linkedin.com/in/martinyanev/https://www.udemy.com/user/martin-yanev-3/
Read more
  • 0
  • 0
  • 18383
article-image-shortcomings-and-challenges-of-chatgpt-implementation
Matt Zand
04 Jun 2023
5 min read
Save for later

Shortcomings and Challenges of ChatGPT Implementation

Matt Zand
04 Jun 2023
5 min read
IntroductionThe emergence of AI technology, such as ChatGPT and Auto-GPT, has presented a wealth of possibilities for industries across the full spectrum of work. This article introduces ChatGPT and its use cases, followed by analyzing the shortcomings and challenges of ChatGPT integration. Overview of ChatGPT  A chatbot is an artificial intelligence-based computer program designed to simulate conversation with human users through a messaging interface. Chatbots can be a valuable tool to learn about AI and natural language processing, as well as to improve their communication skills. By interacting with a chatbot, beginners can practice their language skills, get feedback, and learn new vocabulary. Additionally, chatbots can provide instant answers to their questions, help them with simple tasks, and guide them through complex processes. For beginners, chatbots can be a useful tool in automating various tasks. Chatbots can also help in providing personalized recommendations, answering frequently asked questions, and offering support.   Technical Use Cases of ChatGPT  ChatGPT can be an excellent resource for experts and technical people in various fields. As a language model, it can provide answers to complex questions, aid in problem-solving, and assist in research. With its vast knowledge database and ability to understand and process natural language, ChatGPT can quickly and efficiently find relevant information and provide accurate answers. This can save time for experts and technical people, allowing them to focus on higher-level tasks that require their expertise. In addition to answering questions and providing information, ChatGPT can also be used by professionals for technical tasks. It can automate processes, such as data analysis, text classification, and language translation, making it an excellent tool for technical people. For example, a data scientist could use ChatGPT to automate the process of analyzing large data sets, while a developer could use it to quickly translate code or troubleshoot technical issues. With its versatility and adaptability, ChatGPT can be a valuable asset to technical people in various fields. Shortcomings and Challenges of ChatGPT  While ChatGPT is a highly advanced and impressive technology, there are still some shortcomings and challenges associated with it.  One of the main challenges is the potential for bias and inaccurate responses based on the data on which it was trained. As with any machine learning model, ChatGPT is only as good as the data it was trained on, so if the training data contains biases or inaccuracies, it may reproduce them in its responses.  Another challenge is the lack of transparency in its decision-making process, which can make it difficult to understand why it generates certain responses.  ChatGPT may struggle with context-dependent conversations and may not always supply accurate or helpful responses to complex or nuanced queries.  Response based on reinforcement learning could potentially be problematic for ChatGPT. Reinforcement learning involves the use of a reward system to incentivize the model to produce certain responses. However, if the feedback supplied is incorrect or biased, it can negatively affect the ChatGPT model's learning and lead to the production of suboptimal responses.  ChatGPT does not provide any confidence score for its response, for example, if an algorithm has multiple functions or sections, it does not provide a confidence score for each section. Hence, it raises questions about the reliability of its responses and how to measure that reliability.  ChatGPT, like any machine learning model, has limitations in its ability to predict the future. While it can generate responses based on patterns it has learned from enormous amounts of data, it cannot anticipate events that have not yet occurred or make predictions beyond its training data. The energy consumption and carbon footprint associated with training and running such a large language model is a concern for its environmental impact.Summary With the ever-growing advancement of AI technology, tools like ChatGPT can assist many professions, from beginners who want to learn a new language, to technical experts who work in the field of data science. Like any other tool, ChatGPT comes with its own shortcomings and challenges. Thus, since ChatGPT is still at its early stage of adoption, it is advisable for the AI community to work on its shortcomings and share its insights and solutions.   About the Author Matt Zand is the director of Coding Bootcamps and High School Technology Services (HSTS) which offers self-paced and live courses related to blockchain, software engineering, and AI.  HSTS is a member of the Linux Foundation and LF AI & Data. He is a leading author of Hands-on Smart Contract Development with Hyperledger Fabric book by O’Reilly Media. He has written many technical articles on blockchain development at sites such as IBM, Alibaba Cloud, Hyperledger, The Linux Foundation, and more. He is also the founder of three tech startups: RealBig, DC Web Makers, and GoReward. Currently, he is the Advisor at Zuma Dating Events. You can connect with him on LinkedIn: https://www.linkedin.com/in/matt-zand-64047871
Read more
  • 0
  • 0
  • 6274

article-image-prompt-engineering-principles
Martin Yanev
04 Jun 2023
5 min read
Save for later

Prompt Engineering Principles

Martin Yanev
04 Jun 2023
5 min read
Prompt Engineering and design play a very vital role in controlling the output of the model. Here are some best practices you can use to improve your prompts, as well as some practices you should avoid:Clarity: Use simple sentences and instructions that can easily be understood by ChatGPT. Conciseness: Favor short prompts and short sentences. This can be achieved by chunking your instructions into smaller sentences with clear intentions.Focus: Keep the focus of the prompt on a well-defined topic so that you don’t risk your output being too generic.Consistency: Maintain a consistent tone and language during the conversation so that you can ensure a coherent conversation.“Acting as…”: The hack of letting ChatGPT act as someone or something has proven to be extremely powerful. You can shorten the context you have to provide to the model by simply asking him to act like the person or system you want information from. We’ve already seen the interview-candidate example, where ChatGPT acted as an interviewer for a data scientist position. A very interesting prompt is that of asking ChatGPT to act as a console. Here is an example of it: Figure 1 – Example of ChatGPT acting as a Python console Note that the console, as it would be if it were real, is also reporting the error I made for the cycle, indicating that I was missing the brackets.There is a continuously growing list of Act as prompts you can try in the following GitHub repository: https://github.com/f/awesome-chatgpt-prompts.Considering the few-shot learning capabilities, there are some good tips for leveraging this feature in prompt designing. An ideal conversation is as follows: On the other hand, there are some things you should avoid while designing your prompt:Start with a concise, clear, and focused prompt. This will help you have an overview of the topic you want to discuss, as well as provide food for thought and potential expansion of particular elements. Here’s an exampleFigure 2 – Example of a clear and focused prompt to initiate a conversation with ChatGPTOnce you have identified the relevant elements in the discussion, you can ask ChatGPT to elaborate on them with much more focusFigure 3 – Example of a deep-dive follow-up question in a ChatGPT Sometimes, it might be useful to remember the model and the context in which you are inquiring, especially if the question might apply to various domainsFigure 4 – Example of a reminder about the context in a conversation with ChatGPTFinally, always in mind the limitations we mentioned in previous chapters. ChatGPT may provide partial or incorrect information, so it is always a good practice to double-check. One nice tip you could try is asking the model to provide documentation about its responses so that you can easily find proof of themFigure 5 – Example of ChatGPT providing documentation supporting its previous responses On the other hand, there are some things you should avoid while designing your prompt: Information overload: Avoid providing too much information to ChatGPT, since it could reduce the accuracy of the response.Open-ended questions: Avoid asking ChatGPT vague, open-ended questions. Prompts such as What can you tell me about the world? or Can you help me with my exam? are far too generic and will result in ChatGPT generating vague, useless, and sometimes hallucinated responses.Lack of constraints: If you are expecting an output with a specific structure, don’t forget to specify that to ChatGPT! If you think about the earlier example of ChatGPT acting as an interviewer, you can see how strict I was in specifying not to generate questions all at once. It took several tries before getting to the result since ChatGPT is thought to generate a continuous flow of text.Furthermore, as a general consideration, we still must remember that the knowledge base of ChatGPT is limited to 2021, so we should avoid asking questions about facts that occurred after that date. You can still provide context; however, all the responses will be biased toward the knowledge base before 2021. SummaryIn this article, we get to learn some strong principles that can help you learn how to prompt effectively.  We cover the importance of a good prompt, and all the important Do’s and Don'ts while designing a good prompt with a practical example. About the Author Valentina Alto graduated in 2021 in Data Science. Since 2020 she has been working in Microsoft as Azure Solution Specialist and, since 2022, she focused on Data&AI workloads within the Manufacturing and Pharmaceutical industry. She has been working on customers’ projects closely with system integrators to deploy cloud architecture with a focus on datalake house and DWH, data integration and engineering, IoT and real-time analytics, Azure Machine Learning, Azure cognitive services (including Azure OpenAI Service), and PowerBI for dashboarding. She holds a BSc in Finance and an MSc degree in Data Science from Bocconi University, Milan, Italy. Since her academic journey, she has been writing Tech articles about Statistics, Machine Learning, Deep Learning, and AI in various publications. She has also written a book about the fundamentals of Machine Learning with Python.LinkedInMedium
Read more
  • 0
  • 0
  • 9054

article-image-create-a-personal-portfolio-website-with-javascript-and-chatgpt
Maaike van Putten
04 Jun 2023
9 min read
Save for later

Create a Personal Portfolio Website with JavaScript and ChatGPT

Maaike van Putten
04 Jun 2023
9 min read
This article is the first part of a series of articles, please refer to Part 2  for learning how to add a Chatbot to the portfolio website you create in this article!Creating a personal portfolio is a great way for showcasing your skills and accomplishments as a developer or designer. Does that sound like a lot of work? Well… it doesn’t have to be. We can use ChatGPT to generate code snippets and obtain a lot of guidance throughout the process. This way you can build an impressive portfolio website with minimal effort.Here’s what you can do in around 10 prompts: Fig 1: Homepage Fig 2: Portfolio PageFig 3: Contact Page Not bad, right? And it even contains some features: The search functionality works and filters projects based on what you are typing.The testimonials and projects are not hard-coded, but dynamically populated with JavaScript (but not connected to a backend with a database, so for the purpose of this article, they are hard-coded there).Of course, this personal portfolio would need more content. And you could definitely use ChatGPT to generate a bit more content and descriptions for it. You should be adding in some professional pictures and images to complete your portfolio. However, this is a project that you can do in half a day to a day using ChatGPT. The prompt magic The prompts used to create the personal portfolio follow a few best practices that I’ll discuss later. In the overview below, asking to continue after cutting off a response is not included. If you’d like to see all the responses and the versions of the personal portfolio after each step, you can check out this GitHub repo: https://github.com/BrightBoost/brightboost-portfolio-chatgpt Here is the first prompt:I'm making a portfolio site, using HTML/CSS/JS. Can you help me write the initial framework for it?  I need a home page, in which I will introduce me, my passions, aspirations and study background. I also need a call-to-action directing visitors to explore my work.Then I need a portfolio page, in which I showcase my best projects. This will include case studies, and testimonials highlighting my contributions and accomplishments.Finally I need a contact page, which is a minimalist form and social media links in order to facilitate professional connections. And the second:That seems to be close to what I want. However, could you split these into 3 files? One for each page.The third, as you can see, a lot of the heavy lifting in terms of content is done in the prompt here:Can you populate the pages with the following information?Name: Olivia MartinezStudy: Olivia recently graduated from the University of California, Berkeley with a Bachelor's degree in Computer Science.Aspirations: Olivia aspires to become a full-stack software engineer at a tech startup that focuses on environmental sustainability. She hopes to contribute her skills to develop innovative solutions for pressing environmental issues.Hobbies: In her free time, Olivia enjoys hiking, painting, and exploring the latest advancements in machine learning.Example Open Source Projects:- GreenRoute: A web application that optimizes travel routes based on carbon emissions.- EcoClicker: A browser extension that encourages users to reduce their digital carbon footprint.Additional Personal Details: Olivia has been an active volunteer at her local recycling center, where she has helped develop a digital platform to streamline recycling processes. This is what it looked like after this prompt:Fig 4: Homepage after initial promptsFig 5: Portfolio page after promptFig 6: Contact Page after promptThe fourth prompt was quite a challenge and it required going back and forward a bit and testing it until it was good. It was tempting to just modify it, but ChatGPT was supposed to create it here and it did eventually:Can you help me modify the following snippet? ```html      <h2>Portfolio</h2>      <div class="project">        <h3>GreenRoute</h3>        <p>A web application that optimizes travel routes based            on carbon emissions.</p>        <a href="#" class="project-link">View Case Study</a>        <div class="testimonials">          <p>Testimonial 1</p>          <p>Testimonial 2</p>        </div>      </div>       <div class="project">        <h3>EcoClicker</h3>        <p>A browser extension that encourages users to reduce            their digital carbon footprint.</p>        <a href="#" class="project-link">View Case Study</a>        <div class="testimonials">          <p>Testimonial 1</p>          <p>Testimonial 2</p>        </div>      </div>    ``` I'm not satisfied with the look. Could you make the following changes: - Each project is displayed in a card.- The project link looks like a button, in the bottom right.- The title is underlined, and a bit larger.- The page shows 2 columns of cards. Fig 7: Home page after refined promptingAnd here’s the fifth: I need to make sure that footer is always at the bottom of the page, can you provide a CSS snippet to make that work?This also needed second attempt because it wasn’t working. Don’t just say that it doesn’t work, but be specific:It doesn't seem to work. The page only uses about 50% of the screen, so the footer is still in the middle. After this, it looks like: Fig 8: Homepage after footer promptsThis is where things really got cool, but this needed a few tweaks in terms of output. Here was the first prompt to add JavaScript: I'd like to make the portfolio a bit more extendable. Can you write some JavaScript code that generates the portfolio page using an array of objects? For now just put the content directly in code. I forgot a few classes, so let’s prompt again: This works, but you've excluded the classes used in the CSS. As a reminder, this is how a single item should look:** code of the prompt omitted And after this it was good: It seems the 2 column layout is gone. I think this:```html<section id="portfolio"><div class="container" id="portfolio-container"></div></section>```Should contain an element with the class `project-grid` somewhere, which should create a grid. Can you modify the snippet? The last part was on the search bar, which required this prompt:I'd like to add a search bar to the portfolio page. It must search for the text in the title and body. I only want to look for the exact text. After each character it should update the list, filtering out any project that does not match the search text. Then there should be a button to clear the search bar, and show all projects. Can you add this to the JavaScript file? And that’s it! Of course, there are many ways to do this, but this is one way of how you can use ChatGPT to create a personal portfolio. Let’s see some best practices for your ChatGPT prompts, to help you with using it to create your personal portfolio.Best practices for ChatGPT prompts There are some best practices I figured out when working with ChatGPT. Let’s go over them before seeing the prompts used for the personal portfolio.Be specific and clear: Make sure your prompt leaves little room for interpretation. For example, the prompt:Help me with a grid layout.Is not going to help you as much as:For this piece of HTML containing bootstrap cards provide a CSS snippet for a responsive 3-column grid layout with a 20px gap between columns: ** insert your HTML snippet here **Include relevant context and background information: Give the AI enough information to understand the problem or task and help you to its best ability. Don’t ask:How do I convert a date string to a Date object?But ask:  I have a JSON object with date and value properties. How do I convert the date property to a JavaScript Date object?Ask one question at a time: Keep your prompts focused and avoid asking multiple questions in one prompt.Make sure ChatGPT completes its answer before asking the next question: Sometimes it cuts off the result. You can ask it to continue and it will. That’s harder when you’re further down the line.Test the result after every step: Related to the previous tip, but make sure to test the result after every step. This way you can provide feedback on the outcome and it can easily adjust still. Step? Yes! Break down big projects into smaller tasks: Divide your project into manageable steps, and ask the AI to complete each task separately.Bonus tip: You can even ask ChatGPT for help on how to break your project into smaller tasks and make these tasks very detailed. Then go ahead and ask it to do one task at a time.The good news is these tips are actually great interaction tips with humans as well! I bet you’d like to see some of the prompts used to create the personal portfolio, so let’s dive in. Author BioMaaike van Putten is an experienced software developer and Pluralsight, LinkedIn Learning, Udemy, and Bright Boost instructor. She has a passion for software development and helping others get to the next level in their career.You can follow Maaike on:LinkedInTraining Courses
Read more
  • 0
  • 0
  • 9120
article-image-using-chatgpt-with-text-to-speech
Denis Rothman
04 Jun 2023
7 min read
Save for later

Using ChatGPT with Text to Speech

Denis Rothman
04 Jun 2023
7 min read
This article provides a quick guide to using the OpenAI API to jump-start ChatGPT. The guide includes instructions on how to use a microphone to speak to ChatGPT and how to create a ChatGPT request with variables. Additionally, the article explains how to use Google gTTS, a text-to-speech tool, to listen to ChatGPT's response. By following these steps, you can have a more interactive experience with ChatGPT and make use of its advanced natural language processing capabilities. We’re using the GPT-3.5-Turbo architecture in this example. We are also running the examples within Google Colab, but they should be applicable to other environments. In this article, we’ll cover: Installing OpenAI, your API key, and Google gTTS for Text-to-SpeechGenerating content with ChatGPTSpeech-to-text ChatGPT's responseTranscribing with WhisperTo understand GPT-3 Transformers in detail, read Transformers for NLP, 2nd Edition 1. Installing OpenAI, gTTS, and your API Key There are a few libraries that we’ll need to install into Colab for this project. We’ll install them as required, starting with OpenAI. Installing and Importing OpenAI To start using OpenAI's APIs and tools, we'll need to install the OpenAI Python package and import it into your project. To do this, you can use pip, a package manager for Python. First, make sure you have pip installed on your system. !pip install --upgrade pipNext, run the following script in your notebook to install the OpenAI package. It should come pre-installed in Colab:#Importing openaitry:import openaiexcept:!pip install openaiimport openai Installing gTTS Next, install Google gTTS a Python library that provides an easy-to-use interface for text-to-speech synthesis using the Google Text-to-Speech API:#Importing gTTStry:from gtts import gTTSexcept:!pip install gTTS   from gtts import gTTS API Key Finally, import your API key. Rather than enter your key directly into your notebook, I recommend keeping it in a local file and importing it from your script. You will need to provide the correct path and filename in the code below.from google.colab import drivedrive.mount('/content/drive')f = open("drive/MyDrive/files/api_key.txt", "r")API_KEY=f.readline()f.close()#The OpenAI Keyimport osos.environ['OPENAI_API_KEY'] =API_KEYopenai.api_key = os.getenv("OPENAI_API_KEY") 2. Generating Content Let’s look at how to pass prompts into the OpenAI API to generate responses. Speech to text When it comes to speech recognition, Windows provides built-in speech-to-text functionality. However, third-party speech-to-text modules are also available, offering features such as multiple language support, speaker identification, and audio transcription. For simple speech-to-text, this notebook uses the built-in functionality in Windows. Press Windows key + H to bring up the Windows speech interface. You can read the documentation for more information.Note: For this notebook, press Enter when you have finished asking for a request in Colab. You could also adapt the function in your application with a timed input function that automatically sends a request after a certain amount of time has elapsed. Preparing the Prompt Note: you can create variables for each part of the OpenAI messages object. This object contains all the information needed to generate a response from ChatGPT, including the text prompt, the model ID, and the API key. By creating variables for each part of the object, you can make it easier to generate requests and responses programmatically. For example, you could create a prompt variable that contains the text prompt for generating a response. You could also create variables for the model ID and API key, making it easier to switch between different OpenAI models or accounts as needed.For more on implementing each part of the messages object, take a look at: Prompt_Engineering_as_an_alternative_to_fine_tuning.ipynb.Here’s the code for accepting the prompt and passing the request to OpenAI:#Speech to text. Use OS speech-to-text app. For example,   Windows: press Windows Key + H def prepare_message():#enter the request with a microphone or type it if you wish  # example: "Where is Tahiti located?"  print("Enter a request and press ENTER:")  uinput = input("")  #preparing the prompt for OpenAI   role="user"  #prompt="Where is Tahiti located?" #maintenance or if you do not want to use a microphone  line = {"role": role, "content": uinput}  #creating the message   assert1={"role": "system", "content": "You are a helpful assistant."}  assert2={"role": "assistant", "content": "Geography is an important topic if you are going on a once in a lifetime trip."}  assert3=line  iprompt = []  iprompt.append(assert1)  iprompt.append(assert2)  iprompt.append(assert3)  return iprompt#run the cell to start/continue a dialogiprompt=prepare_message() #preparing the messages for ChatGPTresponse=openai.ChatCompletion.create(model="gpt-3.5-turbo",messages=iprompt) #ChatGPT dialogtext=response["choices"][0]["message"]["content"] #response in JSONprint("ChatGPT response:",text) Here's a sample of the output: Enter a request and press ENTER:Where is Tahiti locatedChatGPT response: Tahiti is located in the South Pacific Ocean, specifically in French Polynesia. It is part of a group of islands called the Society Islands and is located approximately 4,000 kilometers (2,500 miles) south of Hawaii and 7,850 kilometers (4,880 miles) east of Australia. 3. Speech-to-text the response GTTS and IPython Once you've generated a response from ChatGPT using the OpenAI package, the next step is to convert the text into speech using gTTS (Google Text-to-Speech) and play it back using  IPython audio.from gtts import gTTSfrom IPython.display import Audiotts = gTTS(text)tts.save('1.wav')sound_file = '1.wav'Audio(sound_file, autoplay=True) 4. Transcribing with Whisper If your project requires the transcription of audio files, you can use OpenAI’s Whisper.First, we’ll install the ffmpeg audio processing library. ffmpeg is a popular open-source software suite for handling multimedia data, including audio and video files:!pip install ffmpegNext, we’ll install Whisper:!pip install git+https://github.com/openai/whisper.git With that done, we can use a simple command to transcribe the WAV file and store it as a JSON file with the same name:!whisper  1.wavYou’ll see Whisper transcribe the file in chunks:[00:00.000 --> 00:06.360]  Tahiti is located in the South Pacific Ocean, specifically in the archipelago of society[00:06.360 --> 00:09.800]  islands and is part of French Polynesia.[00:09.800 --> 00:22.360]  It is approximately 4,000 miles, 6,400 km, south of Hawaii and 5,700 miles, 9,200 km,[00:22.360 --> 00:24.640]  west of Santiago, Chile.Once that’s done, we can read the JSON file and display the text object:import json with open('1.json') as f:     data = json.load(f) text = data['text'] print(text)This gives the following output:Tahiti is located in the South Pacific Ocean, specifically in the archipelago of society islands and is part of French Polynesia. It is approximately 4,000 miles, 6,400 km, south of Hawaii and 5,700 miles, 9,200 km, west of Santiago, Chile. By using Whisper in combination with ChatGPT and gTTS, you can create a fully featured AI-powered application that enables users to interact with your system using natural language inputs and receive audio responses. This might be useful for applications that involve transcribing meetings, conferences, or other audio files. About the Author Denis Rothman graduated from Sorbonne University and Paris-Diderot University, designing one of the very first word2matrix patented embedding and patented AI conversational agents. He began his career authoring one of the first AI cognitive natural language processing (NLP) chatbots applied as an automated language teacher for Moet et Chandon and other companies. He authored an AI resource optimizer for IBM and apparel producers. He then authored an advanced planning and scheduling (APS) solution used worldwide.You can follow Denis on LinkedIn:  https://www.linkedin.com/in/denis-rothman-0b034043/Copyright 2023 Denis Rothman, MIT License
Read more
  • 0
  • 0
  • 18392

article-image-generating-data-descriptions-with-openai-chatgpt
Greg Beaumont
02 Jun 2023
5 min read
Save for later

Generating Data Descriptions with OpenAI ChatGPT

Greg Beaumont
02 Jun 2023
5 min read
This article is an excerpt from the book, Machine Learning with Microsoft Power BI, by Greg Beaumont. This book is designed for data scientists and BI professionals seeking to improve their existing solutions and workloads using AI.Data description generation plays a vital role in understanding complex datasets, but it can be a time-consuming task. Enter ChatGPT, an advanced AI language model developed by OpenAI. Trained on extensive text data, ChatGPT demonstrates impressive capabilities in understanding and generating human-like responses. In this article, we explore how ChatGPT can revolutionize data analysis by expediting the creation of accurate and coherent data descriptions. We delve into its training process, architecture, and potential applications in fields like research, journalism, and business analytics. While acknowledging limitations, we unveil the transformative potential of ChatGPT for data interpretation and knowledge dissemination. Our first step will be to identify a suitable use case for leveraging the power of GPT models to generate descriptions of elements of FAA Wildlife Strike data. Our objective is to unlock the potential of external data by creating prompts for GPT models that can provide detailed information and insights about the data we are working with. Through this use case, we will explore the value that GPT models can bring to the table when it comes to data analysis and interpretation.For example, a description of the FAA Wildlife Strike Database by ChatGPT might look like this: Figure 1 – OpenAI ChatGPT description of FAA Wildlife Strike Database Within your solution using the FAA Wildlife Strike database, you have data that could be tied to external data using the GPT models. A few examples include additional information about:AirportsFAA RegionsFlight OperatorsAircraftAircraft EnginesAnimal SpeciesTime of Year When the scoring process for a large number of separate rows in a dataset is automated, we can use a GPT model to generate descriptive text for each individual row. It is worth noting that ChatGPT's approach varies from this, as it operates as a chatbot that calls upon different GPT models and integrates past conversations into future answers. Despite the differences in how GPT models will be used in the solution, ChatGPT can still serve as a valuable tool for testing various use cases.When using GPT models, the natural language prompts that are used to ask questions and give instructions will impact the context of the generated text. Prompt engineering is a topic that has surged in popularity for OpenAI and LLMs. The following prompts will provide different answers when using “dogs” as a topic for a GPT query:Tell me about dogs:From the perspective of an evolutionary biologist, tell me about dogs:Tell me the history of dogs:At a third-grade level, tell me about dogs:When planning for your use of OpenAI on large volumes of data, you should test and evaluate your prompt engineering strategy. For this book, the use cases will be kept simple since the goal is to teach tool integration with Power BI. Prompt engineering expertise will probably be the topic of many books and blogs this year. You can test different requests for a description of an FAA Region in the data: Figure 2 – Testing the utility of describing an FAA Region using OpenAI ChatGPT You can also combine different data elements for a more detailed description. The following example combines data fields with a question to ask “Tell me about the Species in State in Month”: Figure 3 – Using ChatGPT to test a combination of data about Species, State, and Month There are many different options to consider. To combine a few fields of data and provide useful context about the data, you decide to plan a use case for describing the aircraft and operator. An example can be tested with the following formula in OpenAI ChatGPT such as “Tell me about the airplane model Aircraft operated by the Operator in three sentences." Here is an example using data from a single row of the FAA Wildlife Strike database: Figure 4 – Information about an airplane in the fleet of an operator as described by OpenAI ChatGPT From a prompt engineering perspective, asking this question for multiple reports in the FAA Wildlife Strike database would require running the following natural language query on each row of data (column names are depicted with brackets): Tell me about the airplane model [Aircraft] operated by [Operator] in three sentences:SummaryThis article explores how ChatGPT expedites the generation of accurate and coherent data descriptions. Unveiling its training process, architecture, and applications in research, journalism, and business analytics, we showcase how ChatGPT revolutionizes data interpretation and knowledge dissemination. Acknowledging limitations, we highlight the transformative power of this AI technology in enhancing data analysis and decision-making. Author BioGreg Beaumont is a Data Architect at Microsoft; Greg is an expert in solving complex problems and creating value for customers. With a focus on the healthcare industry, Greg works closely with customers to plan enterprise analytics strategies, evaluate new tools and products, conduct training sessions and hackathons, and architect solutions that improve the quality of care and reduce costs. With years of experience in data architecture and a passion for innovation, Greg has a unique ability to identify and solve complex challenges. He is a trusted advisor to his customers and is always seeking new ways to drive progress and help organizations thrive. For more than 15 years, Greg has worked with healthcare customers who strive to improve patient outcomes and find opportunities for efficiencies. He is a veteran of the Microsoft data speaker network and has worked with hundreds of customers on their data management and analytics strategies.You can follow Greg on his LinkedIn 
Read more
  • 0
  • 0
  • 8833
Modal Close icon
Modal Close icon