DEV Community

Akshay Keerthi
Akshay Keerthi

Posted on

Building Domain Name Generator using Lyzr SDK

In today’s digital age, your company’s online presence starts with a domain name. It’s not just an address; it’s your brand’s identity in the vast virtual landscape. But finding the perfect domain name can be a daunting task, often requiring hours of brainstorming and research.

Image description

That’s why we’re thrilled to introduce our latest innovation: the Domain Name Generator powered by Lyzr’s advanced ChatBot technology. Say goodbye to the endless search for available domain names and hello to a streamlined, personalized solution tailored to your business needs.

With our Domain Name Generator, finding the perfect domain name has never been easier. Powered by Lyzr’s state-of-the-art ChatBot technology, our generator combines the latest in AI and natural language processing to deliver personalized results in seconds. It’s like having your own team of branding experts at your fingertips, ready to help you unlock the full potential of your online presence.

Why use Lyzr SDK’s?

With Lyzr SDKs, crafting your own GenAI application is a breeze, requiring only a few lines of code to get up and running swiftly.

Checkout the Lyzr SDK’s

Lets get Started!

Create a new file app.py and use that

import os
import shutil
import streamlit as st
from lyzr import ChatBot
Enter fullscreen mode Exit fullscreen mode

This script starts by importing essential libraries like os, shutil, and streamlit. It then imports a custom module ChatBot from the lyzr package. Using streamlit, it creates a web application interface. The purpose seems to be integrating a chatbot into this interface. This chatbot functionality likely interacts with users, potentially providing information or performing tasks based on their input.

Subsequently, it initializes the OpenAI API key using Streamlit’s secrets management. By accessing the specific key stored securely in Streamlit’s secrets, where the OpenAI API key is securely stored, it replaces the placeholder “OPENAI_API_KEY”. This ensures secure access to the OpenAI API within the Streamlit application.

# Set the OpenAI API key
os.environ["OPENAI_API_KEY"] = st.secrets["apikey"]
Enter fullscreen mode Exit fullscreen mode
# Function to remove existing files in the directory
def remove_existing_files(directory):
    for filename in os.listdir(directory):
        file_path = os.path.join(directory, filename)
        try:
            if os.path.isfile(file_path) or os.path.islink(file_path):
                os.unlink(file_path)
            elif os.path.isdir(file_path):
                shutil.rmtree(file_path)
        except Exception as e:
            st.error(f"Error while removing existing files: {e}")
Enter fullscreen mode Exit fullscreen mode

This function, remove_existing_files(directory), is designed to clear out any existing files within a specified directory. It iterates through each file in the directory using os.listdir(directory). For each file, it constructs the full file path using os.path.join(directory, filename). Then, it attempts to remove the file or directory using os.unlink() if it's a file or shutil.rmtree() if it's a directory. Any encountered exceptions, such as permission errors or file not found errors, are caught and displayed as an error message using st.error().

# Set the local directory
data_directory = "data"

# Create the data directory if it doesn't exist
os.makedirs(data_directory, exist_ok=True)

# Remove existing files in the data directory
remove_existing_files(data_directory)
Enter fullscreen mode Exit fullscreen mode

In these lines of code, a local directory named “data” is set using the variable data_directory. The os.makedirs() function is then used to create this directory if it doesn't already exist, with the exist_ok=True parameter ensuring that no error is raised if the directory already exists. Following this, the remove_existing_files() function is called with the data_directory passed as an argument, effectively clearing out any existing files within the "data" directory to ensure a clean workspace.

# Function to implement RAG Lyzr Chatbot
def rag_implementation(file_path):
    # Check the file extension
    _, file_extension = os.path.splitext(file_path)

    if file_extension.lower() == ".pdf":
        # Initialize the PDF Lyzr ChatBot
        rag = ChatBot.pdf_chat(
            input_files=[file_path],
            llm_params={"model": "gpt-4"},
        )
    elif file_extension.lower() == ".docx":
        # Initialize the DOCX Lyzr ChatBot
        rag = ChatBot.docx_chat(
            input_files=[file_path],
            llm_params={"model": "gpt-4"},
        )
    else:
        # Handle unsupported file types
        raise ValueError("Unsupported file type. Only PDF and DOCX files are supported.")

    return rag
Enter fullscreen mode Exit fullscreen mode

This rag_implementation(file_path) function is responsible for implementing the RAG Lyzr Chatbot based on the file type specified by file_path. It first extracts the file extension using os.path.splitext(file_path) and then checks whether the file extension is ".pdf" or ".docx".

If the file is a PDF, it initializes the PDF Lyzr ChatBot with specific parameters such as input files and LLM (Large Language Model) parameters. Similarly, if the file is a DOCX document, it initializes the DOCX Lyzr ChatBot with the same parameters.

