Can we take the below code:

from sentence_transformers import SentenceTransformer, util
import torch

# Load the model
model = SentenceTransformer('all-MiniLM-L6-v2')

# Updated representative sentences for each category
categories_with_sentences = [
    {
        'category': 'Infrastructure',
        'sentence': (
            'We need assistance with building maintenance and infrastructure issues like plumbing, gates, or waterproofing. '
            'For example, there is a leaking tap in the men’s kitchen that needs urgent repair.'
        )
    },
    {
        'category': 'Soft Services',
        'sentence': (
            'We require services related to cleaning, catering, waste management, or landscaping. '
            'For instance, we need someone to clean up water leaking onto the floor.'
        )
    },
    {
        'category': 'Power Systems',
        'sentence': (
            'There is a problem with our power systems such as emergency power, UPS, or solar energy systems. '
            'Technicians are on-site connecting a generator because there’s no AC power. '
            'We have a mains failure; the generator won’t start remotely. '
            'We are experiencing power outages affecting our telecom equipment.'
        )
    },
    {
        'category': 'HVAC',
        'sentence': (
            'Our heating, ventilation, or air conditioning systems are not working properly. '
            'For instance, there is a high-temperature alarm due to aircon failure.'
        )
    },
    {
        'category': 'Electrical',
        'sentence': (
            'We are experiencing issues with electrical systems like lighting, distribution, or main supply. '
            'For example, there are strange noises coming from the electrical distribution board, '
            'or the power supply voltage is too high.'
        )
    },
    {
        'category': 'Fire Services',
        'sentence': (
            'We need support with fire safety systems including fire alarms, sprinklers, or suppression systems.'
        )
    },
    {
        'category': 'Security',
        'sentence': (
            'We need security services such as CCTV surveillance, intruder alarms, or security patrols. '
            'For example, arranging security escort for site visits.'
        )
    },
    {
        'category': 'Water Reticulation',
        'sentence': (
            'We have problems with water systems like domestic water supply, drainage, or water features. '
            'For example, water is leaking and pouring out, or there’s no water supply.'
        )
    },
    {
        'category': 'Appliances',
        'sentence': (
            'There are issues with appliances like kitchen equipment, audio-visual devices, or gym equipment. '
            'For example, the dishwasher is leaking, or the pie warmer is not turning on.'
        )
    },
    {
        'category': 'Mechanical Units',
        'sentence': (
            'We require maintenance for mechanical units like hoists, conveyors, or mechanical equipment. '
            'For instance, the gate latch is out of place; the gate won’t lock, and we need mechanical assistance.'
        )
    },
    {
        'category': 'Masts and Towers',
        'sentence': (
            'We need services related to masts, towers, or satellite antennas. '
            'Issues such as site access to towers, maintenance on telecom equipment on towers, or antenna problems.'
        )
    },
    {
        'category': 'Access Control',
        'sentence': (
            'We need assistance with access to a site, including key numbers, gate access, access codes, or site permissions. '
            'For example, I need access to a site; here is my key number and site ID. '
            'Can you confirm if the site is locked or if I have permission to enter?'
        )
    },
    {
        'category': 'Remote Monitoring',
        'sentence': (
            'We require help with systems that enable us to monitor sites remotely, such as surveillance or tracking systems. '
            'For instance, our remote systems can’t start the generator; we need assistance with remote access and monitoring tools.'
        )
    },
    {
        'category': 'Safety, Health, and Environment',
        'sentence': (
            'We need safety equipment like first aid kits or assistance with health and environmental issues. '
            'For example, water leaking poses a safety hazard, or we need to address high-temperature alarms.'
        )
    },
    {
        'category': 'Workplace Services',
        'sentence': (
            'We require workplace services like furniture moves, indoor plants, or archiving. '
            'For example, we need authorization for delivery of items to the office.'
        )
    },
    {
        'category': 'Lifts',
        'sentence': (
            'Our lifts or escalators are malfunctioning and need repair.'
        )
    },
    {
        'category': 'Cable Pressurisation and Dehydration',
        'sentence': (
            'We need services related to cable pressurisation and dehydration systems.'
        )
    },
    {
        'category': 'Vehicles',
        'sentence': (
            'We require maintenance or services for vehicles or transportation equipment.'
        )
    },
    {
        'category': 'Data and IT Equipment',
        'sentence': (
            'There are issues with data servers, IT equipment, or intelligent cabinets. '
            'For example, we are experiencing network problems; the line keeps breaking during calls. '
            'Our network systems are unstable, and we’re having trouble with IT equipment or services.'
        )
    },
    {
        'category': 'Other',
        'sentence': (
            'We have a request that does not fit into standard categories and need assistance.'
        )
    },
]

