Skip to main content

How to use ChatGPT in Whatsapp

ChatGPT is a powerful natural language generation model that can create realistic and engaging text from a given prompt. It can be used for various purposes, such as writing stories, jokes, lyrics, code, and more. But did you know that you can also use chatGPT to spice up your whatsapp conversations?


In this blog post, I will show you how you can make chatGPT work in your whatsapp using a simple Python script. You will need some basic programming skills and a few tools to get started. Here are the steps:


1. Install the required libraries. You will need to install the transformers library from Hugging Face, which provides an easy way to access chatGPT and other pre-trained models. You will also need to install selenium, which is a tool for automating web browsers. You can use pip to install them:


pip install transformers

pip install selenium


2. Load the chatGPT model and tokenizer. You can use the transformers library to load the chatGPT model and tokenizer with a few lines of code. You can choose from different versions of chatGPT, such as small, medium, large, or extra large. For this example, I will use the medium one:


from transformers import AutoModelForCausalLM, AutoTokenizer

model = AutoModelForCausalLM.from_pretrained("microsoft/DialoGPT-medium")

tokenizer = AutoTokenizer.from_pretrained("microsoft/DialoGPT-medium")


3. Connect to whatsapp web. You will need to use selenium to open a web browser and navigate to whatsapp web. You will also need to scan the QR code with your phone to log in. You can use the following code to do that:


from selenium import webdriver

driver = webdriver.Chrome() # you can use other browsers as well

driver.get("https://web.whatsapp.com/")

input("Scan the QR code and press enter")


4. Select a chat and generate a response. You will need to use selenium to find the chat element by its name and click on it. Then you will need to get the last message from the chat and pass it to the chatGPT model as a prompt. The model will generate a response and you will need to send it back to the chat using selenium. You can use the following code to do that:


import random

chat_name = "Your friend's name" # change this to the name of your chat

chat = driver.find_element_by_xpath(f"//span[@title='{chat_name}']")

chat.click()

last_message = driver.find_elements_by_class_name("_1RAno")[-1].text

prompt = tokenizer.encode(last_message + tokenizer.eos_token, return_tensors="pt")

response = model.generate(prompt, max_length=50, do_sample=True)

response = tokenizer.decode(response[0], skip_special_tokens=True)

message_box = driver.find_element_by_class_name("_13mgZ")

message_box.send_keys(response)

send_button = driver.find_element_by_class_name("_4sWnG")

send_button.click()


5. Repeat step 4 as many times as you want. You can use a loop or a function to repeat step 4 for different chats or messages. You can also modify the parameters of the model.generate() function to change the length, randomness, or temperature of the response.


That's it! You have successfully made chatGPT work in your whatsapp. Now you can have fun and creative conversations with your friends using chatGPT. Just be careful not to reveal your secret or offend anyone with your generated messages. Enjoy!

Comments

Popular posts from this blog

How to create a login page in Tkinter [PYTHON] {VS CODE}

if You want to create a login page in tkinter here's the  tutorial   Insure that you have installed Tkinter Module VIDEO: Source code: from tkinter import * root = Tk() root.geometry( "700x455" ) def k():     Label(text= "Login UnSuccesful" ,font= "timesnewroman 12 bold" ).grid(row= 12 ,column= 3 ) i = Label(text= "User ID" ,font= "comicsansm 15 bold" ).grid(row= 2 ,column= 2 ) j = Label(text= "Password" ,font= "comicsansm 15 bold" ).grid(row= 3 ,column= 2 ) Label(text= "LOGIN SETUP" ,font= "callebri 13 bold" ,padx= 540 ).grid(row= 0 ,column= 3 ,columnspan= 9 ) user = Entry(textvariable=i).grid(row= 2 ,column= 3 ) passwd = Entry(textvariable=j).grid(row= 3 ,column= 3 ) Button(text= "SUBMIT" ,command=k,font= "helvatica 10 bold" ).grid(row = 6 , column= 3 ) root.mainloop()

How to declare a variable in python? Variable in python|

Welcome back to the course of Python. In previous blog we knew how to print anything in python. In this blog we are going to talk about Variable  in python. What is variable in python?  Variables are like storehouse of the data we want to use for our program. When we add some value in a variable python saves it and it can be use in program. Now the question is how we store anything in variable? The answer is very simple firts we call a variable name and then give some value to them. for example a = "Python" b = 120 And so on Python have 5 types of variable. String Number List Tuple Dictionary But for now we are just going to focus on Numbers and string. Here's a video how to declare a variable in python. Follow me for full course and follow me on Instagram and ask questions  Instagram -  https://instagram.com/praphull_verma12?igshid=1uyrn4ksip94l Give your suggestions in comment box.........