henry2024 commited on
Commit
140799d
1 Parent(s): d1dece6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -25
app.py CHANGED
@@ -123,31 +123,32 @@ class_names= {0: 'Acne', 1: 'Arthritis', 2: 'Bronchial Asthma', 3: 'Cervical spo
123
  10: 'Impetigo', 11: 'Jaundice', 12: 'Malaria', 13: 'Migraine', 14: 'Pneumonia', 15: 'Psoriasis', 16: 'Typhoid', 17: 'Varicose Veins', 18: 'allergy', 19: 'diabetes', 20: 'drug reaction',
124
  21: 'gastroesophageal reflux disease', 22: 'peptic ulcer disease', 23: 'urinary tract infection'}
125
  # Disease Advice
 
126
  disease_advice = {
127
- 'Acne': "Maintain a proper skincare routine, avoid excessive touching of the affected areas, and consider using over-the-counter topical treatments. If severe, consult a dermatologist.",
128
- 'Arthritis': "Stay active with gentle exercises, manage weight, and consider pain-relief strategies like hot/cold therapy. Consult a rheumatologist for tailored guidance.",
129
- 'Bronchial Asthma': "Follow prescribed inhaler and medication regimen, avoid triggers like smoke and allergens, and have an asthma action plan. Regular check-ups with a pulmonologist are important.",
130
- 'Cervical spondylosis': "Maintain good posture, do neck exercises, and use ergonomic support. Physical therapy and pain management techniques might be helpful.",
131
- 'Chicken pox': "Rest, maintain hygiene, and avoid scratching. Consult a doctor for appropriate antiviral treatment.",
132
- 'Common Cold': "Get plenty of rest, stay hydrated, and consider over-the-counter remedies for symptom relief. Seek medical attention if symptoms worsen or last long.",
133
- 'Dengue': "Stay hydrated, rest, and manage fever with acetaminophen. Seek medical care promptly, as dengue can escalate quickly.",
134
- 'Dimorphic Hemorrhoids': "Follow a high-fiber diet, maintain good hygiene, and consider stool softeners. Consult a doctor if symptoms persist.",
135
- 'Fungal infection': "Keep the affected area clean and dry, use antifungal creams, and avoid sharing personal items. Consult a dermatologist if it persists.",
136
- 'Hypertension': "Follow a balanced diet, exercise regularly, reduce salt intake, and take prescribed medications. Regular check-ups with a healthcare provider are important.",
137
- 'Impetigo': "Keep the affected area clean, use prescribed antibiotics, and avoid close contact. Consult a doctor for proper treatment.",
138
- 'Jaundice': "Get plenty of rest, maintain hydration, and follow a doctor's advice for diet and medications. Regular monitoring is important.",
139
- 'Malaria': "Take prescribed antimalarial medications, rest, and manage fever. Seek medical attention for severe cases.",
140
- 'Migraine': "Identify triggers, manage stress, and consider pain-relief medications. Consult a neurologist for personalized management.",
141
- 'Pneumonia': "Follow prescribed antibiotics, rest, stay hydrated, and monitor symptoms. Seek immediate medical attention for severe cases.",
142
- 'Psoriasis': "Moisturize, use prescribed creams, and avoid triggers. Consult a dermatologist for effective management.",
143
- 'Typhoid': "Take prescribed antibiotics, rest, and stay hydrated. Dietary precautions are important. Consult a doctor for proper treatment.",
144
- 'Varicose Veins': "Elevate legs, exercise regularly, and wear compression stockings. Consult a vascular specialist for evaluation and treatment options.",
145
- 'allergy': "Identify triggers, manage exposure, and consider antihistamines. Consult an allergist for comprehensive management.",
146
- 'diabetes': "Follow a balanced diet, exercise, monitor blood sugar levels, and take prescribed medications. Regular visits to an endocrinologist are essential.",
147
- 'drug reaction': "Discontinue the suspected medication, seek medical attention if symptoms are severe, and inform healthcare providers about the reaction.",
148
- 'gastroesophageal reflux disease': "Follow dietary changes, avoid large meals, and consider medications. Consult a doctor for personalized management.",
149
- 'peptic ulcer disease': "Avoid spicy and acidic foods, take prescribed medications, and manage stress. Consult a gastroenterologist for guidance.",
150
- 'urinary tract infection': "Stay hydrated, take prescribed antibiotics, and maintain good hygiene. Consult a doctor for appropriate treatment."
151
  }