# Extract sentences and categories
sentences = [item['sentence'] for item in categories_with_sentences]
categories = [item['category'] for item in categories_with_sentences]

# Encode the category sentences into embeddings
category_embeddings = model.encode(sentences, convert_to_tensor=True)

# Transcribed calls (the actual transcripts)
transcripts = [
    """Thank you for calling me to see now for speaking. Can I assist you? I need access to a site, please. Glam key number? Charlie Papa 87. Charlie Papa 87. 87. Speaking to Leon. Leon, yeah. Site number? 353380. 353380. Site number three five double three eight oh three five double three eight oh, yeah, I'm going to the main listening. No, I'm saying how long? How long? Give us two hours, please. All right, you cannot make sure to close any of that. I'll do that. Thank you. All right, thank you. Bye. Bye-bye.""",
    """Thank you for calling ATC. I'm supposed to push you. How can I assist? Hello. Can you please confirm if the site is logged? 352824. You said it's 352824. And we are at, what's the name? Uku Kanya. Uku Kanya. Okay. The file is closed. Thank you for your concern. Thank you back.""",
    """Okay, how are you? I'm good. Can I please access a site? Key number? B-8-E-W-5-9. Site I-B-8-8-5-3-0-3-8. N-G? Yes. Which gate? N Main gate. Who am I speaking to? Masugi. Which company? CGA. What are you doing then? Maintenance on cell phone. 0902. Sorry. 092-084. 890902-6092-084. How many are you there? I'm alone. And say 5. Thank you.""",
    """Welcome to the City of Joseph. Please note that this call may be recorded for quality and training purposes. Dear valid pensioner, the city has seen a spike in a number of pensioners inquiring and doing follow-ups on the application of rebates. Pensioners are advised to be patient as the city is working around the clock in ensuring that all applications are processed and are correctly captured. We apologize for the delay. Dear CLJ customers, kind to be advised that you can now submit your electricity and water meter readings on a monthly basis using the eJoburg portal. For more information, visit www.e-joburg.org.za, putting you in charge of your municipal account. In an effort to improve on our service offerings, we now invite you to give feedback on your experience with our call center by answering just two questions at the end of the call. For all account-related inquiries, please press 1. For electricity-technical-related inquiries, please press 2. For water-technical-related enquiries, please press 3. For all refuse, waste removal, and pick it up... Seripalo, you're speaking to Sonisha. How can I assist? Good morning, Sonisha. How are you? Good morning. How are you? Hello. Hello. Hello. Okay.
""","""Hello. Hello, how are you? Good, and you? I'm good. You shouldn't see Elisa from PCC. I'm calling you out about Kumqa Exchange. William went to the site earlier on and around for a truck and at Kumqa there was no network so he couldn't call so he left the site when he was still investigating the generators running. And as he was investigating the power restored, and then he left the site. And then when I could get a hold of him as we were speaking, he said what's going on on site. And then we called access view to check alarms and everything. As they were checking, they said the alarms were still accessed, and then Coombs said that he's going to check with DC Power. As they were checking with DC Power, the alarms that main sale came up again, and then they tried to start the generator mostly and then it didn't start. So now I cannot find the tech to dispatch, to just go check what's really going on there at Kumha again. Okay. Who went there earlier in the day? William. William? Yes. Okay. The date on call is Philip Jacobs. He's away of time. I cannot get a hold of him. That's why I'm quoting you. Just hold. Just hold. Just hold. I'm going to try and link him. Let me just pull over here because I'm driving. Okay. No problem. Just hold. Just hold. I I've got BCC on the line. They want somebody to go to Comda. Yeah, they say Billy was there during the day, but there's still an issue, or I the latest fault? What is the latest fault on site? What is the latest for it on site? They said a main fail. Yeah, but there will be a main fail and then the batteries will be running inside. Only after 48 volts, below 48 volts, the sample will be running. Otherwise, it's running off lithium batteries at the moment. Yeah. The site is going to... Does it have I2M system? Am I right? Yes, it's got IQM system, yes. Yes, it has IQM, but already the battery was not charging. It's at 46 volts at the moment. They tried to start it remotely while we were still on the call with William, but it didn't start. You're breaking off there. Can you repeat that? When they said there's mains fail, they tried to start the engine remotely as the batteries were at 46 valves. Okay. Yes. So you want us to run the engine manually? Yes, they requested that so they want us to go and start the engine yes because it's not going remotely because the rkm is not starting the engine yes no that's a communication problem with the rkm Okay, what do you want? Do you want telecom to go? No, no, no. They'll phone you. Yeah? No, no, no. I'm still early and stuff. I want it down now before it's 12 o'clock at night and stuff like that. They'll phone you at ugly hours to still go. Yes. But the thing is that what do I do? I can't put the inverter and stuff off and the mines off because you remember everything runs now through that whole solar system. What do I want us to do starting? Because the windows are all connected up to a remote start. Okay. Precisely, who said we must go start the engine? Kums from AccessU. Can you put Coombs online? Okay, please just hold on. Besides solar panels, all of them are a headache. Thank you. Thank you. Hello? It looks like they broke off or something. Hello? Yes, I have Paul, who is out. Uh, Paul says, uh, the rectifier has started charging now. Yeah, I'm not sure what is wrong or what you did do on site but the rectify seems to be charging at the moment obviously you don't need to take to go to site let me just find out yet give me once homes homes just for your info what is happening that site is called solar panels so they put in all those systems for change over and all of that, so that system seems to be problematic. Yeah, but at the moment I'm looking at my IQM site, and we're having a standby focus. Kums, you broke off, can you repeat that? Yes. Can you repeat that, please? You broke off. At the moment we're getting a standby focus start alarm from Comcha as well. That is why Koems might be asking you guys to go to South to see why we're getting that standby phone to start. I tried to start the machine remotely and it did not start. Okay. But now could there be an issue with the IQM system or not? That I cannot tell you for sure. As we were busy testing here, the alarms on the IQM were's changing so uh that said i think the iqm might working fine for now okay bottom line you want to take to go to site to see why we're getting the standby phone to start yes okay so you go to site and maybe he's going to confirm it's right to him. Philip, you've got that. Yes, of course, but it's the same thing that Paul was there today. He confirmed it's not on our side. So we're going the second time again, but it's fine. But you see, okay, but this photo start alarm came up at 1742, so not too long ago. Okay, Kooms, when the tag is on site, who must have phone? Must you phone you or who? What time are you logging off? All of us is logging off at 7 o'clock, so that will be the new team when you phone in. So anyone from Night Shift you can talk to okay if it's easy it's gonna be the third or fourth time now they prove there's an issue with the iqm system if we prove that again who do we take it up with yeah that's a good question either um you know danny on our side um danny for he is doing the iqm so maybe um you must see what is happening there. Because now we're going to be sent to that site all the time, all the time, perpetually, and it's not right. Yeah, no, I agree. I really agree. Okay. Just touch phone, and then when you are on site, you can phone PCC to give them the update. You can link me if you want. Okay, not a problem, sir. Okay, thanks everyone. I'll get you. Okay, bye. Bye.
""","""Yes, Mr. I repeat. I mean, I'm in Velcom. And the software is like, no, no, no, no. During the day, I think, no, no. I was in Waden. I was attending some jobs in Whiten. It was going to be closed. Okay. Yeah. But if you don't come close, you'll let me know again. Yeah, because now I'm already in Valcom, so we have a minimum of four hours because it has a continuous area of Cyrus Smith me five hours okay and even a guy from uh what money i don't know who nourish the second option will be a technician from Longmedo. Longmedo, it will only take them three hours. From a person who is from Joanne's back side. Okay. Yes, but then let you. Talk to you now, now. All right.
""","""for calling me to see now for speaking i can assist you ah good this uh speaking to become from trading trading could you kindly assist by extending uh a time uh on site side number three five two eight seven four three five two eight seven four 352874. How long? Until 70. Who am I speaking to? Bokang. Bokang. Yes, sir. Only the main gate. only the main gate only are also requested the db that on my because i open it is still open all right no problem okay no problem thank you so much thank you bye thanks
""","""Hi there. I am in importance of gardens. And I ordered an item because we moved in recently. I ordered an item. And it was supposed to be delivered on Friday. But I had an issue and they couldn't deliver Friday or today. Or yesterday, I mean. So they are here now this morning. But the security doesn't want them to enter. Is there anything else we can do for our fridge to be delivered? Did you log a request for that delivery? No, because I didn't log a request, because they said, because we moved in last week, we had about a week for our staff to be coming in. So that's why we ordered the fridge for what we delivered in that week. But because I had an issue, so they can only deliver it today. Yeah, they won't allow them to deliver because you need to make a request once you settle and then if you have any delivery, you need to let us know. We'll make a And we didn't have to get a letter. But now because it's after the week, due to an issue on the app or on the website, now we can't get it. Is there anything else we can do to get it delivered today? Because they are in front now. They won't allow it. You will have to either speak to the security or you're going to have to log a request which is going to take you another two working days for you to receive that authorization. So I will tell you that you have to take it to the property manager. There is actually no other way for me to get the footage now. No. Okay, how do I, there's any way for me to log a complaint for the securities. There's no complaint that you need to log. No, the reason I'm saying that is because they can see we're in a situation where we really need this item, but we don't want to let them in. Like you said, they're doing their job. But in the night when we come out, then other cars can come in and all they have to do is sign in. That's all they have to do. So why can't they do the same? Okay, then report it to the property manager. Okay, so the property manager. Okay, there is nothing else you guys can do. We only log a call when you have any problem, like if you want to put in something to the property or that something is faulty in the house. That's all we can access to. Okay, so something to be into the property, that is how long? Two days. Two working days, yes. Two working days. Uh-huh. Okay. Okay, thank you. No problem. Bye.
""","""Hello, good morning, Teresa, how are you? IDD. I'm not sure if I can hear you clearly. I said, please speak to Tingehla and ask if he's got a telephone, a telephone mobile available because we spread results under him. If not, I'll... Not a mobile. We do not need a mobile. We need an e-con technician to... Okay, sorry. Can you speak to Tingehla? We spread results under him. All right. Thank you. I will speak to you. Bye.
"""
]

