Spaces:
Paused
Paused
| import gradio as gr | |
| import torch | |
| from transformers import pipeline, AutoModelForCausalLM, AutoTokenizer | |
| # Load your fine-tuned model | |
| model_path = "Gajendra5490/skinChatbot" | |
| model = AutoModelForCausalLM.from_pretrained( | |
| model_path, | |
| torch_dtype=torch.float16, | |
| device_map="auto" | |
| ) | |
| tokenizer = AutoTokenizer.from_pretrained(model_path) | |
| # Create text-generation pipeline | |
| chatbot = pipeline( | |
| "text-generation", | |
| model=model, | |
| tokenizer=tokenizer, | |
| max_length=250, | |
| do_sample=True | |
| ) | |
| # Define keyword lists | |
| greetings = [ | |
| # Emoji & reactions | |
| "π", "ππ»", "ππ½", "β", | |
| "π", "π", "π", "π", | |
| # Extended hi/hey family | |
| "hi", "hi!", "hii", "hiii", "hiiii", "hy", "hie", "hiya", "hiya!", "heya", "heya!", "heeey", "hayy", | |
| "hello", "hello!", "helloo", "hellooo", "helo", "heloo", "hullo", "hulloo", "hellow", "ello", "ello gov'nor", | |
| "hey", "hey!", "heyy", "heyyy", "heyyyy", "hay", "hay!", "hei", "yo", "yo!", "yoo", "yoo!", "yope", | |
| # Playful/slang | |
| "sup", "sup?", "what's up", "whats up", "whatsup", "wassup", "wasup", "wazzup", "wuz up", "wut up", | |
| "what's good", "what's new", "whatβs happening", "whatβs poppin'", "what's crackin'", "what's shakin'", | |
| "yo yo", "hey yo", "hey fam", "yo fam", "hey peeps", "hey squad", | |
| # How are you variants | |
| "how are you", "how r you", "how are u", "how r u", "how ru", "how are ya", "howaya", "how's it going", | |
| "hows it going", "how's life", "howz life", "howzit", "how you doin'", "how you doing", | |
| # Time-based & day-starters | |
| "good morning", "good morning!", "gm", "gm!", "gud morning", "goood morning", | |
| "good afternoon", "good afternoon!", "ga", "ga!", "gud afternoon", "goood afternoon", | |
| "good evening", "good evening!", "ge", "ge!", "gud evening", "goood evening", | |
| "good day", "good day!", "gud day", "goood day", "top of the morning", | |
| # Formal / classic | |
| "greetings", "greetings!", "salutations", "salutations!", "greetings and salutations", "ahoy", | |
| "howdy", "howdy partner", "peace", "namaste", "aloha", "shalom", | |
| # International | |
| "hola", "hola!", "hola amigo", "bonjour", "bonjour!", "ciao", "ciao!", "ola", "ola!", "salut", "salut!", | |
| "hallo", "hallo!", "privet", "konnichiwa", "namaskar", | |
| # Friendly/familiar | |
| "hey buddy", "hey pal", "hey dude", "hey bro", "hey girl", "hi friend", "hello friend", | |
| "hello everyone", "hi everyone", "hi all", "hello all", "hiya gang", | |
| # Fun / one-offs | |
| "knock knock", "whatβs cookinβ", "ready to chat?", "long time no see", "look who's here", "well hello there", | |
| "hiya stranger", "hey stranger", "hello stranger" | |
| ] | |
| farewells = [ | |
| "bye", "goodbye", "good bye", "byebye", "bye bye", "bye-bye", "see you", "see ya", "see u", "see you soon", | |
| "talk to you later", "talk to ya later", "talk to u later", "catch you later", "catch ya later", "until next time", | |
| "take care", "farewell", "so long", "have a nice day", "have a good day", "have a good one", "be well", | |
| "see you around", "until then", "good day", "later", "later on", "till next time", "until we meet again", | |
| # Slang & Informal | |
| "peace", "peace out", "ttyl", "l8r", "see ya", "catch ya", "catch u", "cya", "cya later", "g2g", "im out", | |
| "outta here", "i'm gone", "talk later", "bye for now", "toodles", "adios", "au revoir", "ciao", "sayonara", | |
| "deuces", "smell ya later", "laters", "buh-bye", "cheerio", "i'm off", "holla", "peace and love", | |
| # Thankful + Exit | |
| "thanks, bye", "thank you, bye", "thank you so much, bye", "thx, bye", "ty, bye", "ok thanks bye", | |
| "thank u bye", "alright thanks, bye", "thanks for your help, bye", | |
| # Misspellings & Variants | |
| "byee", "byy", "gbye", "goobye", "gudbye", "byeebye", "seeya", "seeyou", "t2yl", "tlk to u later", | |
| "tk care", "tkcr", "ta ta", "ta-ta", "peece out", "seee ya", "se you", "sse ya", "have gud day", "hav a good one", | |
| "have anice day", "haveanice day", "latr", "laterr", "l8er", "tlk later", "see yuh", "c u soon", "catcha later" | |
| ] | |
| skincare_keywords = [ | |
| # Existing keywords | |
| "skin", "skincare", "solution", "face", "facial", "glow", "smooth skin", "clear skin", "radiant skin", | |
| "acne", "solutions", "tretmets", "pimple", "blemish", "breakout", "blackhead", "whitehead", "pores", "skin texture", | |
| "oily skin", "dry skin", "combination skin", "sensitive skin", "hydration", "moisturizer", | |
| "serum", "cleanser", "toner", "exfoliation", "exfoliator", "sunscreen", "spf", "anti-aging", | |
| "wrinkle", "fine lines", "crow's feet", "skin tightening", "skin firming", | |
| "chemical peel", "microdermabrasion", "microneedling", "laser treatment", "ipl", "rf treatment", | |
| "prp facial", "hydrafacial", "dermaplaning", "led therapy", "blue light therapy", | |
| "botox", "botulinum", "filler", "dermal filler", "lip filler", "cheek filler", "chin filler", | |
| "jawline filler", "tear trough filler", "nasolabial fold filler", "under-eye filler", | |
| "lip enhancement", "lip augmentation", | |
| "mesotherapy", "skin booster", "profhilo", "biorevitalization", "thread lift", "pdo threads", | |
| "fox eye lift", "facial contouring", "jawline contouring", "skin rejuvenation", "collagen stimulation", | |
| "skin resurfacing", "plasma fibroblast", | |
| "hyperpigmentation", "melasma", "dark spots", "sun spots", "age spots", "skin lightening", | |
| "brightening serum", "niacinamide", "vitamin c serum", | |
| "hair loss", "prp hair", "hair thinning", "scalp treatment", "eyebrow microblading", | |
| "eyelash extensions", "lash lift", "brow lamination", | |
| "body contouring", "body sculpting", "fat freezing", "coolsculpting", "cellulite treatment", | |
| "stretch marks", "skin laxity", "double chin treatment", | |
| "cosmetic", "beauty treatment", "aesthetic procedure", "non-surgical facelift", "skin consultation", | |
| "cosmetic consultation", "dermatology consultation", "aesthetician", "cosmetologist", | |
| # Additional skin types | |
| "normal skin","which","wich", "acne-prone skin", "dehydrated skin", "mature skin", | |
| # Skincare products | |
| "face wash", "face oil", "face mask", "sheet mask", "clay mask", "eye cream", "spot treatment", | |
| "face mist", "micellar water", "facial essence", "night cream", "peeling solution", "lip balm", | |
| # Active ingredients | |
| "retinol", "salicylic acid", "glycolic acid", "lactic acid", "vitamin c", "hyaluronic acid", | |
| "ceramides", "zinc", "bakuchiol", "azelaic acid", "squalane", "tranexamic acid", "kojic acid", | |
| "alpha arbutin", "peptides", "caffeine", "green tea extract", "niacinamide", "allantoin", | |
| # Skin concerns and conditions | |
| "uneven skin tone", "dull skin", "sagging skin", "redness", "rosacea", "eczema", "psoriasis", | |
| "sunburn", "dark circles", "bumpy skin", "skin sensitivity", "keratosis pilaris", "seborrheic dermatitis", | |
| "vitiligo", "actinic keratosis", "perioral dermatitis", "contact dermatitis", "hives", "cold sores", | |
| "shingles", "folliculitis", "milia", "melanoma", "skin cancer", "age spots", "liver spots", | |
| # Beauty tools and devices | |
| "primer", "foundation", "concealer", "bb cream", "cc cream", "setting spray", "setting powder", | |
| "highlighter", "blush", "bronzer", "face roller", "gua sha", "jade roller", "face massager", | |
| "derma roller", "led mask", "pore vacuum", "face steamer", "microcurrent device", "ultrasonic scrubber", | |
| "skin spatula", "ice roller", "facial cleansing brush", | |
| # Skincare routines and practices | |
| "morning skincare routine", "night skincare routine", "double cleansing", "layering skincare", | |
| "skin cycling", "slugging", "glass skin routine", "korean skincare routine", "japanese skincare routine", | |
| "minimalist skincare", "anti-aging skincare routine", "acne skincare routine", "sensitive skin routine", | |
| # Miscellaneous | |
| "non-comedogenic", "fragrance-free", "hypoallergenic", "dermatologist-tested", "cruelty-free", | |
| "vegan skincare", "organic skincare", "natural skincare", "medical-grade skincare", "over-the-counter products", | |
| "prescription skincare", "skincare for men", "skincare for women", "teen skincare", "pregnancy-safe skincare", | |
| "postpartum skincare", "menopausal skincare", "ethnic skincare", "melanin-rich skin care", "skin barrier repair", | |
| "skin microbiome", "pH-balanced skincare", "hydrating skincare", "exfoliating skincare", "brightening skincare", | |
| "firming skincare", "soothing skincare", "calming skincare", "reparative skincare", "preventative skincare", | |
| "targeted treatments", "spot correctors", "eye treatments", "lip treatments", "neck creams", "decollete care", | |
| # Original + Typos | |
| "skin", "skincare", "skincar", "skincrae", "skare", "skarecare", | |
| "solution", "sulotion", "solushun", "solutin", | |
| "face", "fac", "faec", "fce", | |
| "facial", "facail", "fasial", "fascial", | |
| "glow", "glo", "glw", "gllow", | |
| "smooth skin", "smoth skin", "smooh skin", "smoohth skin", | |
| "clear skin", "claer skin", "cler skin", "cleer skin", | |
| "radiant skin", "radient skin", "raidant skin", "radinat skin", | |
| # Acne & Treatment Misspellings | |
| "acne", "acnee", "ackne", "akne", | |
| "solutions", "solutons", "soltions", "sloutions", | |
| "tretmets", "treatments", "tretments", "treatmnts", "trtmnts", | |
| "pimple", "pimle", "pimlpe", "pimmpel", | |
| "blemish", "blemsh", "blemesh", "belmish", | |
| "breakout", "brakeout", "brakout", "breakot", | |
| "blackhead", "blackhed", "blakhead", "blachead", | |
| "whitehead", "witehead", "whithead", "whitehed", | |
| "pores", "poars", "porse", "porrs", | |
| "skin texture", "skin texure", "skin textr", "skin textrure", | |
| # Common Product Misspellings | |
| "moisturizer", "moisturiser", "moisturizr", "moisturizor", | |
| "cleanser", "cleanser", "clenser", "clenaser", "clenserr", | |
| "toner", "tonar", "toaner", "tonner", | |
| "serum", "serrum", "serom", "serun", | |
| "sunscreen", "suncreen", "sunscrean", "sunscern", | |
| "exfoliation", "exfoliaton", "exfolliation", "exfoliatoin", | |
| "retinol", "retinoll", "retonol", "retinl", | |
| "hyaluronic acid", "hyluronic acid", "hylauronic acid", "hyalurinc acid", | |
| # Treatment Terms with Typos | |
| "microneedling", "micronedling", "microneedlin", "microneedlng", | |
| "dermaplaning", "dermaplanning", "dermaplannin", "dermaplaneing", | |
| "botox", "bottox", "botx", "btox", | |
| "filler", "filr", "fillar", "fillr", | |
| "profhilo", "profillo", "profhillo", "prophilo", | |
| "thread lift", "tread lift", "thred lift", "thraed lift", | |
| # Concerns | |
| "hyperpigmentation", "hyperpigmantation", "hyperpigmetation", "hyperpgimentation", | |
| "melasma", "melazma", "melasmaa", "malasma", | |
| "eczema", "eczma", "ezcema", "eczmea", | |
| "rosacea", "rosacia", "rosasa", "rosaccea", | |
| # Actives | |
| "niacinamide", "niacinnamide", "niacinimide", "niacinemide", | |
| "salicylic acid", "salicilic acid", "salicyic acid", "salysilic acid", | |
| "vitamin c", "vitmain c", "vitamin k", "vitamn c", | |
| "glycolic acid", "glycolyc acid", "glycloic acid", "glycoic acid", | |
| # Tools | |
| "gua sha", "goua sha", "guasha", "gwa sha", | |
| "jade roller", "jaderoller", "jade roler", "jdae roller", | |
| "face steamer", "face steemer", "face streamr", "face steemer", | |
| # Devices | |
| "led mask", "led maske", "led maks", "ledmask", | |
| "ice roller", "ice roler", "ice rolr", "ice roaller", | |
| # Routines | |
| "morning skincare routine", "morning skincare routin", "morning skincar routine", "mrning skincare routine", | |
| "night skincare routine", "night skincar routine", "nite skincare routine", "nigh skincare routine", | |
| # Label Claims | |
| "non-comedogenic", "non comedogenic", "non-comidogenic", "non-comedegenic", | |
| "cruelty-free", "crulty-free", "cruelity-free", "crueltyfree", | |
| "fragrance-free", "fragance-free", "fragnance-free", "fragrancefree", | |
| # Demographic | |
| "skincare for men", "skincare for man", "skincar for men", "skincare 4 men", | |
| "teen skincare", "teen skincar", "teen skin care", "teen skncare", | |
| # Conditions | |
| "psoriasis", "psoraisis", "psorasis", "psoriosis", | |
| "vitiligo", "vitilligo", "vitalligo", "vitilago" | |
| ] | |
| def check_keywords(text, keyword_list): | |
| """Helper function to check if any keyword from the list is in the text""" | |
| return any(keyword.lower() in text.lower() for keyword in keyword_list) | |
| def ask_bot(user_question): | |
| # Convert input to lowercase for consistent matching | |
| question_lower = user_question.lower().strip() | |
| # Check for exact greeting matches | |
| if question_lower in [greeting.lower() for greeting in greetings]: | |
| return "Hello!π Welcome to Aesthetic AI β your personal skincare assistant. I'm here to help you with all your skin-related concerns. Let's get started!" | |
| # Check for exact farewell matches | |
| if question_lower in [farewell.lower() for farewell in farewells]: | |
| return "Goodbye! π Wishing you glowing skin and a beautiful day ahead. Come back anytime for skincare help! πββοΈβ¨" | |
| # Check if question contains any skincare keywords | |
| if check_keywords(question_lower, skincare_keywords): | |
| # Pass to the model for response | |
| prompt = f"""You are an expert skincare and aesthetic consultant. Answer the following question based only on skincare and aesthetic knowledge. | |
| Question: {user_question} | |
| Answer:""" | |
| response = chatbot(prompt)[0]["generated_text"] | |
| answer = response.split("Answer:")[-1].strip() | |
| return answer | |
| # If no relevant keywords found | |
| else: | |
| # Use hosted Gradio model | |
| from gradio_client import Client | |
| client = Client("Gajendra5490/SkinChatBot") | |
| result = client.predict( | |
| prompt=user_question, # Pass actual user question | |
| api_name="/predict" | |
| ) | |
| return result | |
| # Gradio interface | |
| iface = gr.Interface( | |
| fn=ask_bot, | |
| inputs=gr.Textbox(lines=2, placeholder="Ask about skin, face, or aesthetic topics..."), | |
| outputs=gr.Textbox(), | |
| title="π§΄ Skin & Aesthetic Chatbot", | |
| description="Ask me anything about skincare, facial treatments, aesthetics! π If your question is unrelated, I will let you know.", | |
| ) | |
| # Launch the app | |
| iface.launch() |