In case the file type is not supported (neither PDF nor DOCX), it raises a ValueError indicating that only PDF and DOCX files are supported. Finally, it returns the initialized RAG Lyzr ChatBot instance for further use. This function facilitates the integration of the chatbot functionality with different types of documents

# Function to get Lyzr response
def Chatbot_response(file_path, preferred_keywords):
    rag = rag_implementation(file_path)
    prompt = f""" 
You are an Expert DOMAIN NAME GENERATOR. Your task is to CREATE domain names that PERFECTLY MATCH the uploaded company profile and the user's  preferred keyword.

Here is your DETAILED INSTRUCTION SET:

1. First, IDENTIFY key attributes of the company that will serve as the foundation for your domain name suggestions.
2. ENSURE each domain name you develop is MEMORABLE by choosing SIMPLE and CATCHY names that are easy to spell and recall.
3. Prioritize BREVITY by generating domain names that are SHORT and UNCOMPLICATED, facilitating quick recognition and ease of use.
4. INCORPORATE the user entered {preferred_keywords}) seamlessly into each domain name to enhance search engine optimization (SEO) and relevance.
5. CONDUCT a SEARCH to VERIFY that your suggested domain names do not violate any trademarks, thus ensuring they are legally sound.
6. For every domain name you create, ASSIGN an appropriate DOMAIN EXTENSION such as .com, .net, or .org that aligns with the company's image and purpose.
7. Think about LONG-TERM GROWTH when selecting a domain name, making sure it allows for FUTURE EXPANSION without restrictions.
8. AVOID including hyphens and numbers in your domain names to maintain simplicity unless they are integral to the brand.

For EACH generated DOMAIN NAME with the preferred keyword , IMMEDIATELY SPECIFY a matching DOMAIN EXTENSION and a DESCRIPTION before proceeding to generate the next one.
Display ALL these in a organized TABULAR format."""
    response = rag.chat(prompt)
    return response.response
Enter fullscreen mode Exit fullscreen mode

The Chatbot_response(file_path, preferred_keywords) function facilitates interaction with the Lyzr Chatbot to obtain domain name suggestions tailored to the provided company profile and user's preferred keywords.

Initially, it initializes the RAG Lyzr Chatbot using the rag_implementation(file_path) function. Then, it constructs a detailed prompt containing instructions for the chatbot. These instructions guide the chatbot on generating domain names that align with specified criteria, including simplicity, memorability, brevity, and incorporation of preferred keywords.

Following the prompt preparation, the function interacts with the chatbot by prompting it with the instructions using rag.chat(prompt). Subsequently, it retrieves and returns the response from the chatbot, likely containing domain name suggestions along with their extensions and descriptions, formatted in an organized tabular layout.

 # File upload widget
uploaded_file = st.file_uploader("Upload your company documentation here⬇️", type=["pdf", "docx"])

# If a file is uploaded
if uploaded_file is not None:
    # Save the uploaded file to the data directory
    file_path = os.path.join(data_directory, uploaded_file.name)
    with open(file_path, "wb") as file:
        file.write(uploaded_file.getvalue())

    # Display the path of the stored file
    st.success("File successfully saved")

    # Get preferred genre after file upload
    preferred_keywords = st.text_input("Enter your preferred keyword")

    # Generate advice button
    if st.button("Generate"):
        automatic_response = Chatbot_response(file_path, preferred_keywords)
        st.markdown(automatic_response)
Enter fullscreen mode Exit fullscreen mode

This code segment presents a file upload widget using Streamlit’s st.file_uploader(). Users can upload company documentation in PDF or DOCX format. Upon file upload, the script saves the uploaded file to the specified data_directory using the os.path.join() method and displays a success message indicating that the file has been saved.

After the file is uploaded, users can input their preferred keyword via a text input field. Upon clicking the “Generate” button, the script calls the Chatbot_response() function to obtain domain name suggestions tailored to the uploaded document and the user's preferred keyword. The resulting domain name suggestions are then displayed on the web interface using st.markdown().

With the introduction of our Domain Name Generator powered by Lyzr’s cutting-edge ChatBot technology, we’re revolutionizing the way businesses approach domain name selection. No longer do you have to rely on luck or spend endless hours brainstorming. Our generator leverages the power of AI to deliver personalized, SEO-optimized, and memorable domain names tailored to your unique needs.

Whether you’re launching a new startup, rebranding an existing business, or expanding your online presence, our generator is here to simplify the process and empower you to make informed decisions that will set your brand up for success both now and in the future.

Experience the power of Gen AI-driven domain name generation today and unlock the full potential of your online presence with confidence.

App link: https://domain-name-generator-lyzr.streamlit.app/

Source Code: https://github.com/isakshay007/Domain-Name-Generator

Connect with Lyzr
To learn more about Lyzr and its SDK’s, visit our website or get in touch with our team:

Website: Lyzr.ai
Book a Demo: Book a Demo
Discord: Join our Discord community
Slack: Join our Slack channel

Top comments (0)