# Preprocessing function to clean transcripts
def preprocess_transcript(text):
    # Lowercase the text
    text = text.lower()
    # Remove filler words and irrelevant phrases
    filler_phrases = [
        'thank you for calling', 'can i assist you', 'may i assist you',
        'hi', 'hello', 'bye', 'goodbye',
        'how are you', "i'm good", "i'm fine", "i'm okay",
        'speaking', 'talking', 'call', 'calling',
        'through to', 'good morning', 'good afternoon', 'good evening',
        'no problem', 'thank you', 'thanks', 'please hold', 'hold on',
        # Additional phrases
        'this is', "you're speaking with", 'have a nice day', 'bye-bye'
    ]
    for phrase in filler_phrases:
        text = text.replace(phrase, '')
    # Remove extra whitespace
    text = ' '.join(text.split())
    return text

# Process each transcript
for transcript_idx, transcript in enumerate(transcripts):
    # Preprocess the transcript
    cleaned_transcript = preprocess_transcript(transcript)

    # Encode the transcript into an embedding
    transcript_embedding = model.encode(cleaned_transcript, convert_to_tensor=True)

    # Compute cosine similarities between the transcript and all category sentences
    cosine_scores = util.cos_sim(transcript_embedding, category_embeddings)[0]

    # Get the top category with the highest similarity score
    top_result = torch.topk(cosine_scores, k=1)
    top_idx = top_result.indices[0].item()
    top_score = top_result.values[0].item()
    matched_category = categories[top_idx]
    matched_sentence = sentences[top_idx]

    print(f"Transcript {transcript_idx + 1}:\n")
    print(transcript)
    print("\nMatched Category:")
    print(f"Category: {matched_category} (Score: {top_score:.4f})")
    print('-' * 80)


But then run through all the transcriptions in the csv:  C:\Users\FourieH\full_transcription_results_with_analysis.csv from the "Full Transcription" column then make a new csv with RecKey,Full Transcription from the full_transcription_results_with_analysis.csv and add catagory and score