import os from PIL import Image from bing_image_downloader import downloader import random from joblib import dump, load import gradio as gr import shutil import os model_impact=load('Fashionmodel.joblib') def resetDirectory(): # Replace 'path/to/your/directory' with the directory you want to delete directory_to_delete = 'Final_Data' if directory_to_delete: try: # Delete the directory and its contents shutil.rmtree(directory_to_delete) print(f"Directory '{directory_to_delete}' and its contents have been deleted successfully.") except Exception as e: print(f"Error deleting directory: {e}") def predictfun(gender,age,fashion_type,country,color): #resetDirectory() gen=0 fashionType="" if(gender=="Male"): gen=0 elif(gender=="Female"): gen=1 if(fashion_type=="Wedding"): fashionType=0 elif(fashion_type=="Job"): fashionType=1 elif(fashion_type=="Party"): fashionType=2 elif(fashion_type=="Daily_Life"): fashionType=3 result=model_impact.predict([[gen,age,fashionType]])[0] fashionBook={0:['Sherwani','Pent coat','Achkan','Waist-coat suit','Shalwar kameez','Kurta Pajama','Kurta with Waistcoat','Tuxedo suit'], 1:['Lehenga Choli', 'Anarkali Suit' , 'Sharara' ,'Gharara' , 'Bridal Lehenga' ,'Saree' ,' Anarkali Gown' ,' Maxi ', 'Frock' , 'Kurta Pajama','Shalwar kameez'], 2:['Suit and Tie' ,'Dress Shirt with Dress Pants' , 'Blazer with Chinos' ,' Collared Shirt with Jeans',' Sweater with Dress Pants' , 'Polo Shirt with Jeans' , 'Casual Button-Down Shirt with Khakis' ,' Expressive Shirts with Tailored Pants'], 3:['Formal Suit with Dress Shirt or Kameez and Trousers' , 'Traditional Shalwar Kameez with Dupatta (formal style)' , 'Kurti or Tunic with Trousers or Palazzos' ,' A-line Kurta with Churidar or Cigarette Pants',' Casual Kurti with Jeans or Leggings ', 'Printed Blouse with Smart Trousers or Culottes' , 'Informal Kurti or Top with Jeans or Khakis' , 'Casual Salwar Kameez with Straight Pants' , 'Funky/Artistic Blouses or Tunics with Tailored Pants or Skirts' , 'Fusion Wear combining traditional elements like a Kameez with modern cuts or styles'], 4:['Polo Shirt with Jeans' , 'Short-sleeved Button-Down Shirt with Chinos' , 'Blazer with T-shirt and Jeans' , 'Dress Shirt with Dressy Jeans or Chinos', 'Dress Shirt with Dress Pants' , 'Blazer with Dress Pants' , 'Collared Shirt with Chinos' , 'Sweater with Smart Trousers' , 'Dress Shirt with Dark Suit' , 'Dress Shirt with Dress Pants and Tie' , 'Tuxedo with Bow Tie' , 'Three-Piece Suit', 'Black or Navy Suit with Optional Tie' , 'Dress Shirt with Dark Suit and Optional Bow Tie' , 'Statement Jacket with Dress Pants' ,'Unique Blazer with Trousers'], 5:['Printed or Embroidered Kurti with Jeans or Trousers' , 'Colorful Casual Shalwar Kameez with Dupatta' , 'Kurti with Palazzo Pants or Culottes' , 'A-line Kurta with Churidar' , 'Embellished Knee-length Kameez with Trousers or Sharara' , 'Printed Anarkali Suit or Long Kurti with Elegant Bottoms' , 'Formal Kurti or Shirt with Straight Pant' , 'A-line Kurta with Trousers' , 'Embroidered or Sequined Anarkali Gown or Lehenga' , 'Stylish Sharara or Gharara Suit' , 'Heavy Embellished Lehenga or Bridal Gown Floor-length Anarkali Gown' , 'Traditional Heavy Lehenga Choli with Elegant Jewelry' , 'Exquisite Saree with Luxurious Embellishments' , 'Fusion Wear combining Traditional and Modern Elements' , 'Unique Designer Dress with Cultural Influences'], 6:['T-Shirt and Jeans' , 'Shalwar Kameez,Polo Shirt with Chinos Kurta with Jeans or Trousers' , 'Button-Down Shirt with Dress Pants', 'Polo Shirt with Shorts', 'Shalwar Kameez, Casual Shirt with Trousers' , 'Blazer with Dress Pants'], 7:['T-Shirt with Jeans or Leggings', 'Kurti with Trousers or Jeans', 'Salwar Kameez' , 'Kurti with Leggings or Palazzos', 'Casual Blouse with Trousers or Jeans', 'Salwar Kameez or Churidar' , 'Salwar Kameez or Straight Suit' , 'Casual Kurti with Trousers', 'Traditional Saree or Shalwar Kameez']} fashion=fashionBook.get(result) counter=3 random_fashion=[] j=0 for i in range(0,3): if gen==0: random_fashion.append("Male"+" "+fashion[random.randrange(0,len(fashion))]+" "+fashion_type+" "+country+" "+color) elif(gen==1): random_fashion.append("female"+""+fashion[random.randrange(0,len(fashion))]+" "+fashion_type+" "+country+" "+color) for i in range(0,len(random_fashion)): downloader.download(random_fashion[i], limit=1, output_dir='Final_Data', adult_filter_off=True, force_replace=False, timeout=60, verbose=True) # Directory path containing subdirectories with images main_directory = 'Final_Data' images = [] # Walk through the directory and its subdirectories for root, _, files in os.walk(main_directory): for file in files: if file.endswith(('png', 'jpg', 'jpeg', 'gif')): try: image_path = os.path.join(root, file) images.append(image_path) # Do something with the image here # For example: img.show() to display the image except Exception as e: print(f"Error reading {file}: {e}") return images[0],images[1],images[2] interface=gr.Interface(fn=predictfun, inputs=[gr.components.Radio(["Male","Female"],type="value"),gr.components.Textbox(label="Enter Your age"),gr.components.Radio(["Wedding","Job","Party","Daily_Life"],type="value"),gr.components.Textbox(label="Enter Country Name"),gr.components.Textbox(label="Enter Dress Color")], outputs=[gr.components.Image(type="pil"),gr.components.Image(type="pil"),gr.components.Image(type="pil")]) interface.launch(debug=True)