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()

Creating a web app In Python

Python is a versatile and powerful programming language that can be used for various applications, such as data analysis, machine learning, web development and more. In this blog post, we will focus on how to create a web app in Python using some popular frameworks and tools. A web app is a software application that runs on a web server and can be accessed by users through a web browser. A web app typically consists of two main components: the front-end and the back-end. The front-end is the part of the app that the user interacts with, such as the user interface, the layout, the graphics and the functionality. The back-end is the part of the app that handles the logic, the data processing, the database and the communication with other services. To create a web app in Python, we need to choose a framework that provides us with the tools and libraries to build both the front-end and the back-end of our app. There are many frameworks available for Python web development, such as Django, ...