DEV Community

Akshay Keerthi
Akshay Keerthi

Posted on

Building Regex Generator using Lyzr SDK

Regular expressions are powerful tools for pattern matching and text processing, but crafting them can be complex and time-consuming. With the advent of automation tools like the Lyzr SDK and the flexibility of Streamlit for creating interactive applications, generating regular expressions has become more accessible than ever before.

Image description

What does Regex Generator do : Our Streamlit application harnesses the Lyzr SDK to provide users with a straightforward interface for generating regular expressions. Users can input their desired patterns or queries, and with the click of a button, the app generates the corresponding regular expression, eliminating the need for manual trial and error.

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 streamlit as st
from lyzr import FormulaGen
Enter fullscreen mode Exit fullscreen mode

This Python script leverages the os, streamlit, and lyzr libraries to build a Streamlit web application. The os module provides functionality for interacting with the operating system, while streamlit empowers the creation of interactive data science and machine learning applications.

Next Set Up OpenAI API Key and using Streamlit’s secrets management, set up the OpenAI API key within your Streamlit application. Replace "OPENAI_API_KEY" with the actual key name defined in your Streamlit secrets where your OpenAI API key is stored.

# Set OpenAI API key
os.environ["OPENAI_API_KEY"] = st.secrets["apikey"]
Enter fullscreen mode Exit fullscreen mode
# Initialize FormulaGen
generate = FormulaGen()

# Define the Streamlit app
def main():

    # Input field for user to enter the pattern
    pattern_input = st.text_input("Enter your pattern/query :")

    if st.button("Generate Regular Expression"):
        # Generate regular expression using FormulaGen
        result = generate.regular_expression(pattern_input)

        # Display the result
        st.write("Generated Regular Expression:")
        st.write(result)
Enter fullscreen mode Exit fullscreen mode

This code initializes an instance of FormulaGen, likely a class or function from the lyzr library, used for generating regular expressions based on patterns.

Within a Streamlit application defined in the main() function, it provides a text input field for users to enter their desired pattern or query.

Upon clicking a button labeled "Generate Regular Expression," the script invokes the regular_expression() method of the FormulaGen instance, passing the user input as an argument. The resulting regular expression is then displayed in the Streamlit app.

# Run the app
if __name__ == "__main__":
    main()
Enter fullscreen mode Exit fullscreen mode

This code segment runs the Streamlit web application defined in the main() function when the script is executed directly.

By combining the Lyzr SDK with the interactive capabilities of Streamlit, we’ve created a powerful tool that simplifies regular expression generation for users across domains. Whether you’re a data scientist, software engineer, or researcher, our app empowers you to tackle complex text processing tasks with ease.

Ready to streamline your regular expression workflow?

Try out our Streamlit app powered by Lyzr SDK today!

App link: https://regex-generator-lyzr.streamlit.app/

We welcome your feedback and suggestions for further improvements.

For more information explore the website: Lyzr

Source Code: https://github.com/isakshay007/Regex-Generator

Book your demo: https://www.lyzr.ai/book-demo/

Join the Lyzr community to stay updated on the latest developments and explore additional AI-driven solutions for your data analysis needs.

Lyzr Community Channels: Discord

Slack : Slack

Top comments (0)