Instagram Hashtag Generator in Python

NeuralNine · Intermediate ·💻 AI-Assisted Coding ·4y ago

Key Takeaways

The video demonstrates building an Instagram hashtag generator using Python with a GUI created by PyQt5, showcasing a practical application of AI coding skills.

Full Transcript

[Music] what is going on guys welcome back in this video we're going to build an instagram hashtag generator in python now actually this is just going to be a graphical user interface tool that you can use for all sorts of social networks so twitter facebook whatever uh let me show you what this is going to look like in the end i actually used this for myself i wrote it for myself for my instagram account uh the basic idea is the following we have this graphical user interface it's also responsive we're going to talk about this uh today as well um and i have a bunch of hashtags here on the left and let's say now i produce a new instagram post about programming data science and linux in some way now what i want to do is i want to use a couple of hashtags it's always similar hashtags but i want to be able to choose this without writing them myself every time so what i do is i select here these hashtags for example then i also want to have machine learning data science ai and all these linux hashtags now what i do is i press this button those are the chosen hashtags and of course if i want to remove ai for example i press this button and now what i click is i click on copy to clipboard and if i now go to instagram let's say my note notepad now is instagram if i go to instagram i can just go ahead and say control v there you go and we have all these hashtags here generated and of course i can also go ahead and save this so i can click on save hashtags i can go to the desktop and i can say my tags dot text i can close the uh i can close the program i can run it again and i can load the hashtags like that so this is what we're going to build today we're going to use pyqt5 to build it and we're going to get started with the qt designer if this is the first pyqt5 tutorial that you're watching i recommend you watch my beginner course on pi qt5 gui development because today we're going to talk a little bit about more advanced stuff like tree views list views and so on and also layouts now i'm going to have some problems here with the ui i guess i always have some problems i think what we need to do first is we need to add a vertical layout we want to keep this responsive so we're going to add a vertical layout we're going to right click and we're going to say layout layout vertically and uh how did i do this i think i added another vertical layout or actually maybe a horizontal layout is enough and then we're going to add a button at the bottom there you go this works and here we have a horizontal layout so in that horizontal layout we want to have two vertical layouts like that and now what i want to do is i want to add a button here i want to add a button here i want to add a label here a label here and now i want to add a list view and a tree view so the tree view is going to be here and the list view is going to be here come on there you go actually it worked fine okay so in a menu we're going to have file we're going to have a load and we're going to have um actually save and load okay now i messed up the names here action save and action load without a two there you go then we're going to say all hashtags selected hashtags like that here we're going to have it like that here we're going to have it like that and here we're going to say copy to clipboard now we need to change the font sizes we're going to change everything to 14 i guess there you go here's well can i select multiple i can and of course here we're going to also do the same thing for the list and tree view but here we're going to go with 12. and one thing that we want to do is we want to make sure that we can select multiple items not only one item so we're going to click on both of them using control we're going to scroll down here to abstract item view and we're going to go to selection mode and from single selection we're going to change to extended selection let's save this and go to the desktop hashtag gui dot ui um and now we want to do is we want to drag this into our development directory and then we're going to create a new main.py file here so main.py and all we need to do now is we need to do the usual stuff by the way if you don't have pi qd5 installed you say pip install pi qt5 like that and then we say from pi q t 5 dot q t widgets import everything then from pi q t 5 dot qt gui import everything uh or actually let's just import q font because we don't need anything else from pi qt5 import uic this is what we're going to use to load the graphical user interface and then from pi qt5 dot qt itself we're going to import the q standard item model um q standard item model and a queue standard item the idea behind those two things is that in list views and tree views we cannot just add elements as strings or objects we need to create an item model and then we need to add items to that item model because and then we need to set to that preview the item model and so on we're going to see that in a second now let's go ahead and create the or before we do that we need to also import json and we need to import pickle why need why do we need to import json we need to import json because we're going to have the hashtags in adjacent format so if i go here to my uh prepared project i'm going to copy this um this is the file that we're going to use now this is one file that you can use you can use whatever you want the basic structures we have uh curly brackets we have tags so programming here for example is a key and then a list of strings that are the hashtags here we have memes humor list machine learning list and so on so for those of you who are completely um completely for for those of you who for whom it's too difficult to understand json we're going to just say test on json and the basic ideas we have here the dictionary with category colon list hashtag one hashtag two and so on then category two another list and so on this is how you create your hashtag json file this is what we're going to load into the script and pixel is going to be just for serialization so let's create a my gui class we're going to extend from main window we're going to have a basic constructor we're going to call super my gui self dot init and i'm going to say uic.load ui from the ui file from hashtag gui dot ui self and then self.show i guess uh yeah the rest we're going to do after that down at the end we're going to say app equals q application with empty list window is going to be my gui and then app dot exec underscore what you see by the way there is getup copilot don't be confused um and now this is the graphical user interface you can see it works um yeah no functionality yet but this is the graphical user interface what we want to do first is want to set up title we want to say self dot set window title neural nine hashtag generator or manager whatever you want to call it and then we want to initialize a dictionary with the json uh content so we want to say self dot hashtag dict is going to be jason load open not hashtag dick.json but hashtags.json and then we want to call a function called self init tree view which we need to write of course because we don't have it so def in a tree view and what want to do is want to get from this dictionary all the content if we want to render it into the tree view shouldn't be too complicated we essentially say self.treeview dot set uh we need to set the header to unvisible by the way we can access treeview because we have it in the qt designer so if i click on this you can see here the object name is this is actually a list view right now this is a tree view this is a list view and these object names can be used in python so self dot uh dot tree view is going to be set header to hidden true just so that we don't see any root elements that are useless and then we're going to define the model so self.tree model is going to be a new q standard item model and then self.treeview is going to get that model uh as its model so set model to self.3 and then we're going to say rootnode of that thing is going to be self.treemodel.invisiblerootitem and now we're going to fill that up with the content so we're going to see for the category that we have in self hashtag dig.keys we're going to say the category item remember we need to turn everything into an item so the category item is going to be a q standard item with category uh and then we're going to say for hashtag in self hashtag the category we're going to create a hashtag or actually we don't need to create an extra object for that category item dot append row we're going to append to that a new q standard item from hashtag let me just close this here and then we're going to say root note appendro category item that's it and after that last but not least self.treeview is going to be expanded so expand all by default we don't want to we don't want it to be collapsed so if i run this now we should already see that there is some content in the tree view there you go if we don't use can uh expand all in the end we're going to have it like that we don't want to have it like that all right so this works we're now going to add we're now going to connect the ui elements so we're going to say what happened there we're going to say self.selected is going to be an empty list by default and then we're going to work with the buttons now we need to see what the buttons are named push push button two is this one push button three is this one and push button is this one okay so self push button to dot clicked dot connect to self dot select or maybe choose select it then push button three self dot remove selected and push button one is going to be self dot copy to clipboard this should work platform independently by the way because it's done by qt or via qt and then we're going to say action load dot triggered dot connect self dot load hashtags an action safe is going to be self dot safe hashtags all right that should be it all we need to do now is we need to implement all these functions so i'm going to say def and we're going to start with um choose selected what we want to do here is this is very important we don't want to select everything we don't want to choose everything we want to choose only the hashtags not the categories so we're going to do is we're going to say if the length of the uh self.treeview.selected indexes if the length of that is not zero so if there is a selection we're going to check for a couple of other things we're going to say for index in [Music] these selected indexes we're going to see if that index has a valid parent so if it's a hashtag because the hashtags have as the parent the category the categories don't have a parent so if the parent is valid we're going to say if the index data is not already part of selected then we're going to add it so then we're going to say self dot selected dot append index data and then self dot did we define a list model by the way we didn't define a list model right self dot list model equals q standard item model self dot list view dot set model self list model and then we're going to say self list model dot append row q standard item oh q standard item index data what's happening here all right q standard item index data does this work should work let's comment out real quick all the stuff that we don't have yet oh i had caps lock on that's the problem all right um so let's comment all these out and sorry run this okay we had a problem what was the problem here choose selected if length where did we mess up something oh i remove this down here [Applause] there you go okay so now it should work if i select a couple of things there you go if i select things that are already in there nothing new is added only the new stuff is added so there you go also if i let's restart this if i choose categories they should not be added because they have no parent so this doesn't work and if i select like these three memes and humor should not go to the right there you go works let's implement the remove selected def remove selected now this is actually not too complicated we need to try i don't know why we need to try a thing i did that only do we actually need to try no i think this was one of the things that i didn't remove from my prepared code even though it's not really important so what we want to see is we want to see if the length of the selected item from the list view this time because we add to the listview and we remove from the list view so if it's not equal to zero of course this is self if we have something selected we're just going to say for index in the selected indexes uh we're going to say self.selected dot remove index.data and self.list model dot remove row index.row that should be it now let's go ahead and comment this or uncomment this and now if i have this and if i have this we have a problem why is that okay let's see what the problem is um there you go or let's remove something list remove x not in list what is the problem here i had this problem already i think this was a ui oh no i know i know what i did the problem is this is actually quite interesting when we remove we need to remove in reversed order because what happens is i think this should not be a problem if i just remove a single element so if i remove this it works if i remove this it works the problem is when i select multiple things the order is messed up and not everything is removed this can be solved quite easily by just saying for index in reversed reversed sorted and then this is no longer a problem so i can actually remove this and this should work now there you go works all right um now what we need is we need to do the copy to clipboard this is actually quite simple def copy to clipboard this is done via pi qt5 so we're going to say if uh length of self selected is not equal to zero because then we don't want to copy anything we're going to say clipboard equals q application dot clipboard and then we're going to just set the text of the clipboard to the following thing a hashtag in the beginning plus a hashtag with a space before that we're going to join on that character uh everything that's selected there you go that's it this is actually it so everything should work except for the saving and loading let's run this uh push button oh of course we don't have push button one there you go so now if i say copy and i go to notepad there you go works all right last but not least we're going to go with the open and safe so def safe selected or actually did we call it safe hashtags safe hashtags is going to use the q file dialog so we're going to say file name and confirmed this is going to be q file dialog get save file name uh save hashtags and we're not going to use dot pixel here in the end we're going to use tag file and i hope i'm not blocking this here i am there you go um [Music] we're going to call q file dialog get saved file name save self save hashtags empty string and then tag file and not dot pickle but um sorry we're going to add here dot tax like that all right um and all we need to do is we need to check if it was confirmed so if the user actually wanted to save this and then we're going to say with open file name write bytes as f and then uh pickle dot dump self selected into f this is quite simple now when we load it we need to do something more because we need to also you know saving the selected is easy but when we load them we also need to load the selected list into the item model so we need to say self load hashtags self and in here we're going to now say again file name confirmed equals get file q file unlock get open file name load hashtags tag file tags uh github copilot doing everything here for me repetitive stuff again if confirmed i would want to do here is want to say okay with open file name read bytes as f self dot selected is going to be pickle load f but the problem now is we need to also load all of this into the item model so self dot list model is going to be q standard item model we're going to create a new one uh and we're going to say for tag that we have in self.selected we're going to say self.listmodel.pendro cue standard item off the tag and then self.listview is going to have a new model this self.list model all right that is actually the whole application now of course i need to uncomment these two but besides that this is the exact same thing that i showed you in the preview so let's remove a couple of things let's copy these to the clipboard there you go now let's save them let's close this run this again load there you go and we should also actually be able to load the my tags there you go all right so this is how you build a simple instagram hashtag managing tool in python so that's it for today's video hope you enjoyed hope you learned something if so let me know by hitting the like button leaving a comment in the comment section down below and of course don't forget to subscribe to this channel and hit the notification bell to not miss a single future video for free other than that thank you much for watching see you next video and bye [Music] you

