test_XL / sys.py
rakib72642's picture
build structure
3fd025a
import os
import pandas as pd
from utils.main import main
import asyncio
data = pd.read_excel('data.xlsx')
data["Pepsodent Sensitive Expert"]=pd.NA
data["Pepsodent Germicheck"]=pd.NA
data["Shelf Talker"]=pd.NA
outputData = "aiGen.xlsx"
data["Pepsodent AI Qty."] = pd.NA
def is_valid_file(file_path):
return os.path.isfile(file_path)
async def det(data):
for index, row in data.iterrows():
outlet = row["Outlet code"]
img_path_underscore = f"img/_{row['Image No.']}"
img_path_no_underscore = f"img/{row['Image No.']}"
try:
if is_valid_file(img_path_underscore):
img = img_path_underscore
elif is_valid_file(img_path_no_underscore):
img = img_path_no_underscore
else:
continue # Skip to the next image if both paths are invalid
print(img)
result = await main(img)
for name,count in result.items():
data.at[index,"Shelf Talker"]="No"
if name=="Pepsodent Germicheck":
data.at[index, "Pepsodent Germicheck"] = result["Pepsodent Germicheck"]
elif name=="Pepsodent Sensitive Expert":
data.at[index, "Pepsodent Sensitive Expert"] = result["Pepsodent Sensitive Expert"]
elif name=="Pepsodent Shelf Talker":
data.at[index,"Shelf Talker"]="Yes"
print(result)
except Exception as e:
print(f"Error processing image {row['Image No.']}: {e}")
continue # Continue to the next image if an error occurs
async def main_async():
await det(data)
data.to_excel(outputData, index=False)
# Entry point for the script
if __name__ == "__main__":
asyncio.run(main_async())