152
 
153
  howto= """Welcome to the <b>Medical Chatbot</b>, powered by Gradio.
@@ -158,7 +159,7 @@ The bot will respond based on the best possible answers to your messages."""
158
 
159
  # Create the gradio demo
160
  with gr.Blocks(css = """#col_container { margin-left: auto; margin-right: auto;} #chatbot {height: 520px; overflow: auto;}""") as demo:
161
- gr.HTML('<h1 align="center">Medical Chatbot: ARIN 7102 project')
162
  with gr.Accordion("Follow these Steps to use the Gradio WebUI", open=True):
163
  gr.HTML(howto)
164
  chatbot = gr.Chatbot()
 
123
  10: 'Impetigo', 11: 'Jaundice', 12: 'Malaria', 13: 'Migraine', 14: 'Pneumonia', 15: 'Psoriasis', 16: 'Typhoid', 17: 'Varicose Veins', 18: 'allergy', 19: 'diabetes', 20: 'drug reaction',
124
  21: 'gastroesophageal reflux disease', 22: 'peptic ulcer disease', 23: 'urinary tract infection'}
125
  # Disease Advice
126
+
127
  disease_advice = {
128
+ 'Acne': "Acne, commonly referred to as \"acne vulgaris\" or \"pimples,\" is a prevalent skin condition that primarily affects teenagers and young adults but can occur at any age. Acne typically appears on the face, back, and chest, particularly in areas with active sebaceous glands. It manifests as skin bumps, comedones, blackheads, whiteheads, and sometimes pustules. You can use topical medications such as benzoyl peroxide, salicylic acid, topical antibiotics, and retinoids (like tretinoin), or oral medications such as antibiotics (like tetracycline and erythromycin), oral contraceptives (which may help some women), and oral retinoids (such as isotretinoin) for improvement. When using these medications on your own, it is essential to follow the prescription and instructions of a doctor. At the same time, in your daily life, it is important to maintain a proper skincare routine, avoid excessive touching of the affected areas, minimize the intake of high-sugar and high-fat foods, and consume more fruits, vegetables, and whole grains.",
129
+ 'Arthritis': "Arthritis is a term that refers to a variety of joint diseases, involving pain and inflammation in the joints. Common types include osteoarthritis (OA) and rheumatoid arthritis (RA). Osteoarthritis is caused by the wear and tear of joint cartilage, while rheumatoid arthritis is an autoimmune disease. You can use nonsteroidal anti-inflammatory drugs (NSAIDs) and analgesics such as ibuprofen or naproxen, acetaminophen (paracetamol), etc., to reduce inflammation and relieve pain. Corticosteroid medications like prednisone can be used for rapid inflammation relief but have potential side effects with long-term use. For rheumatoid arthritis, disease-modifying antirheumatic drugs (DMARDs) like methotrexate can be used to slow disease progression. When using these medications, it is crucial to follow the prescription and instructions of a doctor. In daily life, it is important to maintain a healthy weight, engage in moderate exercise, follow a healthy diet, avoid joint injuries, ensure adequate rest, and avoid overusing the joints.",
130
+ 'Bronchial Asthma': "Bronchial Asthma is a chronic inflammatory respiratory disease characterized by recurrent episodes of wheezing, chest tightness, and difficulty breathing. To control and prevent asthma symptoms and attacks over the long term, you can use inhaled corticosteroids (such as fluticasone), long-acting beta2 agonists (such as salmeterol), leukotriene receptor antagonists (such as montelukast), and immunomodulators (such as omalizumab); for urgent situations requiring rapid relief of symptoms during an attack, you can use inhaled short-acting beta2 agonists (such as albuterol) or oral or intravenous corticosteroids (for severe attacks). When taking these medications, follow the prescription and guidance of a doctor, and do not change the dosage or discontinue on your own. In daily life, it is important to avoid known triggers, such as tobacco smoke and dust mites, pay attention to outdoor air quality forecasts, engage in regular appropriate exercise, maintain a healthy lifestyle, and manage stress effectively.",
131
+ 'Cervical spondylosis': "Cervical spondylosis is a common degenerative condition that increases with age and affects the vertebrae and intervertebral discs of the cervical spine. Treatment options include medication with nonsteroidal anti-inflammatory drugs (NSAIDs) such as ibuprofen, as well as physical therapy where a therapist guides the patient through specific exercises. Alternative therapies such as acupuncture, massage, and spinal manipulation may also be considered. For prevention or improvement of cervical spondylosis, it is important to maintain good posture, take regular breaks and change positions frequently, engage in exercises to strengthen and improve the flexibility of neck muscles, maintain a healthy weight, ensure quality sleep, and use an appropriate pillow.",
132
+ 'Chicken pox': "Chickenpox is a contagious disease caused by the varicella-zoster virus (VZV). It typically affects children but can also occur in unvaccinated adults. The characteristic symptoms of chickenpox include an itchy, blister-like rash across the body, which may be accompanied by fever, fatigue, and loss of appetite. For most healthy children, chickenpox usually doesn't require special treatment as it tends to resolve on its own within about two weeks. However, for certain groups such as adults, pregnant women, and people with weakened immune systems, antiviral medications like acyclovir may be used, as well as antihistamines to reduce itching and acetaminophen to relieve pain and fever. It is important to always follow the doctor's instructions when taking medication. In terms of prevention, vaccination is the most effective measure against chickenpox. Additionally, since chickenpox is spread through droplets, avoiding contact with infected individuals can prevent transmission. Maintaining good personal hygiene and frequent handwashing are also important in preventing the spread of the virus.",
133
+ 'Common Cold': "The common cold, often simply referred to as a cold, is an extremely common minor respiratory infection. There is no cure for the common cold, and treatment primarily involves symptom relief. Over-the-counter medications such as acetaminophen (to reduce pain and fever), antihistamines (to alleviate sneezing, nasal congestion, and runny nose), and cough suppressants are commonly used. In daily life, personal hygiene is important, including frequent handwashing and avoiding close contact with carriers of the cold virus. A balanced diet, regular exercise, and sufficient sleep contribute to a healthy lifestyle that can help boost immunity.",
134
+ 'Dengue': "Dengue fever is a tropical infectious disease caused by the dengue virus, primarily transmitted through the bites of Aedes mosquitoes, such as Aedes aegypti or Aedes albopictus. Symptoms may include high fever, severe headache, pain in the muscles and joints, rash, nausea, and vomiting. Symptoms typically appear 5 to 7 days after the bite and can last about a week. There is no specific treatment for dengue fever. Treatment is mainly supportive and symptomatic, starting with ensuring adequate rest to aid the body's recovery. To prevent dehydration, it is important to consume plenty of fluids and electrolytes. Acetaminophen (Paracetamol) can be used to control fever and relieve pain, but aspirin or non-steroidal anti-inflammatory drugs (NSAIDs) should be avoided as they may increase the risk of bleeding. During treatment, it is crucial to follow medical advice strictly, and if symptoms worsen, such as subcutaneous bleeding, persistent vomiting, or severe abdominal pain, medical help should be sought immediately. In everyday life, to prevent dengue fever, one should avoid mosquito bites by using mosquito nets, wearing long-sleeved clothing, applying insect repellent, etc., and also eliminate standing water near living areas to prevent mosquito breeding.",
135
+ 'Dimorphic Hemorrhoids': "Hemorrhoids are the pathological dilation of vascular structures in the anal canal, which can sometimes lead to pain, bleeding, and swelling. Treatment for hemorrhoids typically includes lifestyle changes, medication such as topical ointments, creams, or suppositories, and in more severe cases, surgical interventions like rubber band ligation, sclerotherapy, laser treatment, or conventional surgical excision. When undergoing treatment, please follow the guidance of a professional doctor. Additionally, in daily life, it is advisable to eat a diet rich in fiber, ensure adequate fluid intake, avoid sitting for prolonged periods, and avoid straining during bowel movements.",
136
+ 'Fungal infection': "Fungal infections are caused by a variety of fungi and typically result in symptoms such as itching, redness, peeling, rashes, and sometimes pain. Topical antifungal medications, such as clotrimazole and terbinafine ointments or creams, can be used to treat skin fungal infections. For more severe infections or those affecting internal organs, oral medications like fluconazole or itraconazole may be required. For specific areas, such as vaginal yeast infections, vaginal suppositories or oral medications may be necessary. It is essential to consult a doctor or pharmacist before using any medication. In daily life, maintaining personal hygiene and keeping the body dry, wearing breathable clothing, avoiding direct contact, eating a balanced diet, and reducing sugar intake can help prevent and alleviate fungal infections.",
137
+ 'Hypertension': "Hypertension, commonly known as high blood pressure, is a prevalent chronic condition where the blood pressure in the arteries is persistently elevated above normal levels. Long-term hypertension increases the risk of health issues such as heart disease, stroke, and kidney disease. The following medications can be considered for treatment: diuretics, beta-blockers, calcium channel blockers, angiotensin-converting enzyme (ACE) inhibitors, and angiotensin II receptor blockers (ARBs). It is important to consult a doctor before taking any medication and to monitor blood pressure changes regularly during treatment. In daily life, it is recommended to reduce salt intake, limit alcohol consumption, increase the intake of vegetables and fruits, maintain a healthy weight to reduce the burden on the heart, control weight, and quit smoking.",
138
+ 'Impetigo': "Impetigo is a common superficial bacterial infection characterized by the appearance of blisters and pus-filled lesions on the skin, which then burst and form yellow crusts. Topical medications such as mupirocin ointment can be applied directly to the infected area. If the infection is severe or widespread, oral antibiotics like amoxicillin or other drugs targeting specific bacteria may be used. Before using any medication, it is essential to consult a doctor. In daily life, it is important to maintain personal hygiene, keep the skin dry and clean, promptly clean and protect minor wounds, and avoid contact with infected individuals.",
139
+ 'Jaundice': "Jaundice is a symptom caused by an elevated level of bilirubin in the blood, which typically results in a yellow discoloration of the skin and eyes. Treatment for jaundice requires addressing the underlying cause, and possible treatments include antiviral or antibiotic therapy, surgery or other procedures to remove stones, discontinuing the use of related drugs, and taking measures to protect the liver. During treatment, it is important to follow the doctor's guidance and medication prescriptions. Methods to prevent jaundice generally involve protecting the liver and maintaining a healthy lifestyle, which includes avoiding excessive alcohol consumption, taking preventive measures to avoid hepatitis virus infections, such as getting vaccinated and avoiding contact with the blood and bodily fluids of infected individuals, and maintaining a healthy diet.",
140
+ 'Malaria': "Malaria is an infectious disease caused by the malaria parasite and transmitted to humans through mosquito bites. Symptoms of malaria include fever, chills, headache, muscle and joint pain, fatigue, and anemia. The primary treatment for malaria involves antimalarial drugs, with commonly used medications including chloroquine, quinine, artemether, and amodiaquine. It is important to follow the doctor's advice and prescription when using antimalarial drugs. In daily life, you can take the following preventive measures to avoid malaria: avoiding mosquito bites, getting vaccinated against malaria if available, and using mosquito repellents.",
141
+ 'Migraine': "Migraine is a neurological disorakder characterized by recurrent episodes of headache. Treatment options for migraine include acute therapies, such as over-the-counter medications like nonsteroidal anti-inflammatory drugs (e.g., ibuprofen, aspirin), and preventive therapies, including tricyclic antidepressants, beta blockers, and antiepileptic drugs. When using medication for treatment, it is important to follow the doctor's advice and prescription. In daily life, you can take the following preventive measures to reduce the occurrence of migraines: maintaining a regular sleep schedule, identifying and avoiding personal triggers such as specific foods, emotional stress, and weather changes, maintaining a balanced diet, and avoiding excessive alcohol and caffeine consumption.",
142
+ 'Pneumonia': "Pneumonia is an infection of the lungs, typically caused by bacteria, viruses, or fungi. It can lead to difficulty breathing, coughing, fever, and sometimes chest pain. The treatment for pneumonia depends on the type of pathogen, as well as the patient's age, health condition, and the severity of symptoms. Bacterial pneumonia is usually treated with antibiotics such as penicillin, amoxicillin, azithromycin, or rifampin, while viral pneumonia may require antiviral medications like oseltamivir. Fungal pneumonia necessitates the use of antifungal medications, such as fluconazole or itraconazole. When taking any medication, it is important to follow the doctor's prescription. Here are some measures to prevent pneumonia, including regular vaccinations like the flu shot and pneumococcal vaccine, frequent hand washing, and maintaining healthy lifestyle habits.",
143
+ 'Psoriasis': "Psoriasis is a chronic autoimmune disease that causes excessive growth of skin cells, resulting in symptoms such as red patches, scales, and itchiness. This condition can affect any part of the body, but it is most commonly found on the scalp, elbows, knees, palms, and soles of the feet. Treatment options for Psoriasis include topical medications (such as corticosteroid creams, vitamin D analogues, keratolytics, and anti-inflammatory drugs), phototherapy, and systemic medications. It is important to follow the doctor's advice and prescription when using medication. In daily life, you can take the following preventive measures to reduce the occurrence and alleviate the symptoms of Psoriasis: maintaining a healthy lifestyle, avoiding stress, excessive tension, skin injuries, and infections, and keeping the skin clean and moisturized.",
144
+ 'Typhoid': "Typhoid is a serious bacterial infection caused by the bacterium Yersinia pestis. Treatment for plague typically requires the use of antibiotics such as streptomycin, doxycycline, and gentamicin sulfate. When using antibiotics to treat plague, it is important to strictly follow the doctor's instructions for medication. The key to preventing typhoid is to avoid contact with potentially infected fleas and animals.",
145
+ 'Varicose Veins': "Varicose Veins is a common vascular condition that primarily affects the veins in the lower limbs. Treatment options for Varicose Veins include compression therapy, medication (such as pain relievers and non-steroidal anti-inflammatory drugs (NSAIDs), and surgical interventions. It is important to follow the doctor's advice when using medication. In daily life, you can take the following preventive measures to reduce the occurrence of Varicose Veins, such as maintaining a healthy weight, exercising, and avoiding tight-fitting clothing.",
146
+ 'allergy': "Allergies occur when your immune system overreacts to typically harmless substances known as allergens, such as pollen, dust mites, pet dander, certain foods, or medications. This reaction can lead to a variety of symptoms, including sneezing, runny nose, itchy skin, redness of the eyes, and swelling. Treatment for allergies depends on the type and severity of the allergic reaction. Common medications include antihistamines, nasal sprays, and eye drops. When taking allergy medication, it is important to strictly follow the doctor's prescription instructions. The key to preventing allergies is to avoid contact with known allergens, understand and avoid the foods or substances that trigger your allergic reactions, regularly clean your home, and minimize outdoor activities during pollen season.",
147
+ 'diabetes': "Diabetes is a chronic condition characterized by abnormally high levels of blood sugar (glucose). There are primarily two types of diabetes: Type 1 Diabetes: Usually occurs in children or young adults. Type 2 Diabetes: More common and associated with age, body weight, and lifestyle. Medical Treatment includes patients with Type 1 diabetes require lifelong insulin injections to control blood sugar levels. Those with Type 2 diabetes may need oral medications, such as Metformin, and sometimes insulin or other injectable medications as well. When taking diabetes medications, it is important to follow the doctor's instructions and not change the dosage on your own. While Type 1 diabetes cannot be prevented, the risk of developing Type 2 diabetes can be reduced by maintaining a healthy weight, eating a balanced diet. Regularly exercising and increasing physical activity, regularly checking blood sugar levels, especially if there is a family history of diabetes.",
148
+ 'drug reaction': "A drug reaction refers to an adverse response or side effects that occur after taking a specific medication. These reactions can range from mild to severe and may include symptoms such as rashes, hives, fever, joint pain, difficulty breathing, swelling, among others. In some cases, a drug reaction can lead to anaphylactic shock, an emergency situation that requires immediate medical attention. The treatment for a drug reaction depends on the severity of the reaction and the specific symptoms. Mild reactions, such as rashes or hives, may only require antihistamines, while severe reactions, like difficulty breathing or anaphylactic shock, require urgent medical intervention. When dealing with a drug reaction, it is important to immediately discontinue the medication that caused the reaction and contact your doctor. Measures to prevent drug reactions include: informing your doctor of all known drug allergies and past drug reactions before starting any new medication, carefully reading the medication's instructions to understand potential side effects, and following the doctor's prescription guidance without altering the dosage or discontinuing the medication on your own.",
149
+ 'gastroesophageal reflux disease': "Gastroesophageal reflux disease (GERD) is a common digestive disorder characterized by the backflow of stomach acids or contents into the esophagus, causing symptoms and/or complications. Common symptoms include a burning sensation behind the breastbone (heartburn), sour taste in the mouth, difficulty swallowing, sore throat, or cough. Treatment for GERD may involve lifestyle changes and medication, with primary drugs including proton pump inhibitors (PPIs), H2 receptor antagonists, antacids, and prokinetics. It is important to strictly follow the doctor's prescription and guidance when using medications. Measures to prevent gastroesophageal reflux disease include maintaining a healthy weight, avoiding overeating, reducing or avoiding consumption of irritant foods and beverages, quitting smoking, and avoiding tight-fitting clothing.",
150
+ 'peptic ulcer disease': "Peptic ulcer disease (PUD) refers to damage to the inner lining of the stomach or duodenum (the beginning part of the small intestine), resulting in ulcers. Common symptoms include upper abdominal pain, discomfort after eating, nausea, vomiting, or weight loss. Treatment for stomach ulcers typically involves a combination of medications, such as antacids, acid secretion inhibitors, antibiotics, and mucosal protectants. It is essential to consult with a healthcare professional for an accurate diagnosis and personalized treatment. To prevent peptic ulcer disease, measures include avoiding excessive use of nonsteroidal anti-inflammatory drugs (NSAIDs), regulating your diet to avoid excessive intake of spicy, fatty, or acidic foods, quitting smoking and limiting alcohol consumption, and maintaining good hygiene practices.",
151
+ 'urinary tract infection': "Urinary tract infections (UTIs) refer to infections in any part of the urinary system, which includes the kidneys, ureters, bladder, and urethra. UTIs are commonly caused by bacteria, particularly Escherichia coli (E. coli). Symptoms may include a strong urge to urinate, frequent urination, pain in the lower abdomen, cloudy or bloody urine, and a strong odor to the urine. The common treatment for a UTI is the use of antibiotics, such as amoxicillin, nitrofurantoin, and trimethoprim/sulfamethoxazole. To prevent UTIs, it is recommended to maintain adequate fluid intake, wear breathable cotton underwear, and practice other hygiene measures."
152
  }
153
 
154
  howto= """Welcome to the <b>Medical Chatbot</b>, powered by Gradio.
 
159
 
160
  # Create the gradio demo
161
  with gr.Blocks(css = """#col_container { margin-left: auto; margin-right: auto;} #chatbot {height: 520px; overflow: auto;}""") as demo:
162
+ gr.HTML('<h1 align="center"> Medical Chatbot: ARIN 7102 project 🌟🏥🤖 (RNN/GRU + TfidfVectorizer in sklearn)') # (Phi-2 + bge-small-en-v1.5) # (RNN/GRU + TfidfVectorizer in sklearn)
163
  with gr.Accordion("Follow these Steps to use the Gradio WebUI", open=True):
164
  gr.HTML(howto)
165
  chatbot = gr.Chatbot()