Original Description

In this video, we build an Instagram hashtag generator with a GUI using PyQt5 in Python. ◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾ 📚 Programming Books & Merch 📚 🐍 The Python Bible Book: https://www.neuralnine.com/books/ 💻 The Algorithm Bible Book: https://www.neuralnine.com/books/ 👕 Programming Merch: https://www.neuralnine.com/shop 🌐 Social Media & Contact 🌐 📱 Website: https://www.neuralnine.com/ 📷 Instagram: https://www.instagram.com/neuralnine 🐦 Twitter: https://twitter.com/neuralnine 🤵 LinkedIn: https://www.linkedin.com/company/neuralnine/ 📁 GitHub: https://github.com/NeuralNine 🎙 Discord: https://discord.gg/JU4xr8U3dm 🎵 Outro Music From: https://www.bensound.com/
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from NeuralNine · NeuralNine · 0 of 60

← Previous Next →
1 Visualizing Stock Data With Candlestick Charts in Python
Visualizing Stock Data With Candlestick Charts in Python
NeuralNine
2 Python Beginner Tutorial #1 - Installation and First Program
Python Beginner Tutorial #1 - Installation and First Program
NeuralNine
3 Python Beginner Tutorial #2 - Variables and Data Types
Python Beginner Tutorial #2 - Variables and Data Types
NeuralNine
4 Python Beginner Tutorial #3 - Operators and User Input
Python Beginner Tutorial #3 - Operators and User Input
NeuralNine
5 Python Beginner Tutorial #4 - If Statements and Conditions
Python Beginner Tutorial #4 - If Statements and Conditions
NeuralNine
6 Python Beginner Tutorial #5 - Loops
Python Beginner Tutorial #5 - Loops
NeuralNine
7 Python Beginner Tutorial #6 - Sequences and Collections
Python Beginner Tutorial #6 - Sequences and Collections
NeuralNine
8 Python Beginner Tutorial #7 - Functions
Python Beginner Tutorial #7 - Functions
NeuralNine
9 Python Beginner Tutorial #8 - Exception Handling
Python Beginner Tutorial #8 - Exception Handling
NeuralNine
10 Python Beginner Tutorial #9 - File Operations
Python Beginner Tutorial #9 - File Operations
NeuralNine
11 Python Beginner Tutorial #10 - String Functions
Python Beginner Tutorial #10 - String Functions
NeuralNine
12 Python Intermediate Tutorial #1 - Classes and Objects
Python Intermediate Tutorial #1 - Classes and Objects
NeuralNine
13 Python Intermediate Tutorial #2 - Inheritance
Python Intermediate Tutorial #2 - Inheritance
NeuralNine
14 Python Intermediate Tutorial #3 - Multithreading
Python Intermediate Tutorial #3 - Multithreading
NeuralNine
15 Python Intermediate Tutorial #4 - Synchronizing Threads
Python Intermediate Tutorial #4 - Synchronizing Threads
NeuralNine
16 Python Intermediate Tutorial #5 - Events and Daemon Threads
Python Intermediate Tutorial #5 - Events and Daemon Threads
NeuralNine
17 Python Intermediate Tutorial #6 - Queues
Python Intermediate Tutorial #6 - Queues
NeuralNine
18 Python Intermediate Tutorial #7 - Sockets and Network Programming
Python Intermediate Tutorial #7 - Sockets and Network Programming
NeuralNine
19 Python Intermediate Tutorial #8 - Database Programming
Python Intermediate Tutorial #8 - Database Programming
NeuralNine
20 Python Intermediate Tutorial #9 - Recursion
Python Intermediate Tutorial #9 - Recursion
NeuralNine
21 Python Intermediate Tutorial #10 - XML Processing
Python Intermediate Tutorial #10 - XML Processing
NeuralNine
22 Python Intermediate Tutorial #11 - Logging
Python Intermediate Tutorial #11 - Logging
NeuralNine
23 Python Data Science Tutorial #1 - Anaconda and PyCharm Setup
Python Data Science Tutorial #1 - Anaconda and PyCharm Setup
NeuralNine
24 Python Data Science Tutorial #2 - NumPy Arrays
Python Data Science Tutorial #2 - NumPy Arrays
NeuralNine
25 Python Data Science Tutorial #3 - Numpy Functions
Python Data Science Tutorial #3 - Numpy Functions
NeuralNine
26 Python Data Science Tutorial #4 - Plotting Functions With Matplotlib
Python Data Science Tutorial #4 - Plotting Functions With Matplotlib
NeuralNine
27 Python Data Science Tutorial #5 - Subplots and Multiple Windows
Python Data Science Tutorial #5 - Subplots and Multiple Windows
NeuralNine
28 Python Data Science Tutorial #6 - Matplotlib Styling
Python Data Science Tutorial #6 - Matplotlib Styling
NeuralNine
29 Python Data Science Tutorial #7 - Bar Charts with Matplotlib
Python Data Science Tutorial #7 - Bar Charts with Matplotlib
NeuralNine
30 Python Data Science Tutorial #8 - Pie Charts with Matplotlib
Python Data Science Tutorial #8 - Pie Charts with Matplotlib
NeuralNine
31 Python Data Science Tutorial #9 - Plotting Histograms with Matplotlib
Python Data Science Tutorial #9 - Plotting Histograms with Matplotlib
NeuralNine
32 Python Data Science Tutorial #10 - Scatter Plots with Matplotlib
Python Data Science Tutorial #10 - Scatter Plots with Matplotlib
NeuralNine
33 Python Data Science Tutorial #11 - 3D Plotting with Matplotlib
Python Data Science Tutorial #11 - 3D Plotting with Matplotlib
NeuralNine
34 Python Data Science Tutorial #12 - Pandas Series
Python Data Science Tutorial #12 - Pandas Series
NeuralNine
35 Python Data Science Tutorial #13 - Pandas Data Frames
Python Data Science Tutorial #13 - Pandas Data Frames
NeuralNine
36 Python Data Science Tutorial #14 - Pandas Statistics
Python Data Science Tutorial #14 - Pandas Statistics
NeuralNine
37 Python Data Science Tutorial #15 - Pandas Sorting and Functions
Python Data Science Tutorial #15 - Pandas Sorting and Functions
NeuralNine
38 Python Data Science Tutorial #16 - Pandas Merging Data Frames
Python Data Science Tutorial #16 - Pandas Merging Data Frames
NeuralNine
39 Python Data Science Tutorial #17 - Pandas Queries
Python Data Science Tutorial #17 - Pandas Queries
NeuralNine
40 Python Machine Learning Tutorial #1 - What is Machine Learning?
Python Machine Learning Tutorial #1 - What is Machine Learning?
NeuralNine
41 Python Machine Learning Tutorial #2 - Linear Regression
Python Machine Learning Tutorial #2 - Linear Regression
NeuralNine
42 Python Machine Learning Tutorial #3 - K-Nearest Neighbors Classification
Python Machine Learning Tutorial #3 - K-Nearest Neighbors Classification
NeuralNine
43 Python Machine Learning #4 - Support Vector Machines
Python Machine Learning #4 - Support Vector Machines
NeuralNine
44 Python Machine Learning Tutorial #5 - Decision Trees and Random Forest Classification
Python Machine Learning Tutorial #5 - Decision Trees and Random Forest Classification
NeuralNine
45 Python Machine Learning Tutorial #6 - K-Means Clustering
Python Machine Learning Tutorial #6 - K-Means Clustering
NeuralNine
46 Python Machine Learning Tutorial #7 - Neural Networks
Python Machine Learning Tutorial #7 - Neural Networks
NeuralNine
47 Python Machine Learning Tutorial #8 - Handwritten Digit Recognition with Tensorflow
Python Machine Learning Tutorial #8 - Handwritten Digit Recognition with Tensorflow
NeuralNine
48 Generating Poetic Texts with Recurrent Neural Networks in Python
Generating Poetic Texts with Recurrent Neural Networks in Python
NeuralNine
49 Stock Portfolio Visualization with Matplotlib in Python
Stock Portfolio Visualization with Matplotlib in Python
NeuralNine
50 Analyzing Coronavirus with Python (COVID-19)
Analyzing Coronavirus with Python (COVID-19)
NeuralNine
51 Making Text Images Readable Again with Python and OpenCV
Making Text Images Readable Again with Python and OpenCV
NeuralNine
52 Neural Networks Simply Explained (Theory)
Neural Networks Simply Explained (Theory)
NeuralNine
53 Motion Filtering with OpenCV in Python
Motion Filtering with OpenCV in Python
NeuralNine
54 Top 5 Programming Languages To Learn in 2020
Top 5 Programming Languages To Learn in 2020
NeuralNine
55 Simple TCP Chat Room in Python
Simple TCP Chat Room in Python
NeuralNine
56 Image Classification with Neural Networks in Python
Image Classification with Neural Networks in Python
NeuralNine
57 Edge Detection with OpenCV in Python
Edge Detection with OpenCV in Python
NeuralNine
58 S&P 500 Web Scraping with Python
S&P 500 Web Scraping with Python
NeuralNine
59 Simple Sentiment Text Analysis in Python
Simple Sentiment Text Analysis in Python
NeuralNine
60 Introduction - Algorithms & Data Structures #1
Introduction - Algorithms & Data Structures #1
NeuralNine

