How to load this script into a script that selects a folder then processes each file of folder

Hi there I have a script with a few handlers how would I load it as a script in a script to apply the routine to a folder of files from choose folder

use AppleScript version "2.4" -- Yosemite (10.10) or later
use framework "Foundation"

use scripting additions
property theA : {}
property fileName : {}

tell application "Finder"


set fileName to (choose file with prompt "Please Select a txt file for Processing")
set fDupe to duplicate fileName to "HD:Users:me:Desktop:CSV:sample:"



set f to (the first file of ¬
	container (alias "HD:Users:me:Desktop:CSV:sample:") of ¬
	application "Finder" whose name ends with "txt")
set ti to text items of (get name of f)
if number of ti is 1 then
	set name of f to "example.txt"
else
	set name of f to "example" & "." & "txt"
end if
end tell
tell application "Finder"
do shell script "/Users/me/Library/Python/3.9/bin/theScript filename ~/Desktop/CSV/sample/example.txt -v -c 'full' -s '10'"
set recCsv to "/Users/me/CSV/sample/example.f0.csv"



set my_data to read recCsv
set csvData to paragraphs 2 thru -2 of my_data as list

set theAnimals to {}

set oldDelims to AppleScript's text item delimiters
set AppleScript's text item delimiters to ","

repeat with a_reading in csvData
	
	
	set y to (text item 2 of a_reading)
	
	if y = "antelope" then
		set y to "A"
	else if y = "bird" then
		set y to "B"
		
		
	end if
	set y to y as text
	
	set end of theAnimals to y
	
             end repeat

set L to theAnimals

 end tell


set theList to {}
repeat 50 times
set theList to theList & items of L
  end repeat

mostPopularItemInList(theList)

to mostPopularItemInList(x)
script accellerator
	property theList : x
	property originalItems : {}
	property originalItemsCount : {}
	on indexof(theItem, theList)
		set text item delimiters to return
		set theList to return & theList & return
		set text item delimiters to {""}
		try
			-1 + (count (paragraphs of (text 1 thru (offset of (return & theItem & return) in theList) of theList)))
		on error
			0
		end try
	end indexof
	to greaterInteger()
		set largerItem to 0
		set largerItemIndex to 0
		repeat with i from 1 to count originalItemsCount
			if originalItemsCount's item i > largerItem then
				set largerItem to originalItemsCount's item i
				set largerItemIndex to i
			end if
		end repeat
		originalItems's item largerItemIndex
	end greaterInteger
    end script

repeat with i from 1 to count accellerator's theList
	considering case
		if accellerator's theList's item i is not in accellerator's originalItems then
			set accellerator's originalItems's end to accellerator's theList's item i
			set accellerator's originalItemsCount's end to 1
		else
			set ind to accellerator's indexof(accellerator's theList's item i, accellerator's originalItems)
			set accellerator's originalItemsCount's item ind to ((accellerator's originalItemsCount's item ind) + 1)
		end if
	end considering
end repeat

set theA to paragraphs 2 thru -2 of return & accellerator's greaterInteger() as text

end mostPopularItemInList



tell application "Finder"

set fileName to fileName as text
set currentFile to (get POSIX path of file fileName) as list
tell currentFile
	
	my tagCmd(it as text)
end tell

end tell

 on tagCmd(f)
do shell script "/usr/local/bin/tag -a " & "'" & theA & "'" & space & quoted form of POSIX path of fileName -- "(get selection)" -- posix path convert path with colon to use in shell
end tagCmd

never mind that reply

I think you want an open handler, then save the script as an applet.

On open fileList
    repeat with thisFile in fileList
      --do your stuff to that file
    end repeat
end open

What I want to do is
set cFol to choose a folder -- and run all the routines as they are, in above script on every file of cFol
Can I choose a folder then use run script theScript in a repeat loop to every file of cfol?

Yes.

set cFol to choose folder

tell application "Finder"
	set myFiles to files of cFol as alias list
	repeat with thisFile in myFiles
		--do your stuff to thisFile
	end repeat
end tell