RASA Custom actions , csv fetching and one hot encoding

I’m building a jewelry bot using the rasa framework , where a user provides a query for example “show me rings for woman” then the bot should extract the entities jewelry type which is “rings” in this query and gender entity which is “woman” once when the bot extracts these entities it should check the csv database in rows where rings ==1 and woman ==1 apart from that the other rows can be zero or 1 for example wife == 0 or 1 that doesn’t matter , and then retrieve the values of Name , MRP , Special Price , Description and URL of those rows and display it to the user , this is my csv database , for sample Im just copy pastin 5 rows : SKU NAME MRP SPECIAL_PRICE DESCRIPTION URL_PATH ADJUSTABLE RINGS ARM BANDS BABY BANGLES BANGLES BELLY RINGS BRACELET BRACELETS BROOCHES CHAINS CHARM BUILDERS CHARMS CUFF LINKS DUMMY PRODUCT EARRING EARRINGS EXPRESS DELIVERY GIFT-CARD GOLD COIN HAIR ACCESSORIES HASLI NECKLACES KADA KANOTI KURTA BUTTONS MAANG TIKKA MANGALSUTRA MASK CHAIN MOUNT-EARRINGS MOUNT-PENDANTS MOUNT-RINGS NACKLACE NAIL RINGS NATH NECKLACES NOSE ACCESSORIES NOSE PINS & RINGS NOSE PIN PENDANTS QWIKCILVER GIFT-CARD RINGS SETS SILVER COIN TANMANIYA TOE RINGS WAIST BANDS WATCH CHARMS WRIST WATCHES BABY BOYFRIEND DAUGHTER FIANCEE GIRLFRIEND HUSBAND INFANTS KIDS MEN UNISEX MOTHER NEPHEW NIECE SISTER SON TEENAGER WIFE WOMAN ALL JR01891-WGP900 Amara Diamond Ring 43749 39375 Diamond (0.16 Ct, IJ-SI),18 Kt White Gold amara-diamond-ring-jr01891-wgp900 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 JE00928-1YP2RE Nazrana Stud Earrings 38873 Diamond(0.12 ct,EF,VVS,Round),Emerald , Ruby,14 Kt Yellow Gold nazrana-stud-earrings-je00928-1yp2re 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 JE04381-1YP4RS Bloom Scallop Gemstone Stud Earrings 197247 165838 Diamond (1.058 Ct, GH-VVS),14 Kt Yellow Gold bloom-scallop-gemstone-stud-earrings-je04381-1yp4rs 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 JR01465-WGP400 Edge of Princess Diamond Band 28192 Diamond(0.25 ct,GH,VVS,Round),18 Kt White Gold edge-of-princess-diamond-band-jr01465-wgp400 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 SR02228-RGP400 Jerry Solitaire Ring for Men 43282 40604 Diamond (0.2 Ct, GH-VVS),18 Kt Rose Gold jerry-solitaire-ring-for-men-sr02228-rgp400 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1

this is my actions.py file contents , I guess the csv filter doesn’t work right in this code thats why when a user queries “show me rings for woman” it simply says “no matching results found” , despite me having checked the database where there are rows with rings ==1 and woman ==1 , so please make necessary changes in my code so that , it retrieves the relevant results and displays it to the user as per the user conditions

import csv from typing import List, Text, Dict, Any, Optional from rasa_sdk import Action, Tracker from rasa_sdk.executor import CollectingDispatcher from rasa_sdk.events import SlotSet from tabulate import tabulate

class ActionSayPresaleOccasion(Action):

def name(self) -> Text:
    return "ActionSayPresaleOccasion"

async def sub_filter_csv(self, jewelry_type: str, gender: Optional[str], csv_file_path: Text, max_results: int = 5) -> List[Dict[str, Any]]:
    results = []

    with open(csv_file_path, newline='', encoding='latin-1') as csvfile:
        reader = csv.DictReader(csvfile)
        count = 0
        for row in reader:
            if count >= max_results:
                break
            # Check if row matches the filter criteria
            if gender:
                if int(row.get(gender.upper(), 0)) == 1 and int(row.get(jewelry_type.upper(), 0)) == 1:
                    result = {
                        'NAME': row['NAME'],
                        'MRP': row['MRP'],
                        'SPECIAL_PRICE': row['SPECIAL_PRICE'],
                        'DESCRIPTION': row['DESCRIPTION'],
                        'URL_PATH': row['URL_PATH']
                    }
                    results.append(result)
                    count += 1
            else:
                if int(row.get(jewelry_type.upper(), 0)) == 1:
                    result = {
                        'NAME': row['NAME'],
                        'MRP': row['MRP'],
                        'SPECIAL_PRICE': row['SPECIAL_PRICE'],
                        'DESCRIPTION': row['DESCRIPTION'],
                        'URL_PATH': row['URL_PATH']
                    }
                    results.append(result)
                    count += 1

    return results