This video teaches how to build an Instagram hashtag generator with a GUI using PyQt5 in Python, providing a hands-on example of AI coding skills. The project involves designing a user interface and implementing the logic for generating hashtags. By following this tutorial, viewers can learn how to apply AI coding concepts to real-world problems.

Key Takeaways
  1. Install PyQt5
  2. Design the GUI
  3. Implement hashtag generation logic
  4. Integrate the GUI with the logic
  5. Test the application
💡 Using PyQt5 for GUI development in Python can simplify the process of creating interactive applications, such as an Instagram hashtag generator.

Related Reads

📰
The Python Skills AI Still Can’t Replace in 2026
Learn the Python skills that AI still can't replace in 2026, focusing on security, architecture, and judgment
Medium · Programming
📰
AI's Next Frontier: Cost, Control, and the Compute Race
Learn how AI's next frontier is driven by cost, control, and the compute race, and why it matters for AI development
Dev.to AI
📰
The Rise of Enterprise AI Coding Assistant Bans: Why Cloud Tools Are Being Blocked and What to Build Instead
Learn why enterprises are banning cloud AI coding assistants and how to build a secure on-premise alternative, a $5,000/month opportunity for founders
Dev.to · ping wang
📰
coding benchmarks are becoming production dependencies
Coding benchmarks like SWE-Bench Pro have significant errors, impacting production dependencies, and it's crucial to reassess their use in decision-making
Dev.to AI
Up next
CodeAI at #ISTELive and their free lessons and learning space
Cool Cat Teacher
Watch →