Building Query2Excel using Lyzr SDK
Tags: ai, promptengineering, excel, nlp
Published: 2024-03-21 06:37:42

**Query2Excel** simplifies this entire workflow by harnessing the power of the **Lyzr SDK**. At its core, Query2Excel is a **Streamlit** application that enables users to input **natural language queries** and receive formatted **Excel** outputs — all with the click of a button. Leveraging Lyzr SDK’s **FormulaGen** capabilities, Query2Excel translates user queries into Excel formulas, automating the process of **data extraction** and organization.


**How Query2Excel Works?**

The user interface of Query2Excel is intuitive and user-friendly. Once the query is submitted, Query2Excel’s backend, powered by **Lyzr SDK**, swings into action. The entered query is processed, parsed, and transformed into **Excel formulas** using Lyzr’s **FormulaGen **module. The resulting Excel output is then presented to the user, ready for download or further analysis.

**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](https://docs.lyzr.ai/lyzr-sdk/opensource/)

**Lets get Started!**
Create a new file **app.py** and use that

```
import os
import lyzr
import streamlit as st
from lyzr import FormulaGen
```

In this script, we’re importing necessary modules to build a Streamlit application integrated with **Lyzr SDK**. **Streamlit **provides the framework for the web application, while Lyzr SDK offers capabilities for **natural language processing** and data manipulation. The **FormulaGen** module from Lyzr likely facilitates formula generation based on user inputs, enabling streamlined **data analysis** and interaction.

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.

```
openai.api_key = st.secrets["OPENAI_API_KEY"]
```

This step secures the **API key** within your application, ensuring its confidentiality and proper usage.

```
generate = FormulaGen()

# Define the Streamlit app
def main():

    # Input field for natural language query
    query = st.text_input("Enter your natural language query :")

    # Generate formulas button
    if st.button("Generate"):
        if query:
            # Generate formulas based on the query
            result = generate.spreadsheets(query)
            st.write("Results:")
            st.write(result)
        else:
            st.write("Please enter a query.")
```

The application initializes a **FormulaGen** object from **Lyzr SDK**, enabling the generation of **formulas**. Within the Streamlit app's main function, users are prompted to input a **natural language query** via a text input field. Upon clicking the 'Generate' button, the application checks if a query has been provided.

If so, it calls the **spreadsheets** method of the FormulaGen object to retrieve formulas based on the query. The resulting formulas are then displayed as output. If no query is entered, the application prompts the user to provide one before proceeding with the generation process.

By leveraging **Lyzr SDK’s** capabilities, the application abstracts away the complexity of formula generation, allowing users to focus on their **data analysis** tasks without getting bogged down in technical details. This user-friendly design fosters accessibility and empowers users of all skill levels to harness the power of natural language processing for their data management needs.

Try out the Application: [Query2Excel
](https://query2excel-lyzr.streamlit.app/)
Youtube Link: [https://youtu.be/tVltzm2Gmas](https://youtu.be/tVltzm2Gmas)

References
Lyzr Website: [Lyzr](https://www.lyzr.ai/)

Book a Demo: [Demo](https://www.lyzr.ai/book-demo/)

Lyzr Community Channels: [Discord](https://discord.com/invite/nm7zSyEFA2)

Slack : [Slack](https://anybodycanai.slack.com/join/shared_invite/zt-2a7fr38f7-_QDOY1W1WSlSiYNAEncLGw#/shared-invite/email)