File size: 1,815 Bytes
3fd025a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
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())