async def run(self, dispatcher: CollectingDispatcher,
              tracker: Tracker,
              domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:

    # Extract values from tracker
    jewelry_type = tracker.get_slot('presale_product_category')
    gender = tracker.get_slot('gender')

    if not jewelry_type:
        dispatcher.utter_message(text="Please specify the type of jewelry you are looking for.")
        return []

    jewelry_type = jewelry_type.upper()  # Convert to uppercase

    # Specify your CSV file path
    csv_file_path = '/home/chandhinii/Downloads/output.csv'

    # Asynchronously filter CSV data
    filtered_results = await self.sub_filter_csv(jewelry_type, gender, csv_file_path)

    if filtered_results:
        for result in filtered_results:
            message = (f"Name: {result['NAME']}\n"
                       f"MRP: {result['MRP']}\n"
                       f"Special Price: {result['SPECIAL_PRICE']}\n"
                       f"Description: {result['DESCRIPTION']}\n"
                       f"URL: {result['URL_PATH']}\n\n")  # Add one-line space after each product
            dispatcher.utter_message(text=message)
    else:
        dispatcher.utter_message(text="No matching results found.")

    return [SlotSet('filtered_results', filtered_results)]

please modify the code such that if both the entities ==1 then display those results for the query “show me rings for woman” , I have such toes , ill copy paste it SKU NAME MRP SPECIAL_PRICE DESCRIPTION URL_PATH ADJUSTABLE RINGS ARM BANDS BABY BANGLES BANGLES BELLY RINGS BRACELET BRACELETS BROOCHES CHAINS CHARM BUILDERS CHARMS CUFF LINKS DUMMY PRODUCT EARRING EARRINGS EXPRESS DELIVERY GIFT-CARD GOLD COIN HAIR ACCESSORIES HASLI NECKLACES KADA KANOTI KURTA BUTTONS MAANG TIKKA MANGALSUTRA MASK CHAIN MOUNT-EARRINGS MOUNT-PENDANTS MOUNT-RINGS NACKLACE NAIL RINGS NATH NECKLACES NOSE ACCESSORIES NOSE PINS & RINGS NOSE PIN PENDANTS QWIKCILVER GIFT-CARD RINGS SETS SILVER COIN TANMANIYA TOE RINGS WAIST BANDS WATCH CHARMS WRIST WATCHES BABY BOYFRIEND DAUGHTER FIANCEE GIRLFRIEND HUSBAND INFANTS KIDS MEN UNISEX MOTHER NEPHEW NIECE SISTER SON TEENAGER WIFE WOMAN ALL JR06978-1YP9P0 Yesha Gemstone Ring 34933 29373 Diamond (0.121 Ct, IJ-SI),14 Kt Yellow Gold yesha-gemstone-ring-jr06978-1yp9p0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 2 0 0 0 1 1 0 0 1 1 0 1 0 0 1 0 JR05986-WGP200 Posy Cluster Diamond Ring 15308 14543 Diamond (0.04 Ct, EF-VVS),18 KT White Gold posy-cluster-diamond-ring-jr05986-wgp200 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 1 1 0 0 0 0 0 1 0 1 1 0 JR05986-1YP200 Posy Cluster Diamond Ring 13793 13103 Diamond (0.04 Ct, EF-VVS),14 KT Yellow Gold posy-cluster-diamond-ring-jr05986-1yp200 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 1 1 0 0 0 0 0 1 0 1 1 0 JR05986-WGP500 Posy Cluster Diamond Ring 14502 13777 Diamond (0.04 Ct, GH-VS),18 KT White Gold posy-cluster-diamond-ring-jr05986-wgp500 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 1 1 0 0 0 0 0 1 0 1 1 0 JR06886-1YP900 Zivana Diamond Band 29333 26499 Diamond (0.139 Ct, IJ-SI),14 Kt Yellow Gold zivana-diamond-band-jr06886-1yp900 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 2 0 0 0 1 1 0 0 1 1 0 1 0 0 1 0 JR06482-1YP900 Alivia Diamond Ring 60986 55633 Diamond (0.3 Ct, IJ-SI),14 Kt Yellow Gold alivia-diamond-ring-jr06482-1yp900 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 2 0 0 0 1 1 0 0 1 1 0 1 0 0 1 0 JR05986-1RP500 Posy Cluster Diamond Ring 12987 12338 Diamond (0.04 Ct, GH-VS),14 KT Rose Gold posy-cluster-diamond-ring-jr05986-1rp500 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 1 1 0 0 0 0 0 1 0 1 1 0 JR06329-1RP900 Glowing Heart Diamond Band 14210 12788 Diamond (0.05 Ct, IJ-SI),14 Kt Rose Gold glowing-heart-diamond-band-jr06329-1rp900 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 1 1 0 0 0 0 0 1 0 1 1 0 JR05986-1YP500 Posy Cluster Diamond Ring 12987 12338 Diamond (0.04 Ct, GH-VS),14 KT Yellow Gold posy-cluster-diamond-ring-jr05986-1yp500 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 1 1 0 0 0 0 0 1 0 1 1 0 in the above both woman ==1 and rings ==1 , I have used the same csv data in my actions.py but still it simply says “no matching results found”, modify the code so that the bot fetches the relevant results correctly , Please odify the above code such that the bot fetches the rows containing g values of rings ==1 and woman ==1 based on the query