Update app.py
Browse files123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051523 unmodified lines56575859606162636465666768698 unmodified lines78798081828384858687888990919293941 unmodified line969798991001011021031041051061071081095 unmodified lines115116117118119120121122123124125126import gradio as grfrom huggingface_hub import InferenceClient# Initialize the InferenceClientclient = InferenceClient("meta-llama/Llama-3.2-3B-Instruct")def is_health_related(message):# Simple heuristic to check if the message is health-relatedhealth_keywords = ["health", "cancer", "diabetes", "hypertension", "asthma","arthritis", "cardiology", "neurology", "depression","anxiety", "cholesterol", "obesity", "allergies", "autism","osteoporosis", "stroke", "HIV", "AIDS", "hepatitis","tuberculosis", "malaria", "COVID-19", "Parkinson's","Alzheimer's", "dementia", "eczema", "psoriasis", "migraine","epilepsy", "insomnia", "fibromyalgia", "sclerosis","pneumonia", "influenza", "endometriosis", "infertility","glaucoma", "cataracts", "anemia", "leukemia", "lymphoma","melanoma", "dermatitis", "IBS", "Crohn's", "ulcers","GERD", "kidney disease", "liver disease", "cirrhosis","thyroid", "menopause", "prostate", "cholera","dysentery", "polio", "tetanus", "diphtheria","Zika", "Ebola", "mental health", "physical health","immunology", "orthopedics", "pediatrics", "geriatrics","surgery", "rehabilitation", "nutrition", "fitness","wellness", "vaccination", "therapy", "radiology","oncology", "pathology", "psychology", "psychiatry","urology", "gastroenterology", "dermatology", "hematology","toxicology", "pharmacology", "trauma", "injury","burns", "sepsis", "addiction", "substance abuse","symptoms", "diagnosis", "treatment", "medication","medicine", "patient", "healthcare", "hospital","clinic", "recovery", "remedy", "pain management","first aid", "disease prevention", "immunization","primary care", "specialist", "prescription", "chronic illness","acute care", "emergency care", "surgical procedures","therapy sessions", "mental therapy", "physical therapy","health monitoring", "health insurance", "medical advice","health tips", "diagnostic tests", "lab results","consultation", "second opinion", "side effects", "health checkup","disease management", "caregiver support", "home care","alternative medicine", "herbal treatment", "integrative medicine","personalized care", "health records", "online consultation"]message = message.lower()for keyword in health_keywords:if keyword in message:return Truereturn Falsedef respond(message,3 unmodified linestemperature,top_p,):if not is_health_related(message):return "Sorry, I can't help you with that because I am just a bot who can help with health-related queries."messages = [{"role": "system", "content": system_message}]for val in history:if val:messages.append({"role": "user", "content": val})if val[1]:messages.append({"role": "assistant", "content": val[1]})8 unmodified linestemperature=temperature,top_p=top_p,):token = message.choices.delta.contentresponse += tokenyield response# CSS for styling the interfacecss = """body {background-color: #06688E; /* Dark background */color: white; /* Text color for better visibility */}.gr-button {background-color: #42B3CE !important; /* White button color */color: black !important; /* Black text for contrast */1 unmodified linepadding: 8px 16px !important;border-radius: 5px !important;}.gr-button:hover {background-color: #e0e0e0 !important; /* Slightly lighter button on hover */}.gr-slider-container {color: white !important; /* Slider labels in white */}"""demo = gr.ChatInterface(respond,additional_inputs=[5 unmodified linesmaximum=1.0,value=0.95,step=0.05,label="Top-p (nucleus sampling)",visible=False),],css=css, # Pass the custom CSS here)if __name__ == "__main__":demo.launch(share=True)12345678910113 unmodified lines15161718192021222324258 unmodified lines343536373839404142434445464748495051521 unmodified line545556575859606162636465666768697071725 unmodified lines787980818283848586878889import gradio as grfrom huggingface_hub import InferenceClient"""For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference"""client = InferenceClient("meta-llama/Llama-3.2-3B-Instruct")def respond(message,3 unmodified linestemperature,top_p,):messages = [{"role": "system", "content": system_message}]for val in history:if val[0]:messages.append({"role": "user", "content": val[0]})if val[1]:messages.append({"role": "assistant", "content": val[1]})8 unmodified linestemperature=temperature,top_p=top_p,):token = message.choices[0].delta.contentresponse += tokenyield response# CSS for styling the interfacecss = """body {background-color: #06688E; /* Dark background */color: white; /* Text color for better visibility */}.gr-button {background-color: #42B3CE !important; /* White button color */color: black !important; /* Black text for contrast */1 unmodified linepadding: 8px 16px !important;border-radius: 5px !important;}.gr-button:hover {background-color: #e0e0e0 !important; /* Slightly lighter button on hover */}.gr-slider-container {color: white !important; /* Slider labels in white */}""""""For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface"""demo = gr.ChatInterface(respond,additional_inputs=[5 unmodified linesmaximum=1.0,value=0.95,step=0.05,label="Top-p (nucleus sampling)",visible=False),],css=css, # Pass the custom CSS here)if __name__ == "__main__":demo.launch(share=True)
app.py+16-53