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 run Python in android phone?

Hello Everyone,               Now days Our smartphone became so powerful that we can run any thing on it. Some of the people can't afford laptop or pc for programming. They want to program in their smartphones but they can't find app which is best for running program. Today I am telling you app which runs python beautifully.. App -   https://play.google.com/store/apps/details?id=ru.iiec.pydroid3 You can download this from playstore and this run smoothly on you mobile Device. Here is an example of this--  Subscribe to my channel and I'll upload more practice video of Python. Follow me on Instagram -  https://instagram.com/praphull_verma12?igshid=6otkb0qmkr4q

How to use python from Android devices? First program|||| Hello world! Program in python

Hello guys! If you have seen my previous blog "how to run python on Android devices" Link -  https://praphullverma.blogspot.com/2020/06/how-to-run-python-in-android-phone.html?m=1 Then You know how to get started in programming with smartphone! In this blog you are going to make your first program in Python|| The code you are going to enter is - print('Hello, World') For next blog subscribe to my blogger account I'll back soon..

How to create a 3d Rubic's cube in python using tkinter

 In this blog post, I will show you how to create a 3d rubic's cube in python using tkinter, a standard GUI library for python. Tkinter provides various widgets and methods to create graphical user interfaces. A 3d rubic's cube is a popular puzzle game that consists of a cube with six faces, each divided into nine smaller squares of different colors. The goal is to rotate the faces of the cube until each face has only one color. To create a 3d rubic's cube in python using tkinter, we will need to use the following steps: 1. Import the tkinter module and create a root window. 2. Create a canvas widget to draw the cube on. 3. Define the coordinates and colors of the vertices and faces of the cube. 4. Define a function to draw the cube on the canvas using polygons. 5. Define a function to rotate the cube along the x, y or z axis using matrix multiplication. 6. Define a function to handle keyboard events and call the rotation function accordingly. 7. Bind the keyboard events to...