{
"cells": [
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"import time\n",
"import os\n",
"import csv\n",
"from bs4 import BeautifulSoup\n",
"import requests\n",
"from tqdm import tqdm\n",
"from IPython.display import clear_output"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"\n",
"def data_extractor(base_url, retries=3, delay=5):\n",
" headers = {\n",
" \"User-Agent\": \"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36\",\n",
" \"Accept\": \"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8\"\n",
" }\n",
"\n",
" diagnosis_treatment_link = \"\"\n",
" doctors_departments_link = \"\"\n",
"\n",
" for attempt in range(retries):\n",
" try:\n",
" response = requests.get(base_url, headers=headers, timeout=20)\n",
" response.raise_for_status()\n",
" soup = BeautifulSoup(response.text, \"html.parser\")\n",
"\n",
" # Extract Diagnosis & Treatment link\n",
" content1 = soup.find('a', id=\"et_genericNavigation_diagnosis-treatment\")\n",
" if not content1:\n",
" # fallback: search by link text containing both words\n",
" for a in soup.find_all('a'):\n",
" link_text = a.get_text(separator=' ').strip().lower()\n",
" if \"diagnosis\" in link_text and \"treatment\" in link_text:\n",
" content1 = a\n",
" break\n",
" if content1:\n",
" href1 = content1.get('href')\n",
" diagnosis_treatment_link = f\"https://www.mayoclinic.org{href1}\" if href1 and href1.startswith(\"/\") else href1\n",
"\n",
" # Extract Doctors & Departments link\n",
" content2 = soup.find('a', id=\"et_genericNavigation_doctors-departments\")\n",
" if not content2:\n",
" # fallback: search by link text containing both words\n",
" for a in soup.find_all('a'):\n",
" link_text = a.get_text(separator=' ').strip().lower()\n",
" if \"doctors\" in link_text and \"departments\" in link_text:\n",
" content2 = a\n",
" break\n",
" if content2:\n",
" href2 = content2.get('href')\n",
" doctors_departments_link = f\"https://www.mayoclinic.org{href2}\" if href2 and href2.startswith(\"/\") else href2\n",
"\n",
" break # success, exit retry loop\n",
"\n",
" except requests.exceptions.RequestException as e:\n",
" print(f\"[Attempt {attempt + 1}] Error fetching {base_url}: {e}\")\n",
" if attempt < retries - 1:\n",
" time.sleep(delay)\n",
"\n",
" return diagnosis_treatment_link, doctors_departments_link\n",
"\n",
"def web_scraping(base_url):\n",
" # Define the expected headers in order\n",
" expected_headers = [\"disease\", \"main_link\", \"Diagnosis_treatment_link\", \"Doctors_departments_link\"]\n",
"\n",
" # Check if file exists and read existing headers if it does\n",
" file_exists = os.path.isfile(\"mayo_diseases.csv\")\n",
" existing_headers = []\n",
"\n",
" if file_exists:\n",
" with open(\"mayo_diseases.csv\", \"r\", encoding=\"utf-8\") as file:\n",
" reader = csv.reader(file)\n",
" existing_headers = next(reader, [])\n",
"\n",
" # Determine if we need to write headers\n",
" write_headers = not file_exists or existing_headers != expected_headers\n",
"\n",
" # Get the webpage content\n",
" response = requests.get(base_url)\n",
" if response.status_code != 200:\n",
" print(\"Failed to retrieve page\")\n",
" exit()\n",
"\n",
" soup = BeautifulSoup(response.text, \"html.parser\")\n",
" items = soup.select(\".cmp-results-with-primary-name__see-link, .cmp-results-with-primary-name a\")\n",
"\n",
" with open(\"mayo_diseases.csv\", \"a\", newline=\"\", encoding=\"utf-8\") as file:\n",
" writer = csv.writer(file)\n",
"\n",
" # Write headers if needed\n",
" if write_headers:\n",
" writer.writerow(expected_headers)\n",
"\n",
" for item in tqdm(items, desc=\"Scraping Diseases\"):\n",
" disease_name = item.text.strip()\n",
" main_link = f\"https://www.mayoclinic.org{item['href']}\" if item['href'].startswith(\"/\") else item['href']\n",
"\n",
" link1, link2 = data_extractor(main_link)\n",
"\n",
" # Create a row with all expected columns\n",
" row_data = {\n",
" \"disease\": disease_name,\n",
" \"main_link\": main_link,\n",
" \"Diagnosis_treatment_link\": link1,\n",
" \"Doctors_departments_link\": link2\n",
" }\n",
"\n",
" # If appending to existing file with different headers, align data with existing headers\n",
" if file_exists and existing_headers:\n",
" row = [row_data.get(header, \"\") for header in existing_headers]\n",
" else:\n",
" row = [row_data[header] for header in expected_headers]\n",
"\n",
" writer.writerow(row)\n",
"\n",
" print(\"Scraping Completed! Data Saved\")\n",
"\n",
"# Example usage:\n",
"# web_scraping(\"https://www.mayoclinic.org/diseases-conditions\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Scraping Diseases: 100%|██████████| 132/132 [00:48<00:00, 2.75it/s]"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Scraping Completed! Data Saved\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"\n"
]
}
],
"source": [
"base_url = f\"https://www.mayoclinic.org/diseases-conditions/index?letter=A\"\n",
"web_scraping(base_url)\n"
]
},
{
"cell_type": "code",
"execution_count": 20,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"overview\n",
"Eggs are one of the most common allergy-causing foods for children.\n",
"\n",
"Egg allergy symptoms usually occur a few minutes to a few hours after eating eggs or foods containing eggs. Signs and symptoms range from mild to severe and can include skin rashes, hives, nasal congestion, and vomiting or other digestive problems. Rarely, egg allergy can cause anaphylaxis — a life-threatening reaction.\n",
"\n",
"Egg allergy can occur as early as infancy. Most children, but not all, outgrow their egg allergy before adolescence.\n",
"symptoms\n",
"Egg allergy reactions vary from person to person and usually occur soon after exposure to egg. Egg allergy symptoms can include:\n",
"when-to-see-a-doctor\n",
"See a doctor if you or your child has signs or symptoms of a food allergy shortly after eating eggs or an egg-containing product. If possible, see the doctor when the allergic reaction is occurring. This may help in making a diagnosis.\n",
"\n",
"If you or your child has signs and symptoms of anaphylaxis, seek immediate emergency treatment and use an autoinjector if one has been prescribed.\n",
"causes\n",
"An immune system overreaction causes food allergies. For egg allergy, the immune system mistakenly identifies certain egg proteins as harmful. When you or your child comes in contact with egg proteins, immune system cells (antibodies) recognize them and signal the immune system to release histamine and other chemicals that cause allergic signs and symptoms.\n",
"\n",
"Both egg yolks and egg whites contain proteins that can cause allergies, but allergy to egg whites is most common. It's possible for breast-fed infants to have an allergic reaction to egg proteins in breast milk if the mother consumes eggs.\n",
"complications\n",
"The most significant complication of egg allergy is having a severe allergic reaction requiring an epinephrine injection and emergency treatment.\n",
"\n",
"The same immune system reaction that causes egg allergy can also cause other conditions. If you or your child has egg allergy, you or your child may be at increased risk of:\n",
"prevention\n",
"Here are some things you can do to avoid an allergic reaction, and to keep it from getting worse if one does occur.\n",
"risk-factors\n",
"Certain factors can increase the risk of developing egg allergy:\n"
]
}
],
"source": [
"from bs4 import BeautifulSoup\n",
"\n",
"\n",
"base_url=\"https://www.mayoclinic.org/diseases-conditions/egg-allergy/symptoms-causes/syc-20372115\"\n",
"headers = {\n",
" \"User-Agent\": \"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36\",\n",
" \"Accept\": \"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8\"\n",
" }\n",
"response = requests.get(base_url, headers=headers, timeout=20)\n",
"response.raise_for_status()\n",
"soup = BeautifulSoup(response.text, 'html.parser')\n",
"extraction_list = [\"overview\",\"symptoms\",\"when-to-see-a-doctor\",\"causes\",\"complications\",\"prevention\",\"risk-factors\"]\n",
"\n",
"for i in extraction_list:\n",
"# Find the overview section by its aria-labelledby attribute\n",
" overview_section = soup.find('section', {'aria-labelledby': i})\n",
"\n",
"# Extract all paragraph text from the overview content\n",
" overview_content = overview_section.find('div', class_='cmp-text__rich-content')\n",
" overview_paragraphs = [p.get_text() for p in overview_content.find_all('p')]\n",
"\n",
"# Join paragraphs into a single string\n",
" overview_text = '\\n\\n'.join(overview_paragraphs)\n",
" print(i)\n",
" print(overview_text)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Overview section not found\n"
]
}
],
"source": [
"from bs4 import BeautifulSoup\n",
"\n",
"def extract_overview(html_content):\n",
" headers = {\n",
" \"User-Agent\": \"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36\",\n",
" \"Accept\": \"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8\"\n",
" }\n",
" response = requests.get(base_url, headers=headers, timeout=20)\n",
" response.raise_for_status()\n",
" soup = BeautifulSoup(response.text, 'html.parser')\n",
"\n",
" # Find the Overview section - looking for h2 with text \"Overview\"\n",
" overview_header = soup.find(lambda tag: tag.name == 'h2' and 'when-to-see-a-doctor\"' in tag.text)\n",
"\n",
" if not overview_header:\n",
" return \"Overview section not found\"\n",
"\n",
" # Initialize overview paragraphs\n",
" overview_paragraphs = []\n",
"\n",
" # Get all siblings after the h2 until the next h2\n",
" for sibling in overview_header.find_next_siblings():\n",
" if sibling.name == 'h2':\n",
" break # Stop when we reach the next section\n",
" if sibling.name == 'p':\n",
" overview_paragraphs.append(sibling.get_text(strip=True))\n",
"\n",
" if not overview_paragraphs:\n",
" return \"No overview content found\"\n",
"\n",
" return '\\n\\n'.join(overview_paragraphs)\n",
"\n",
"# Example usage:\n",
"base_url=\"https://www.mayoclinic.org/diseases-conditions/hyperhidrosis/symptoms-causes/syc-20367152\"\n",
"\n",
"html_content = \"\"\" (your HTML content here) \"\"\"\n",
"overview_text = extract_overview(base_url)\n",
"print(overview_text)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"=== OVERVIEW ===\n",
"Hyperhidrosis (hi-pur-hi-DROE-sis) is excessive sweating that's not always related to heat or exercise. You may sweat so much that it soaks through your clothes or drips off your hands. Heavy sweating can disrupt your day and cause social anxiety and embarrassment.\n",
"Hyperhidrosis treatment usually helps. It often begins with antiperspirants. If these don't help, you may need to try different medications and therapies. In severe cases, your health care provider may suggest surgery to remove the sweat glands or to disconnect the nerves related to producing too much sweat.\n",
"Sometimes an underlying condition may be found and treated.\n",
"\n",
"==================================================\n",
"\n",
"=== SYMPTOMS ===\n",
"The main symptom of hyperhidrosis is heavy sweating. This goes beyond the sweating from being in a hot environment, exercising, or feeling anxious or stressed. The type of hyperhidrosis that usually affects the hands, feet, underarms or face causes at least one episode a week when you're awake. And the sweating usually happens on both sides of the body.\n",
"\n",
"==================================================\n",
"\n",
"=== WHEN TO SEE A DOCTOR ===\n",
"Sometimes excessive sweating is a sign of a serious condition.\n",
"Seek immediate medical attentionif you have heavy sweating with dizziness, pain in the chest, throat, jaw, arms, shoulders or throat, or cold skin and a rapid pulse.\n",
"See your health care provider if:\n",
"Sweating disrupts your daily routine\n",
"Sweating causes emotional distress or social withdrawal\n",
"You suddenly begin to sweat more than usual\n",
"You experience night sweats for no apparent reason\n",
"\n",
"==================================================\n",
"\n",
"=== CAUSES ===\n",
"Sweating is the body's mechanism to cool itself. The nervous system automatically triggers sweat glands when your body temperature rises. Sweating also occurs, especially on your palms, when you're nervous.\n",
"Primary hyperhidrosis is caused by faulty nerve signals that trigger eccrine sweat glands to become overactive. It usually affects the palms, soles, underarms and sometimes the face.\n",
"There is no medical cause for this type of hyperhidrosis. It can run in families.\n",
"Secondary hyperhidrosis is caused by an underlying medical condition or by taking certain medications, such as pain relievers, antidepressants, and some diabetes and hormonal medications. This type of hyperhidrosis may cause sweating all over the body. Conditions that might cause it include:\n",
"Diabetes\n",
"Menopause hot flashes\n",
"Thyroid problems\n",
"Some types of cancer\n",
"Nervous system disorders\n",
"Infections\n",
"\n",
"==================================================\n",
"\n",
"=== RISK FACTORS ===\n",
"Risk factors for hyperhidrosis include:\n",
"Having a blood relative, such as a parent, sibling or grandparent, who sweats heavily\n",
"Taking medicines or supplements that cause sweating\n",
"Having a medical condition that causes sweating\n",
"\n",
"==================================================\n",
"\n",
"=== COMPLICATIONS ===\n",
"Complications of hyperhidrosis include:\n",
"Infections.People who sweat a lot are more prone to skin infections.\n",
"Social and emotional effects.Having clammy or dripping hands and sweat-soaked clothes can be embarrassing. Your condition may affect your pursuit of work and educational goals.\n",
"\n",
"==================================================\n",
"\n"
]
}
],
"source": [
"from bs4 import BeautifulSoup\n",
"import requests\n",
"\n",
"def extract_mayo_clinic_sections(url):\n",
" headers = {\n",
" \"User-Agent\": \"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36\",\n",
" \"Accept\": \"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8\"\n",
" }\n",
"\n",
" try:\n",
" response = requests.get(url, headers=headers, timeout=20)\n",
" response.raise_for_status()\n",
" soup = BeautifulSoup(response.text, 'html.parser')\n",
"\n",
" main_content = soup.find('div', class_='content')\n",
" if not main_content:\n",
" return {\"error\": \"Main content not found\"}\n",
"\n",
" sections = {\n",
" \"Overview\": None,\n",
" \"Symptoms\": None,\n",
" \"When to see a doctor\": None,\n",
" \"Causes\": None,\n",
" \"Risk factors\": None,\n",
" \"Complications\": None,\n",
" \"Prevention\": None\n",
" }\n",
"\n",
" # Find all headings (h2 and h3)\n",
" headings = main_content.find_all(['h2', 'h3'])\n",
"\n",
" for heading in headings:\n",
" heading_text = heading.get_text(strip=True)\n",
"\n",
" # Handle the typo \"dotor\" in the HTML\n",
" if \"When to see a dotor\" in heading_text:\n",
" heading_text = \"When to see a doctor\"\n",
"\n",
" if heading_text in sections:\n",
" content = []\n",
" next_node = heading.next_sibling\n",
"\n",
" # Collect content until next heading\n",
" while next_node and next_node.name not in ['h2', 'h3']:\n",
" if next_node.name == 'p':\n",
" content.append(next_node.get_text(strip=True))\n",
" elif next_node.name in ['ul', 'ol']:\n",
" items = [li.get_text(strip=True) for li in next_node.find_all('li')]\n",
" content.extend(items)\n",
" next_node = next_node.next_sibling\n",
"\n",
" sections[heading_text] = '\\n'.join(content) if content else \"No content found\"\n",
"\n",
" return {k: v for k, v in sections.items() if v is not None}\n",
"\n",
" except requests.exceptions.RequestException as e:\n",
" return {\"error\": f\"Failed to fetch page: {str(e)}\"}\n",
"\n",
"# Example usage:\n",
"url = \"https://www.mayoclinic.org/diseases-conditions/hyperhidrosis/symptoms-causes/syc-20367152\"\n",
"sections = extract_mayo_clinic_sections(url)\n",
"\n",
"for section_name, content in sections.items():\n",
" print(f\"=== {section_name.upper()} ===\")\n",
" print(content)\n",
" print(\"\\n\" + \"=\"*50 + \"\\n\")"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Processing: Atrioventricular nodal reentry tachycardia (AVNRT)\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"100%|██████████| 132/132 [01:09<00:00, 1.90it/s]"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"CSV file updated successfully with 132 rows\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"\n"
]
}
],
"source": [
"import csv\n",
"from bs4 import BeautifulSoup\n",
"import requests\n",
"import os\n",
"from tqdm import tqdm\n",
"\n",
"def extract_sections(url):\n",
" headers = {\n",
" \"User-Agent\": \"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36\",\n",
" \"Accept\": \"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8\"\n",
" }\n",
"\n",
" try:\n",
" response = requests.get(url, headers=headers, timeout=20)\n",
" response.raise_for_status()\n",
" soup = BeautifulSoup(response.text, 'html.parser')\n",
"\n",
" # Try different possible main content containers\n",
" main_content = soup.find('div', class_='content') or soup.find('article', id='main-content')\n",
" if not main_content:\n",
" return {} # Don't return error; just skip\n",
"\n",
" # Section headings you want\n",
" sections = {\n",
" \"Overview\": None,\n",
" \"Symptoms\": None,\n",
" \"When to see a doctor\": None,\n",
" \"Causes\": None,\n",
" \"Risk factors\": None,\n",
" \"Complications\": None,\n",
" \"Prevention\": None\n",
" }\n",
"\n",
" # Find all headings inside main content\n",
" headings = main_content.find_all(['h2', 'h3'])\n",
" for idx, heading in enumerate(headings):\n",
" heading_text = heading.get_text(strip=True)\n",
" # Fix potential typo in heading\n",
" if \"When to see a dotor\" in heading_text:\n",
" heading_text = \"When to see a doctor\"\n",
" # If it's a section we care about\n",
" if heading_text in sections:\n",
" # Gather all paragraph and list content until next heading\n",
" content = []\n",
" next_node = heading.find_next_sibling()\n",
" while next_node and next_node.name not in ['h2', 'h3']:\n",
" if next_node.name == 'p':\n",
" content.append(next_node.get_text(strip=True))\n",
" elif next_node.name in ['ul', 'ol']:\n",
" items = [li.get_text(strip=True) for li in next_node.find_all('li')]\n",
" content.extend(items)\n",
" next_node = next_node.find_next_sibling()\n",
" if content:\n",
" sections[heading_text] = '\\n'.join(content)\n",
" # Only return sections with content\n",
" return {k: v for k, v in sections.items() if v}\n",
" except Exception as e:\n",
" # Just return empty dict for error\n",
" return {}\n",
"\n",
"def update_csv_with_sections(csv_file):\n",
" # Read existing data and headers\n",
" rows = []\n",
" existing_headers = []\n",
" if os.path.exists(csv_file):\n",
" with open(csv_file, 'r', newline='', encoding='utf-8') as f:\n",
" reader = csv.DictReader(f)\n",
" existing_headers = reader.fieldnames\n",
" rows = list(reader)\n",
"\n",
" # List of desired section headers\n",
" section_headers = [\n",
" 'Overview', 'Symptoms', 'When to see a doctor',\n",
" 'Causes', 'Risk factors', 'Complications', 'Prevention'\n",
" ]\n",
" # Columns from csv plus any missing section headers\n",
" all_headers = existing_headers.copy() if existing_headers else ['disease', 'main_link']\n",
" for header in section_headers:\n",
" if header not in all_headers:\n",
" all_headers.append(header)\n",
"\n",
" # Process each row and update with extracted sections\n",
" updated_rows = []\n",
" for row in tqdm(rows):\n",
" # Only process if main_link exists\n",
" if 'main_link' in row and row['main_link']:\n",
" clear_output(wait=True)\n",
" print(f\"Processing: {row.get('disease', 'Unknown')}\")\n",
" sections = extract_sections(row['main_link'])\n",
" # Update row with whatever we could extract\n",
" for section, content in sections.items():\n",
" row[section] = content\n",
" updated_rows.append(row)\n",
"\n",
" # Write back to CSV with updated headers and rows\n",
" with open(csv_file, 'w', newline='', encoding='utf-8') as f:\n",
" writer = csv.DictWriter(f, fieldnames=all_headers)\n",
" writer.writeheader()\n",
" writer.writerows(updated_rows)\n",
" print(f\"CSV file updated successfully with {len(updated_rows)} rows\")\n",
"\n",
"# Example usage\n",
"if __name__ == \"__main__\":\n",
" csv_file = \"mayo_diseases.csv\"\n",
" update_csv_with_sections(csv_file)"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Processing diseases: 99%|█████████▉| 131/132 [00:45<00:00, 3.71disease/s]"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Processing: Atrioventricular nodal reentry tachycardia (AVNRT)\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"Processing diseases: 100%|██████████| 132/132 [00:46<00:00, 2.86disease/s]"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"CSV file updated successfully with 132 rows\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"\n"
]
}
],
"source": [
"import csv\n",
"from bs4 import BeautifulSoup\n",
"import requests\n",
"import os\n",
"from tqdm import tqdm\n",
"\n",
"# Section slugs for aria-labelledby (new design) and pretty names\n",
"SECTION_SLUGS = [\n",
" (\"overview\", \"Overview\"),\n",
" (\"symptoms\", \"Symptoms\"),\n",
" (\"when-to-see-a-doctor\", \"When to see a doctor\"),\n",
" (\"causes\", \"Causes\"),\n",
" (\"risk-factors\", \"Risk factors\"),\n",
" (\"complications\", \"Complications\"),\n",
" (\"prevention\", \"Prevention\"),\n",
"]\n",
"\n",
"def extract_sections(url):\n",
" headers = {\n",
" \"User-Agent\": \"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36\",\n",
" \"Accept\": \"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8\"\n",
" }\n",
"\n",
" try:\n",
" response = requests.get(url, headers=headers, timeout=20)\n",
" response.raise_for_status()\n",
" soup = BeautifulSoup(response.text, 'html.parser')\n",
"\n",
" result_sections = {}\n",
"\n",
" # Try method 1: Old layout (div.content or article#main-content)\n",
" main_content = soup.find('div', class_='content') or soup.find('article', id='main-content')\n",
" if main_content:\n",
" headings = main_content.find_all(['h2', 'h3'])\n",
" for heading in headings:\n",
" heading_text = heading.get_text(strip=True)\n",
" # Fix typo\n",
" if \"When to see a dotor\" in heading_text:\n",
" heading_text = \"When to see a doctor\"\n",
" # If it's a section we care about\n",
" for _, section_name in SECTION_SLUGS:\n",
" if heading_text == section_name:\n",
" content = []\n",
" next_node = heading.find_next_sibling()\n",
" while next_node and next_node.name not in ['h2', 'h3']:\n",
" if next_node.name == 'p':\n",
" content.append(next_node.get_text(strip=True))\n",
" elif next_node.name in ['ul', 'ol']:\n",
" items = [li.get_text(strip=True) for li in next_node.find_all('li')]\n",
" content.extend(items)\n",
" next_node = next_node.find_next_sibling()\n",
" if content:\n",
" result_sections[section_name] = '\\n'.join(content)\n",
" # Try method 2: New layout (section[aria-labelledby] + cmp-text__rich-content)\n",
" for slug, section_name in SECTION_SLUGS:\n",
" if section_name in result_sections:\n",
" continue # Already found by old method\n",
" # Find aria-labelledby section\n",
" section = soup.find('section', {'aria-labelledby': slug})\n",
" if section:\n",
" content_div = section.find('div', class_='cmp-text__rich-content')\n",
" if content_div:\n",
" paragraphs = [p.get_text(strip=True) for p in content_div.find_all('p')]\n",
" if paragraphs:\n",
" result_sections[section_name] = '\\n\\n'.join(paragraphs)\n",
" return result_sections\n",
" except Exception as e:\n",
" # Skip on error, return empty\n",
" return {}\n",
"\n",
"def update_csv_with_sections(csv_file):\n",
" # Read existing data and headers\n",
" rows = []\n",
" existing_headers = []\n",
" if os.path.exists(csv_file):\n",
" with open(csv_file, 'r', newline='', encoding='utf-8') as f:\n",
" reader = csv.DictReader(f)\n",
" existing_headers = reader.fieldnames\n",
" rows = list(reader)\n",
"\n",
" section_headers = [section for slug, section in SECTION_SLUGS]\n",
" all_headers = existing_headers.copy() if existing_headers else ['disease', 'main_link']\n",
" for header in section_headers:\n",
" if header not in all_headers:\n",
" all_headers.append(header)\n",
"\n",
" # --- SINGLE tqdm bar for ALL rows ---\n",
" updated_rows = []\n",
" with tqdm(total=len(rows), desc=\"Processing diseases\", unit=\"disease\") as pbar:\n",
" for row in rows:\n",
" if 'main_link' in row and row['main_link']:\n",
" clear_output(wait=True)\n",
" # (Optional) tqdm.write() to log messages without disrupting the bar\n",
" tqdm.write(f\"Processing: {row.get('disease', 'Unknown')}\")\n",
" sections = extract_sections(row['main_link'])\n",
" for section, content in sections.items():\n",
" row[section] = content\n",
" updated_rows.append(row)\n",
" pbar.update(1) # Always update once per disease\n",
"\n",
" with open(csv_file, 'w', newline='', encoding='utf-8') as f:\n",
" writer = csv.DictWriter(f, fieldnames=all_headers)\n",
" writer.writeheader()\n",
" writer.writerows(updated_rows)\n",
" print(f\"CSV file updated successfully with {len(updated_rows)} rows\")\n",
"\n",
"# Example usage\n",
"if __name__ == \"__main__\":\n",
" csv_file = \"mayo_diseases.csv\"\n",
" update_csv_with_sections(csv_file)"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Processing diseases: 99%|█████████▉| 131/132 [01:15<00:00, 2.60disease/s]"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Processing: Atrioventricular nodal reentry tachycardia (AVNRT)\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"Processing diseases: 100%|██████████| 132/132 [01:16<00:00, 1.74disease/s]"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"CSV file updated successfully with 132 rows\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"\n"
]
}
],
"source": [
"import csv\n",
"from bs4 import BeautifulSoup\n",
"import requests\n",
"import os\n",
"from tqdm import tqdm\n",
"\n",
"# Section slugs for aria-labelledby (new design) and pretty names\n",
"SECTION_SLUGS = [\n",
" (\"diagnosis\", \"Diagnosis\"),\n",
" (\"treatment\", \"Treatment\"),\n",
" (\"coping-and-support\", \"Coping and support\"),\n",
" (\"preparing-for-your-appointment\", \"Preparing for your appointment\"),\n",
" (\"lifestyle-and-home-remedies\", \"Lifestyle and home remedies\")\n",
"]\n",
"\n",
"def extract_sections(url):\n",
" headers = {\n",
" \"User-Agent\": \"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36\",\n",
" \"Accept\": \"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8\"\n",
" }\n",
"\n",
" try:\n",
" response = requests.get(url, headers=headers, timeout=20)\n",
" response.raise_for_status()\n",
" soup = BeautifulSoup(response.text, 'html.parser')\n",
"\n",
" result_sections = {}\n",
"\n",
" # Try method 1: Old layout (div.content or article#main-content)\n",
" main_content = soup.find('div', class_='content') or soup.find('article', id='main-content')\n",
" if main_content:\n",
" headings = main_content.find_all(['h2', 'h3'])\n",
" for heading in headings:\n",
" heading_text = heading.get_text(strip=True)\n",
" # Fix typo\n",
" if \"When to see a dotor\" in heading_text:\n",
" heading_text = \"When to see a doctor\"\n",
" # If it's a section we care about\n",
" for _, section_name in SECTION_SLUGS:\n",
" if heading_text == section_name:\n",
" content = []\n",
" next_node = heading.find_next_sibling()\n",
" while next_node and next_node.name not in ['h2', 'h3']:\n",
" if next_node.name == 'p':\n",
" content.append(next_node.get_text(strip=True))\n",
" elif next_node.name in ['ul', 'ol']:\n",
" items = [li.get_text(strip=True) for li in next_node.find_all('li')]\n",
" content.extend(items)\n",
" next_node = next_node.find_next_sibling()\n",
" if content:\n",
" result_sections[section_name] = '\\n'.join(content)\n",
" # Try method 2: New layout (section[aria-labelledby] + cmp-text__rich-content)\n",
" for slug, section_name in SECTION_SLUGS:\n",
" if section_name in result_sections:\n",
" continue # Already found by old method\n",
" # Find aria-labelledby section\n",
" section = soup.find('section', {'aria-labelledby': slug})\n",
" if section:\n",
" content_div = section.find('div', class_='cmp-text__rich-content')\n",
" if content_div:\n",
" paragraphs = [p.get_text(strip=True) for p in content_div.find_all('p')]\n",
" if paragraphs:\n",
" result_sections[section_name] = '\\n\\n'.join(paragraphs)\n",
" return result_sections\n",
" except Exception as e:\n",
" # Skip on error, return empty\n",
" return {}\n",
"\n",
"def update_csv_with_sections(csv_file):\n",
" # Read existing data and headers\n",
" rows = []\n",
" existing_headers = []\n",
" if os.path.exists(csv_file):\n",
" with open(csv_file, 'r', newline='', encoding='utf-8') as f:\n",
" reader = csv.DictReader(f)\n",
" existing_headers = reader.fieldnames\n",
" rows = list(reader)\n",
"\n",
" section_headers = [section for slug, section in SECTION_SLUGS]\n",
" all_headers = existing_headers.copy() if existing_headers else ['disease', 'main_link']\n",
" for header in section_headers:\n",
" if header not in all_headers:\n",
" all_headers.append(header)\n",
"\n",
" # --- SINGLE tqdm bar for ALL rows ---\n",
" updated_rows = []\n",
" with tqdm(total=len(rows), desc=\"Processing diseases\", unit=\"disease\") as pbar:\n",
" for row in rows:\n",
" if 'main_link' in row and row['Diagnosis_treatment_link']:\n",
" clear_output(wait=True)\n",
" # (Optional) tqdm.write() to log messages without disrupting the bar\n",
" tqdm.write(f\"Processing: {row.get('disease', 'Unknown')}\")\n",
" sections = extract_sections(row['Diagnosis_treatment_link'])\n",
" for section, content in sections.items():\n",
" row[section] = content\n",
" updated_rows.append(row)\n",
" pbar.update(1) # Always update once per disease\n",
"\n",
" with open(csv_file, 'w', newline='', encoding='utf-8') as f:\n",
" writer = csv.DictWriter(f, fieldnames=all_headers)\n",
" writer.writeheader()\n",
" writer.writerows(updated_rows)\n",
" print(f\"CSV file updated successfully with {len(updated_rows)} rows\")\n",
"\n",
"# Example usage\n",
"if __name__ == \"__main__\":\n",
" csv_file = \"mayo_diseases.csv\"\n",
" update_csv_with_sections(csv_file)"
]
},
{
"cell_type": "code",
"execution_count": 31,
"metadata": {},
"outputs": [],
"source": [
"extraction_list = [\"overview\",\"symptoms\",\"when-to-see-a-doctor\",\"causes\",\"complications\",\"prevention\",\"risk-factors\"]"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [],
"source": [
"df = pd.read_csv(\"mayo_diseases.csv\")"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(132, 16)"
]
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.shape"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"disease 0\n",
"main_link 0\n",
"Diagnosis_treatment_link 1\n",
"Doctors_departments_link 25\n",
"Overview 0\n",
"Symptoms 2\n",
"When to see a doctor 12\n",
"Causes 2\n",
"Risk factors 2\n",
"Complications 22\n",
"Prevention 52\n",
"Diagnosis 1\n",
"Treatment 1\n",
"Coping and support 76\n",
"Preparing for your appointment 6\n",
"Lifestyle and home remedies 81\n",
"dtype: int64"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.isnull().sum()"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"
\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" disease | \n",
" main_link | \n",
" Diagnosis_treatment_link | \n",
" Doctors_departments_link | \n",
" Overview | \n",
" Symptoms | \n",
" When to see a doctor | \n",
" Causes | \n",
" Risk factors | \n",
" Complications | \n",
" Prevention | \n",
" Diagnosis | \n",
" Treatment | \n",
" Coping and support | \n",
" Preparing for your appointment | \n",
" Lifestyle and home remedies | \n",
"
\n",
" \n",
" \n",
" \n",
" | 0 | \n",
" Atrial fibrillation | \n",
" https://www.mayoclinic.org/diseases-conditions... | \n",
" https://www.mayoclinic.org/diseases-conditions... | \n",
" https://www.mayoclinic.org/diseases-conditions... | \n",
" Atrial fibrillation (AFib) is an irregular and... | \n",
" Symptoms ofAFibmay include:\\nFeelings of a fas... | \n",
" If you have symptoms of atrial fibrillation, m... | \n",
" To understand the causes of atrial fibrillatio... | \n",
" Things that can increase the risk of atrial fi... | \n",
" Blood clots are a dangerous complication of at... | \n",
" Healthy lifestyle choices can reduce the risk ... | \n",
" You may not know you have atrial fibrillation ... | \n",
" The goals of atrial fibrillation treatment are... | \n",
" NaN | \n",
" If you have an irregular or pounding heartbeat... | \n",
" Following a heart-healthy lifestyle can help p... | \n",
"
\n",
" \n",
" | 1 | \n",
" Hyperhidrosis | \n",
" https://www.mayoclinic.org/diseases-conditions... | \n",
" https://www.mayoclinic.org/diseases-conditions... | \n",
" https://www.mayoclinic.org/diseases-conditions... | \n",
" Hyperhidrosis (hi-pur-hi-DROE-sis) is excessiv... | \n",
" The main symptom of hyperhidrosis is heavy swe... | \n",
" Sometimes excessive sweating is a sign of a se... | \n",
" Sweating is the body's mechanism to cool itsel... | \n",
" Risk factors for hyperhidrosis include:\\nHavin... | \n",
" Complications of hyperhidrosis include:\\nInfec... | \n",
" NaN | \n",
" Diagnosing hyperhidrosis may start with your h... | \n",
" Treating hyperhidrosis may start with treating... | \n",
" Hyperhidrosis can be the cause of discomfort a... | \n",
" You may start by seeing your primary care prov... | \n",
" The following suggestions may help control swe... | \n",
"
\n",
" \n",
" | 2 | \n",
" Bartholin's cyst | \n",
" https://www.mayoclinic.org/diseases-conditions... | \n",
" https://www.mayoclinic.org/diseases-conditions... | \n",
" https://www.mayoclinic.org/diseases-conditions... | \n",
" The Bartholin's (BAHR-toe-linz) glands are loc... | \n",
" If you have a small, noninfected Bartholin's c... | \n",
" Call your doctor if you have a painful lump ne... | \n",
" Experts believe that the cause of a Bartholin'... | \n",
" NaN | \n",
" A Bartholin's cyst or abscess may recur and ag... | \n",
" There's no way to prevent a Bartholin's cyst. ... | \n",
" To diagnose a Bartholin's cyst, your doctor ma... | \n",
" Often a Bartholin's cyst requires no treatment... | \n",
" NaN | \n",
" Your first appointment will likely be with eit... | \n",
" NaN | \n",
"
\n",
" \n",
" | 3 | \n",
" Infant reflux | \n",
" https://www.mayoclinic.org/diseases-conditions... | \n",
" https://www.mayoclinic.org/diseases-conditions... | \n",
" NaN | \n",
" Infant reflux is when a baby spits up liquid o... | \n",
" Most of the time, infant reflux isn't a cause ... | \n",
" See a healthcare professional if a baby:\\nIsn'... | \n",
" In infants, the ring of muscle between the eso... | \n",
" Infant reflux is common. But some things make ... | \n",
" Infant reflux usually gets better on its own. ... | \n",
" NaN | \n",
" To diagnose infant reflux, a healthcare profes... | \n",
" For most babies, making some changes to feedin... | \n",
" NaN | \n",
" You may start by seeing your baby's primary he... | \n",
" To minimize reflux:\\nFeed your baby in an upri... | \n",
"
\n",
" \n",
" | 4 | \n",
" Hidradenitis suppurativa | \n",
" https://www.mayoclinic.org/diseases-conditions... | \n",
" https://www.mayoclinic.org/diseases-conditions... | \n",
" https://www.mayoclinic.org/diseases-conditions... | \n",
" Hidradenitis suppurativa (hi-drad-uh-NIE-tis s... | \n",
" Hidradenitis suppurativa can affect one or sev... | \n",
" Early diagnosis of hidradenitis suppurativa is... | \n",
" Hidradenitis suppurativa develops when hair fo... | \n",
" Factors that increase your chance of developin... | \n",
" Persistent and severe hidradenitis suppurativa... | \n",
" NaN | \n",
" Hidradenitis suppurativa can be mistaken for p... | \n",
" Treatment with medicines, surgery or both can ... | \n",
" Hidradenitis suppurativa can be a challenge to... | \n",
" You'll likely first see your primary care prov... | \n",
" Mild hidradenitis suppurativa can sometimes be... | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" disease \\\n",
"0 Atrial fibrillation \n",
"1 Hyperhidrosis \n",
"2 Bartholin's cyst \n",
"3 Infant reflux \n",
"4 Hidradenitis suppurativa \n",
"\n",
" main_link \\\n",
"0 https://www.mayoclinic.org/diseases-conditions... \n",
"1 https://www.mayoclinic.org/diseases-conditions... \n",
"2 https://www.mayoclinic.org/diseases-conditions... \n",
"3 https://www.mayoclinic.org/diseases-conditions... \n",
"4 https://www.mayoclinic.org/diseases-conditions... \n",
"\n",
" Diagnosis_treatment_link \\\n",
"0 https://www.mayoclinic.org/diseases-conditions... \n",
"1 https://www.mayoclinic.org/diseases-conditions... \n",
"2 https://www.mayoclinic.org/diseases-conditions... \n",
"3 https://www.mayoclinic.org/diseases-conditions... \n",
"4 https://www.mayoclinic.org/diseases-conditions... \n",
"\n",
" Doctors_departments_link \\\n",
"0 https://www.mayoclinic.org/diseases-conditions... \n",
"1 https://www.mayoclinic.org/diseases-conditions... \n",
"2 https://www.mayoclinic.org/diseases-conditions... \n",
"3 NaN \n",
"4 https://www.mayoclinic.org/diseases-conditions... \n",
"\n",
" Overview \\\n",
"0 Atrial fibrillation (AFib) is an irregular and... \n",
"1 Hyperhidrosis (hi-pur-hi-DROE-sis) is excessiv... \n",
"2 The Bartholin's (BAHR-toe-linz) glands are loc... \n",
"3 Infant reflux is when a baby spits up liquid o... \n",
"4 Hidradenitis suppurativa (hi-drad-uh-NIE-tis s... \n",
"\n",
" Symptoms \\\n",
"0 Symptoms ofAFibmay include:\\nFeelings of a fas... \n",
"1 The main symptom of hyperhidrosis is heavy swe... \n",
"2 If you have a small, noninfected Bartholin's c... \n",
"3 Most of the time, infant reflux isn't a cause ... \n",
"4 Hidradenitis suppurativa can affect one or sev... \n",
"\n",
" When to see a doctor \\\n",
"0 If you have symptoms of atrial fibrillation, m... \n",
"1 Sometimes excessive sweating is a sign of a se... \n",
"2 Call your doctor if you have a painful lump ne... \n",
"3 See a healthcare professional if a baby:\\nIsn'... \n",
"4 Early diagnosis of hidradenitis suppurativa is... \n",
"\n",
" Causes \\\n",
"0 To understand the causes of atrial fibrillatio... \n",
"1 Sweating is the body's mechanism to cool itsel... \n",
"2 Experts believe that the cause of a Bartholin'... \n",
"3 In infants, the ring of muscle between the eso... \n",
"4 Hidradenitis suppurativa develops when hair fo... \n",
"\n",
" Risk factors \\\n",
"0 Things that can increase the risk of atrial fi... \n",
"1 Risk factors for hyperhidrosis include:\\nHavin... \n",
"2 NaN \n",
"3 Infant reflux is common. But some things make ... \n",
"4 Factors that increase your chance of developin... \n",
"\n",
" Complications \\\n",
"0 Blood clots are a dangerous complication of at... \n",
"1 Complications of hyperhidrosis include:\\nInfec... \n",
"2 A Bartholin's cyst or abscess may recur and ag... \n",
"3 Infant reflux usually gets better on its own. ... \n",
"4 Persistent and severe hidradenitis suppurativa... \n",
"\n",
" Prevention \\\n",
"0 Healthy lifestyle choices can reduce the risk ... \n",
"1 NaN \n",
"2 There's no way to prevent a Bartholin's cyst. ... \n",
"3 NaN \n",
"4 NaN \n",
"\n",
" Diagnosis \\\n",
"0 You may not know you have atrial fibrillation ... \n",
"1 Diagnosing hyperhidrosis may start with your h... \n",
"2 To diagnose a Bartholin's cyst, your doctor ma... \n",
"3 To diagnose infant reflux, a healthcare profes... \n",
"4 Hidradenitis suppurativa can be mistaken for p... \n",
"\n",
" Treatment \\\n",
"0 The goals of atrial fibrillation treatment are... \n",
"1 Treating hyperhidrosis may start with treating... \n",
"2 Often a Bartholin's cyst requires no treatment... \n",
"3 For most babies, making some changes to feedin... \n",
"4 Treatment with medicines, surgery or both can ... \n",
"\n",
" Coping and support \\\n",
"0 NaN \n",
"1 Hyperhidrosis can be the cause of discomfort a... \n",
"2 NaN \n",
"3 NaN \n",
"4 Hidradenitis suppurativa can be a challenge to... \n",
"\n",
" Preparing for your appointment \\\n",
"0 If you have an irregular or pounding heartbeat... \n",
"1 You may start by seeing your primary care prov... \n",
"2 Your first appointment will likely be with eit... \n",
"3 You may start by seeing your baby's primary he... \n",
"4 You'll likely first see your primary care prov... \n",
"\n",
" Lifestyle and home remedies \n",
"0 Following a heart-healthy lifestyle can help p... \n",
"1 The following suggestions may help control swe... \n",
"2 NaN \n",
"3 To minimize reflux:\\nFeed your baby in an upri... \n",
"4 Mild hidradenitis suppurativa can sometimes be... "
]
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.head()"
]
},
{
"cell_type": "code",
"execution_count": 22,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"\"Symptoms ofAFibmay include:\\nFeelings of a fast, fluttering or pounding heartbeat, called palpitations.\\nChest pain.\\nDizziness.\\nFatigue.\\nLightheadedness.\\nReduced ability to exercise.\\nShortness of breath.\\nWeakness.\\nSome people with atrial fibrillation (AFib) don't notice any symptoms.\\nAtrial fibrillation may be:\\nOccasional, also called paroxysmal atrial fibrillation.AFibsymptoms come and go. The symptoms usually last for a few minutes to hours. Some people have symptoms for as long as a week. The episodes can happen repeatedly. Symptoms might go away on their own. Some people with occasionalAFibneed treatment.\\nPersistent.The irregular heartbeat is constant. The heart rhythm does not reset on its own. If symptoms occur, medical treatment is needed to correct the heart rhythm.\\nLong-standing persistent.This type ofAFibis constant and lasts longer than 12 months. Medicines or a procedure are needed to correct the irregular heartbeat.\\nPermanent.In this type of atrial fibrillation, the irregular heart rhythm can't be reset. Medicines are needed to control the heart rate and to prevent blood clots.\""
]
},
"execution_count": 22,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df[\"Symptoms\"][0]"
]
},
{
"cell_type": "code",
"execution_count": 20,
"metadata": {},
"outputs": [],
"source": [
"import nltk"
]
},
{
"cell_type": "code",
"execution_count": 21,
"metadata": {},
"outputs": [],
"source": [
"symptoms = df[\"Symptoms\"]"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"symptoms[\"symptoms\"] = symptoms[\"symptoms\"]."
]
},
{
"cell_type": "code",
"execution_count": 23,
"metadata": {},
"outputs": [],
"source": [
"import requests\n",
"import json"
]
},
{
"cell_type": "code",
"execution_count": 24,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"API Key Loaded Successfully: gsk_7rEOxb*****\n"
]
}
],
"source": [
"import os\n",
"\n",
"# Get the API key from the environment variable\n",
"api_key = os.getenv(\"GROQ_API_KEY\")\n",
"\n",
"# Optional: Check if it's loaded\n",
"if api_key:\n",
" print(\"API Key Loaded Successfully:\", api_key[:10] + \"*****\")\n",
"else:\n",
" print(\"API Key not found. Check if the environment variable is set.\")\n"
]
},
{
"cell_type": "code",
"execution_count": 25,
"metadata": {},
"outputs": [],
"source": [
"url = \"https://api.groq.com/openai/v1/chat/completions\"\n",
"headers = {\n",
" \"Content-Type\": \"application/json\",\n",
" \"Authorization\": f\"Bearer {api_key}\"\n",
"}"
]
},
{
"cell_type": "code",
"execution_count": 26,
"metadata": {},
"outputs": [],
"source": [
"text = \"Symptoms ofAFibmay include:\\nFeelings of a fast, fluttering or pounding heartbeat, called palpitations.\\nChest pain.\\nDizziness.\\nFatigue.\\nLightheadedness.\\nReduced ability to exercise.\\nShortness of breath.\\nWeakness.\\nSome people with atrial fibrillation (AFib) don't notice any symptoms.\\nAtrial fibrillation may be:\\nOccasional, also called paroxysmal atrial fibrillation.AFibsymptoms come and go. The symptoms usually last for a few minutes to hours. Some people have symptoms for as long as a week. The episodes can happen repeatedly. Symptoms might go away on their own. Some people with occasionalAFibneed treatment.\\nPersistent.The irregular heartbeat is constant. The heart rhythm does not reset on its own. If symptoms occur, medical treatment is needed to correct the heart rhythm.\\nLong-standing persistent.This type ofAFibis constant and lasts longer than 12 months. Medicines or a procedure are needed to correct the irregular heartbeat.\\nPermanent.In this type of atrial fibrillation, the irregular heart rhythm can't be reset. Medicines are needed to control the heart rate and to prevent blood clots.\"\n",
"\n",
"data = {\n",
" \"model\": \"llama-3.3-70b-versatile\",\n",
" \"messages\": [\n",
" {\n",
" \"role\": \"user\",\n",
" \"content\": f\"\"\"\n",
"You are a helpful and expert **medical assistant AI**. You read medical or health-related texts and explain them in clear, friendly, and simplified language for non-medical users.\n",
"\n",
"Here is a health-related text a user might find hard to understand:\n",
"\n",
"\\\"\\\"\\\"{text}\\\"\\\"\\\"\n",
"\n",
"Your job is to extract and present the following:\n",
"\n",
"1. A user-friendly **summary of all symptoms** mentioned in the text (bullet point format).\n",
"2. Break down and **explain any types or stages** of the condition (if present), in plain English.\n",
"3. Provide a short and clear **educational paragraph** on the condition that includes what it is, its symptoms, and when to seek medical help.\n",
"4. Output everything in **structured JSON** format with the following fields:\n",
" - `symptoms`: A list of clear symptoms in bullet point format\n",
" - `types`: A list explaining any forms or categories (like “Occasional”, “Persistent”, etc.)\n",
" - `summary`: A friendly paragraph explaining the condition and what the user should know\n",
"\n",
"Make sure your output is simple, empathetic, and helpful — written in a tone similar to a nurse explaining something gently to a patient.\n",
"\"\"\"\n",
" }\n",
" ]\n",
"}"
]
},
{
"cell_type": "code",
"execution_count": 29,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"AI Response:\n",
"\n",
"```json\n",
"{\n",
" \"symptoms\": [\n",
" \"Feelings of a fast, fluttering or pounding heartbeat (palpitations)\",\n",
" \"Chest pain\",\n",
" \"Dizziness\",\n",
" \"Fatigue\",\n",
" \"Lightheadedness\",\n",
" \"Reduced ability to exercise\",\n",
" \"Shortness of breath\",\n",
" \"Weakness\"\n",
" ],\n",
" \"types\": [\n",
" \"Occasional (paroxysmal): Symptoms come and go, lasting from a few minutes to hours or even a week, and may go away on their own.\",\n",
" \"Persistent: The irregular heartbeat is constant and doesn't reset on its own, requiring medical treatment.\",\n",
" \"Long-standing persistent: This type lasts longer than 12 months and requires medicine or a procedure to correct the heartbeat.\",\n",
" \"Permanent: The irregular heartbeat can't be reset, and medicine is needed to control the heart rate and prevent blood clots.\"\n",
" ],\n",
" \"summary\": \"Atrial fibrillation, also known as AFib, is a heart condition where the heartbeat becomes irregular. It can cause a range of symptoms, including palpitations, chest pain, dizziness, and shortness of breath. Some people may not notice any symptoms at all. AFib can be occasional, persistent, or even permanent, and it's essential to seek medical help if you experience any symptoms or if they worsen over time. Your doctor can help you manage the condition and prevent any potential complications. Remember, if you're experiencing any unusual heart rhythms or symptoms, don't hesitate to reach out to your healthcare provider for guidance and support.\"\n",
"}\n",
"```\n"
]
}
],
"source": [
"response = requests.post(url, headers=headers, data=json.dumps(data))\n",
"\n",
"# ✅ Print the AI response\n",
"if response.status_code == 200:\n",
" result = response.json()\n",
" print(\"AI Response:\\n\")\n",
" print(result['choices'][0]['message']['content'])\n",
"else:\n",
" print(\"Error:\", response.status_code)\n",
" print(response.text)"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"tensorFlow== 2.19.0\n",
"numpy== 2.0.2\n",
"pillow== 11.0.0\n",
"keras== 3.10.0\n"
]
}
],
"source": [
"import tensorflow as tf\n",
"import numpy as np\n",
"import PIL\n",
"import keras\n",
"\n",
"print(\"tensorFlow==\", tf.__version__)\n",
"print(\"numpy==\", np.__version__)\n",
"print(\"pillow==\", PIL.__version__)\n",
"print(\"keras==\", keras.__version__)\n"
]
},
{
"cell_type": "code",
"execution_count": 39,
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd"
]
},
{
"cell_type": "code",
"execution_count": 40,
"metadata": {},
"outputs": [],
"source": [
"df = pd.read_csv(\"mayo_diseases.csv\")"
]
},
{
"cell_type": "code",
"execution_count": 41,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" disease | \n",
" main_link | \n",
" Diagnosis_treatment_link | \n",
" Doctors_departments_link | \n",
" Overview | \n",
" Symptoms | \n",
" When to see a doctor | \n",
" Causes | \n",
" Risk factors | \n",
" Complications | \n",
" Prevention | \n",
" Diagnosis | \n",
" Treatment | \n",
" Coping and support | \n",
" Preparing for your appointment | \n",
" Lifestyle and home remedies | \n",
"
\n",
" \n",
" \n",
" \n",
" | 0 | \n",
" Atrial fibrillation | \n",
" https://www.mayoclinic.org/diseases-conditions... | \n",
" https://www.mayoclinic.org/diseases-conditions... | \n",
" https://www.mayoclinic.org/diseases-conditions... | \n",
" Atrial fibrillation (AFib) is an irregular and... | \n",
" Symptoms ofAFibmay include:\\nFeelings of a fas... | \n",
" If you have symptoms of atrial fibrillation, m... | \n",
" To understand the causes of atrial fibrillatio... | \n",
" Things that can increase the risk of atrial fi... | \n",
" Blood clots are a dangerous complication of at... | \n",
" Healthy lifestyle choices can reduce the risk ... | \n",
" You may not know you have atrial fibrillation ... | \n",
" The goals of atrial fibrillation treatment are... | \n",
" NaN | \n",
" If you have an irregular or pounding heartbeat... | \n",
" Following a heart-healthy lifestyle can help p... | \n",
"
\n",
" \n",
" | 1 | \n",
" Hyperhidrosis | \n",
" https://www.mayoclinic.org/diseases-conditions... | \n",
" https://www.mayoclinic.org/diseases-conditions... | \n",
" https://www.mayoclinic.org/diseases-conditions... | \n",
" Hyperhidrosis (hi-pur-hi-DROE-sis) is excessiv... | \n",
" The main symptom of hyperhidrosis is heavy swe... | \n",
" Sometimes excessive sweating is a sign of a se... | \n",
" Sweating is the body's mechanism to cool itsel... | \n",
" Risk factors for hyperhidrosis include:\\nHavin... | \n",
" Complications of hyperhidrosis include:\\nInfec... | \n",
" NaN | \n",
" Diagnosing hyperhidrosis may start with your h... | \n",
" Treating hyperhidrosis may start with treating... | \n",
" Hyperhidrosis can be the cause of discomfort a... | \n",
" You may start by seeing your primary care prov... | \n",
" The following suggestions may help control swe... | \n",
"
\n",
" \n",
" | 2 | \n",
" Bartholin's cyst | \n",
" https://www.mayoclinic.org/diseases-conditions... | \n",
" https://www.mayoclinic.org/diseases-conditions... | \n",
" https://www.mayoclinic.org/diseases-conditions... | \n",
" The Bartholin's (BAHR-toe-linz) glands are loc... | \n",
" If you have a small, noninfected Bartholin's c... | \n",
" Call your doctor if you have a painful lump ne... | \n",
" Experts believe that the cause of a Bartholin'... | \n",
" NaN | \n",
" A Bartholin's cyst or abscess may recur and ag... | \n",
" There's no way to prevent a Bartholin's cyst. ... | \n",
" To diagnose a Bartholin's cyst, your doctor ma... | \n",
" Often a Bartholin's cyst requires no treatment... | \n",
" NaN | \n",
" Your first appointment will likely be with eit... | \n",
" NaN | \n",
"
\n",
" \n",
" | 3 | \n",
" Infant reflux | \n",
" https://www.mayoclinic.org/diseases-conditions... | \n",
" https://www.mayoclinic.org/diseases-conditions... | \n",
" NaN | \n",
" Infant reflux is when a baby spits up liquid o... | \n",
" Most of the time, infant reflux isn't a cause ... | \n",
" See a healthcare professional if a baby:\\nIsn'... | \n",
" In infants, the ring of muscle between the eso... | \n",
" Infant reflux is common. But some things make ... | \n",
" Infant reflux usually gets better on its own. ... | \n",
" NaN | \n",
" To diagnose infant reflux, a healthcare profes... | \n",
" For most babies, making some changes to feedin... | \n",
" NaN | \n",
" You may start by seeing your baby's primary he... | \n",
" To minimize reflux:\\nFeed your baby in an upri... | \n",
"
\n",
" \n",
" | 4 | \n",
" Hidradenitis suppurativa | \n",
" https://www.mayoclinic.org/diseases-conditions... | \n",
" https://www.mayoclinic.org/diseases-conditions... | \n",
" https://www.mayoclinic.org/diseases-conditions... | \n",
" Hidradenitis suppurativa (hi-drad-uh-NIE-tis s... | \n",
" Hidradenitis suppurativa can affect one or sev... | \n",
" Early diagnosis of hidradenitis suppurativa is... | \n",
" Hidradenitis suppurativa develops when hair fo... | \n",
" Factors that increase your chance of developin... | \n",
" Persistent and severe hidradenitis suppurativa... | \n",
" NaN | \n",
" Hidradenitis suppurativa can be mistaken for p... | \n",
" Treatment with medicines, surgery or both can ... | \n",
" Hidradenitis suppurativa can be a challenge to... | \n",
" You'll likely first see your primary care prov... | \n",
" Mild hidradenitis suppurativa can sometimes be... | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" disease \\\n",
"0 Atrial fibrillation \n",
"1 Hyperhidrosis \n",
"2 Bartholin's cyst \n",
"3 Infant reflux \n",
"4 Hidradenitis suppurativa \n",
"\n",
" main_link \\\n",
"0 https://www.mayoclinic.org/diseases-conditions... \n",
"1 https://www.mayoclinic.org/diseases-conditions... \n",
"2 https://www.mayoclinic.org/diseases-conditions... \n",
"3 https://www.mayoclinic.org/diseases-conditions... \n",
"4 https://www.mayoclinic.org/diseases-conditions... \n",
"\n",
" Diagnosis_treatment_link \\\n",
"0 https://www.mayoclinic.org/diseases-conditions... \n",
"1 https://www.mayoclinic.org/diseases-conditions... \n",
"2 https://www.mayoclinic.org/diseases-conditions... \n",
"3 https://www.mayoclinic.org/diseases-conditions... \n",
"4 https://www.mayoclinic.org/diseases-conditions... \n",
"\n",
" Doctors_departments_link \\\n",
"0 https://www.mayoclinic.org/diseases-conditions... \n",
"1 https://www.mayoclinic.org/diseases-conditions... \n",
"2 https://www.mayoclinic.org/diseases-conditions... \n",
"3 NaN \n",
"4 https://www.mayoclinic.org/diseases-conditions... \n",
"\n",
" Overview \\\n",
"0 Atrial fibrillation (AFib) is an irregular and... \n",
"1 Hyperhidrosis (hi-pur-hi-DROE-sis) is excessiv... \n",
"2 The Bartholin's (BAHR-toe-linz) glands are loc... \n",
"3 Infant reflux is when a baby spits up liquid o... \n",
"4 Hidradenitis suppurativa (hi-drad-uh-NIE-tis s... \n",
"\n",
" Symptoms \\\n",
"0 Symptoms ofAFibmay include:\\nFeelings of a fas... \n",
"1 The main symptom of hyperhidrosis is heavy swe... \n",
"2 If you have a small, noninfected Bartholin's c... \n",
"3 Most of the time, infant reflux isn't a cause ... \n",
"4 Hidradenitis suppurativa can affect one or sev... \n",
"\n",
" When to see a doctor \\\n",
"0 If you have symptoms of atrial fibrillation, m... \n",
"1 Sometimes excessive sweating is a sign of a se... \n",
"2 Call your doctor if you have a painful lump ne... \n",
"3 See a healthcare professional if a baby:\\nIsn'... \n",
"4 Early diagnosis of hidradenitis suppurativa is... \n",
"\n",
" Causes \\\n",
"0 To understand the causes of atrial fibrillatio... \n",
"1 Sweating is the body's mechanism to cool itsel... \n",
"2 Experts believe that the cause of a Bartholin'... \n",
"3 In infants, the ring of muscle between the eso... \n",
"4 Hidradenitis suppurativa develops when hair fo... \n",
"\n",
" Risk factors \\\n",
"0 Things that can increase the risk of atrial fi... \n",
"1 Risk factors for hyperhidrosis include:\\nHavin... \n",
"2 NaN \n",
"3 Infant reflux is common. But some things make ... \n",
"4 Factors that increase your chance of developin... \n",
"\n",
" Complications \\\n",
"0 Blood clots are a dangerous complication of at... \n",
"1 Complications of hyperhidrosis include:\\nInfec... \n",
"2 A Bartholin's cyst or abscess may recur and ag... \n",
"3 Infant reflux usually gets better on its own. ... \n",
"4 Persistent and severe hidradenitis suppurativa... \n",
"\n",
" Prevention \\\n",
"0 Healthy lifestyle choices can reduce the risk ... \n",
"1 NaN \n",
"2 There's no way to prevent a Bartholin's cyst. ... \n",
"3 NaN \n",
"4 NaN \n",
"\n",
" Diagnosis \\\n",
"0 You may not know you have atrial fibrillation ... \n",
"1 Diagnosing hyperhidrosis may start with your h... \n",
"2 To diagnose a Bartholin's cyst, your doctor ma... \n",
"3 To diagnose infant reflux, a healthcare profes... \n",
"4 Hidradenitis suppurativa can be mistaken for p... \n",
"\n",
" Treatment \\\n",
"0 The goals of atrial fibrillation treatment are... \n",
"1 Treating hyperhidrosis may start with treating... \n",
"2 Often a Bartholin's cyst requires no treatment... \n",
"3 For most babies, making some changes to feedin... \n",
"4 Treatment with medicines, surgery or both can ... \n",
"\n",
" Coping and support \\\n",
"0 NaN \n",
"1 Hyperhidrosis can be the cause of discomfort a... \n",
"2 NaN \n",
"3 NaN \n",
"4 Hidradenitis suppurativa can be a challenge to... \n",
"\n",
" Preparing for your appointment \\\n",
"0 If you have an irregular or pounding heartbeat... \n",
"1 You may start by seeing your primary care prov... \n",
"2 Your first appointment will likely be with eit... \n",
"3 You may start by seeing your baby's primary he... \n",
"4 You'll likely first see your primary care prov... \n",
"\n",
" Lifestyle and home remedies \n",
"0 Following a heart-healthy lifestyle can help p... \n",
"1 The following suggestions may help control swe... \n",
"2 NaN \n",
"3 To minimize reflux:\\nFeed your baby in an upri... \n",
"4 Mild hidradenitis suppurativa can sometimes be... "
]
},
"execution_count": 41,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.head()"
]
},
{
"cell_type": "code",
"execution_count": 42,
"metadata": {},
"outputs": [],
"source": [
"symptoms = df[\"Symptoms\"]"
]
},
{
"cell_type": "code",
"execution_count": 46,
"metadata": {},
"outputs": [],
"source": [
"sample = symptoms[2]"
]
},
{
"cell_type": "code",
"execution_count": 50,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Device set to use cpu\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"non Detailed_description\n",
"cy Sign_symptom\n",
"##st Coreference\n",
"cy Sign_symptom\n",
"lump Sign_symptom\n",
"mass Sign_symptom\n",
"va Biological_structure\n",
"cyst Sign_symptom\n",
"full Detailed_description\n",
"blown Detailed_description\n",
"cy Sign_symptom\n",
"cy Sign_symptom\n",
"cyst Sign_symptom\n",
"abscess Sign_symptom\n"
]
}
],
"source": [
"from transformers import AutoTokenizer, AutoModelForTokenClassification, pipeline\n",
"\n",
"model_name = \"d4data/biomedical-ner-all\"\n",
"tokenizer = AutoTokenizer.from_pretrained(model_name)\n",
"model = AutoModelForTokenClassification.from_pretrained(model_name)\n",
"\n",
"ner = pipeline(\"ner\", model=model, tokenizer=tokenizer, aggregation_strategy=\"simple\")\n",
"\n",
"entities = ner(sample)\n",
"\n",
"for e in entities:\n",
" print(e['word'], e['entity_group'])\n"
]
},
{
"cell_type": "code",
"execution_count": 47,
"metadata": {},
"outputs": [],
"source": [
"import re\n",
"\n",
"def extract_symptoms(text):\n",
" # Split into lines\n",
" lines = text.split(\"\\n\")\n",
" # Keep lines that are short symptom-like phrases\n",
" symptoms = []\n",
" for line in lines:\n",
" line = line.strip()\n",
" if line and len(line.split()) <= 10: # filter short lines (likely symptoms)\n",
" # Clean extra characters\n",
" line = re.sub(r\"^[•\\-–\\d.\\s]*\", \"\", line) # remove bullets or numbering\n",
" symptoms.append(line)\n",
" return symptoms\n"
]
},
{
"cell_type": "code",
"execution_count": 48,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[]"
]
},
"execution_count": 48,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"extract_symptoms(sample)"
]
},
{
"cell_type": "code",
"execution_count": 49,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"\"If you have a small, noninfected Bartholin's cyst, you may not notice it. If the cyst grows, you might feel a lump or mass near your vaginal opening. Although a cyst is usually painless, it can be tender.\\n\\nA full-blown infection of a Bartholin's cyst can occur in a matter of days. If the cyst becomes infected, you may experience:\\n\\nA Bartholin's cyst or abscess typically occurs on only one side of the vaginal opening.\""
]
},
"execution_count": 49,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sample"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"import sys\n",
"import pandas as pd\n",
"from tqdm import tqdm\n",
"\n",
"from langchain_community.embeddings import HuggingFaceEmbeddings\n",
"from langchain_community.vectorstores import FAISS\n",
"from langchain.schema import Document\n"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [],
"source": [
"sys.path.append(os.path.abspath(os.path.join(os.getcwd(), \"..\")))\n",
"\n",
"from backend.utils.text_cleaning import Text_Preprocessing\n",
"from backend.utils.filtering_with_ner import RemoveUselessWords\n"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Loaded CSV\n"
]
},
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" disease | \n",
" main_link | \n",
" Diagnosis_treatment_link | \n",
" Doctors_departments_link | \n",
" Overview | \n",
" Symptoms | \n",
" When to see a doctor | \n",
" Causes | \n",
" Risk factors | \n",
" Complications | \n",
" Prevention | \n",
" Diagnosis | \n",
" Treatment | \n",
" Coping and support | \n",
" Preparing for your appointment | \n",
" Lifestyle and home remedies | \n",
"
\n",
" \n",
" \n",
" \n",
" | 0 | \n",
" Atrial fibrillation | \n",
" https://www.mayoclinic.org/diseases-conditions... | \n",
" https://www.mayoclinic.org/diseases-conditions... | \n",
" https://www.mayoclinic.org/diseases-conditions... | \n",
" Atrial fibrillation (AFib) is an irregular and... | \n",
" Symptoms ofAFibmay include:\\nFeelings of a fas... | \n",
" If you have symptoms of atrial fibrillation, m... | \n",
" To understand the causes of atrial fibrillatio... | \n",
" Things that can increase the risk of atrial fi... | \n",
" Blood clots are a dangerous complication of at... | \n",
" Healthy lifestyle choices can reduce the risk ... | \n",
" You may not know you have atrial fibrillation ... | \n",
" The goals of atrial fibrillation treatment are... | \n",
" NaN | \n",
" If you have an irregular or pounding heartbeat... | \n",
" Following a heart-healthy lifestyle can help p... | \n",
"
\n",
" \n",
" | 1 | \n",
" Hyperhidrosis | \n",
" https://www.mayoclinic.org/diseases-conditions... | \n",
" https://www.mayoclinic.org/diseases-conditions... | \n",
" https://www.mayoclinic.org/diseases-conditions... | \n",
" Hyperhidrosis (hi-pur-hi-DROE-sis) is excessiv... | \n",
" The main symptom of hyperhidrosis is heavy swe... | \n",
" Sometimes excessive sweating is a sign of a se... | \n",
" Sweating is the body's mechanism to cool itsel... | \n",
" Risk factors for hyperhidrosis include:\\nHavin... | \n",
" Complications of hyperhidrosis include:\\nInfec... | \n",
" NaN | \n",
" Diagnosing hyperhidrosis may start with your h... | \n",
" Treating hyperhidrosis may start with treating... | \n",
" Hyperhidrosis can be the cause of discomfort a... | \n",
" You may start by seeing your primary care prov... | \n",
" The following suggestions may help control swe... | \n",
"
\n",
" \n",
" | 2 | \n",
" Bartholin's cyst | \n",
" https://www.mayoclinic.org/diseases-conditions... | \n",
" https://www.mayoclinic.org/diseases-conditions... | \n",
" https://www.mayoclinic.org/diseases-conditions... | \n",
" The Bartholin's (BAHR-toe-linz) glands are loc... | \n",
" If you have a small, noninfected Bartholin's c... | \n",
" Call your doctor if you have a painful lump ne... | \n",
" Experts believe that the cause of a Bartholin'... | \n",
" NaN | \n",
" A Bartholin's cyst or abscess may recur and ag... | \n",
" There's no way to prevent a Bartholin's cyst. ... | \n",
" To diagnose a Bartholin's cyst, your doctor ma... | \n",
" Often a Bartholin's cyst requires no treatment... | \n",
" NaN | \n",
" Your first appointment will likely be with eit... | \n",
" NaN | \n",
"
\n",
" \n",
" | 3 | \n",
" Infant reflux | \n",
" https://www.mayoclinic.org/diseases-conditions... | \n",
" https://www.mayoclinic.org/diseases-conditions... | \n",
" NaN | \n",
" Infant reflux is when a baby spits up liquid o... | \n",
" Most of the time, infant reflux isn't a cause ... | \n",
" See a healthcare professional if a baby:\\nIsn'... | \n",
" In infants, the ring of muscle between the eso... | \n",
" Infant reflux is common. But some things make ... | \n",
" Infant reflux usually gets better on its own. ... | \n",
" NaN | \n",
" To diagnose infant reflux, a healthcare profes... | \n",
" For most babies, making some changes to feedin... | \n",
" NaN | \n",
" You may start by seeing your baby's primary he... | \n",
" To minimize reflux:\\nFeed your baby in an upri... | \n",
"
\n",
" \n",
" | 4 | \n",
" Hidradenitis suppurativa | \n",
" https://www.mayoclinic.org/diseases-conditions... | \n",
" https://www.mayoclinic.org/diseases-conditions... | \n",
" https://www.mayoclinic.org/diseases-conditions... | \n",
" Hidradenitis suppurativa (hi-drad-uh-NIE-tis s... | \n",
" Hidradenitis suppurativa can affect one or sev... | \n",
" Early diagnosis of hidradenitis suppurativa is... | \n",
" Hidradenitis suppurativa develops when hair fo... | \n",
" Factors that increase your chance of developin... | \n",
" Persistent and severe hidradenitis suppurativa... | \n",
" NaN | \n",
" Hidradenitis suppurativa can be mistaken for p... | \n",
" Treatment with medicines, surgery or both can ... | \n",
" Hidradenitis suppurativa can be a challenge to... | \n",
" You'll likely first see your primary care prov... | \n",
" Mild hidradenitis suppurativa can sometimes be... | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" disease \\\n",
"0 Atrial fibrillation \n",
"1 Hyperhidrosis \n",
"2 Bartholin's cyst \n",
"3 Infant reflux \n",
"4 Hidradenitis suppurativa \n",
"\n",
" main_link \\\n",
"0 https://www.mayoclinic.org/diseases-conditions... \n",
"1 https://www.mayoclinic.org/diseases-conditions... \n",
"2 https://www.mayoclinic.org/diseases-conditions... \n",
"3 https://www.mayoclinic.org/diseases-conditions... \n",
"4 https://www.mayoclinic.org/diseases-conditions... \n",
"\n",
" Diagnosis_treatment_link \\\n",
"0 https://www.mayoclinic.org/diseases-conditions... \n",
"1 https://www.mayoclinic.org/diseases-conditions... \n",
"2 https://www.mayoclinic.org/diseases-conditions... \n",
"3 https://www.mayoclinic.org/diseases-conditions... \n",
"4 https://www.mayoclinic.org/diseases-conditions... \n",
"\n",
" Doctors_departments_link \\\n",
"0 https://www.mayoclinic.org/diseases-conditions... \n",
"1 https://www.mayoclinic.org/diseases-conditions... \n",
"2 https://www.mayoclinic.org/diseases-conditions... \n",
"3 NaN \n",
"4 https://www.mayoclinic.org/diseases-conditions... \n",
"\n",
" Overview \\\n",
"0 Atrial fibrillation (AFib) is an irregular and... \n",
"1 Hyperhidrosis (hi-pur-hi-DROE-sis) is excessiv... \n",
"2 The Bartholin's (BAHR-toe-linz) glands are loc... \n",
"3 Infant reflux is when a baby spits up liquid o... \n",
"4 Hidradenitis suppurativa (hi-drad-uh-NIE-tis s... \n",
"\n",
" Symptoms \\\n",
"0 Symptoms ofAFibmay include:\\nFeelings of a fas... \n",
"1 The main symptom of hyperhidrosis is heavy swe... \n",
"2 If you have a small, noninfected Bartholin's c... \n",
"3 Most of the time, infant reflux isn't a cause ... \n",
"4 Hidradenitis suppurativa can affect one or sev... \n",
"\n",
" When to see a doctor \\\n",
"0 If you have symptoms of atrial fibrillation, m... \n",
"1 Sometimes excessive sweating is a sign of a se... \n",
"2 Call your doctor if you have a painful lump ne... \n",
"3 See a healthcare professional if a baby:\\nIsn'... \n",
"4 Early diagnosis of hidradenitis suppurativa is... \n",
"\n",
" Causes \\\n",
"0 To understand the causes of atrial fibrillatio... \n",
"1 Sweating is the body's mechanism to cool itsel... \n",
"2 Experts believe that the cause of a Bartholin'... \n",
"3 In infants, the ring of muscle between the eso... \n",
"4 Hidradenitis suppurativa develops when hair fo... \n",
"\n",
" Risk factors \\\n",
"0 Things that can increase the risk of atrial fi... \n",
"1 Risk factors for hyperhidrosis include:\\nHavin... \n",
"2 NaN \n",
"3 Infant reflux is common. But some things make ... \n",
"4 Factors that increase your chance of developin... \n",
"\n",
" Complications \\\n",
"0 Blood clots are a dangerous complication of at... \n",
"1 Complications of hyperhidrosis include:\\nInfec... \n",
"2 A Bartholin's cyst or abscess may recur and ag... \n",
"3 Infant reflux usually gets better on its own. ... \n",
"4 Persistent and severe hidradenitis suppurativa... \n",
"\n",
" Prevention \\\n",
"0 Healthy lifestyle choices can reduce the risk ... \n",
"1 NaN \n",
"2 There's no way to prevent a Bartholin's cyst. ... \n",
"3 NaN \n",
"4 NaN \n",
"\n",
" Diagnosis \\\n",
"0 You may not know you have atrial fibrillation ... \n",
"1 Diagnosing hyperhidrosis may start with your h... \n",
"2 To diagnose a Bartholin's cyst, your doctor ma... \n",
"3 To diagnose infant reflux, a healthcare profes... \n",
"4 Hidradenitis suppurativa can be mistaken for p... \n",
"\n",
" Treatment \\\n",
"0 The goals of atrial fibrillation treatment are... \n",
"1 Treating hyperhidrosis may start with treating... \n",
"2 Often a Bartholin's cyst requires no treatment... \n",
"3 For most babies, making some changes to feedin... \n",
"4 Treatment with medicines, surgery or both can ... \n",
"\n",
" Coping and support \\\n",
"0 NaN \n",
"1 Hyperhidrosis can be the cause of discomfort a... \n",
"2 NaN \n",
"3 NaN \n",
"4 Hidradenitis suppurativa can be a challenge to... \n",
"\n",
" Preparing for your appointment \\\n",
"0 If you have an irregular or pounding heartbeat... \n",
"1 You may start by seeing your primary care prov... \n",
"2 Your first appointment will likely be with eit... \n",
"3 You may start by seeing your baby's primary he... \n",
"4 You'll likely first see your primary care prov... \n",
"\n",
" Lifestyle and home remedies \n",
"0 Following a heart-healthy lifestyle can help p... \n",
"1 The following suggestions may help control swe... \n",
"2 NaN \n",
"3 To minimize reflux:\\nFeed your baby in an upri... \n",
"4 Mild hidradenitis suppurativa can sometimes be... "
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"csv_path = \"mayo_diseases.csv\"\n",
"\n",
"df = pd.read_csv(csv_path)\n",
"print(\"Loaded CSV\")\n",
"df.head()\n"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Device set to use cpu\n",
"🧼 Cleaning Symptoms: 100%|██████████| 132/132 [00:02<00:00, 57.72it/s]\n",
"🧼 Cleaning Symptoms: 100%|██████████| 132/132 [00:06<00:00, 21.30it/s]\n",
"🧼 Cleaning Symptoms: 100%|██████████| 132/132 [00:00, ?it/s]\n"
]
}
],
"source": [
"from tqdm import tqdm\n",
"tqdm.pandas(desc=\"🧼 Cleaning Symptoms\")\n",
"\n",
"# Initialize processing classes\n",
"text_cleaner = Text_Preprocessing()\n",
"ner_filter = RemoveUselessWords()\n",
"\n",
"# Step 1: Clean the raw symptom text\n",
"df[\"symptoms_cleaned\"] = df[\"Symptoms\"].progress_apply(lambda x: text_cleaner.go_on(x))\n",
"\n",
"# Step 2: Apply NER filtering to remove unimportant entities\n",
"df[\"symptoms_filtered\"] = df[\"symptoms_cleaned\"].progress_apply(lambda x: ner_filter.process_entities(x))\n",
"\n",
"# Step 3: Convert list of symptoms to a single space-separated string (for embedding)\n",
"df[\"symptoms_main\"] = df[\"symptoms_filtered\"].progress_apply(lambda x: \" \".join(x))\n",
"\n",
"# Show preview\n"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"📄 Creating Documents (Rows): 100%|██████████| 132/132 [00:00<00:00, 170.06it/s]"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"✅ Total documents created: 4412\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"\n"
]
}
],
"source": [
"from tqdm import tqdm\n",
"from langchain.schema import Document\n",
"\n",
"documents = []\n",
"\n",
"# Outer loop: iterate through each row (disease)\n",
"for _, row in tqdm(df.iterrows(), total=len(df), desc=\"📄 Creating Documents (Rows)\"):\n",
" disease = row[\"disease\"]\n",
" words = row[\"symptoms_main\"].split()\n",
"\n",
" # Inner loop: iterate through each symptom keyword (word)\n",
" for word in tqdm(words, desc=f\"🧠 Embedding words for {disease}\", leave=False):\n",
" documents.append(Document(page_content=word.strip(), metadata={\"disease\": disease}))\n",
"\n",
"print(f\"✅ Total documents created: {len(documents)}\")\n"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"C:\\Users\\harme\\AppData\\Local\\Temp\\ipykernel_3340\\3413216380.py:1: LangChainDeprecationWarning: The class `HuggingFaceEmbeddings` was deprecated in LangChain 0.2.2 and will be removed in 1.0. An updated version of the class exists in the :class:`~langchain-huggingface package and should be used instead. To use it run `pip install -U :class:`~langchain-huggingface` and import as `from :class:`~langchain_huggingface import HuggingFaceEmbeddings``.\n",
" embedder = HuggingFaceEmbeddings(model_name=\"all-MiniLM-L6-v2\")\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"WARNING:tensorflow:From c:\\Users\\harme\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\tf_keras\\src\\losses.py:2976: The name tf.losses.sparse_softmax_cross_entropy is deprecated. Please use tf.compat.v1.losses.sparse_softmax_cross_entropy instead.\n",
"\n",
"✅ Vector store saved at Vector/symptom_faiss_db\n"
]
}
],
"source": [
"embedder = HuggingFaceEmbeddings(model_name=\"all-MiniLM-L6-v2\")\n",
"\n",
"vectorstore = FAISS.from_documents(documents, embedder)\n",
"\n",
"save_path = \"Vector/symptom_faiss_db\"\n",
"vectorstore.save_local(save_path)\n",
"\n",
"print(f\"✅ Vector store saved at {save_path}\")\n"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"\"If you have a small, noninfected Bartholin's cyst, you may not notice it. If the cyst grows, you might feel a lump or mass near your vaginal opening. Although a cyst is usually painless, it can be tender.\\n\\nA full-blown infection of a Bartholin's cyst can occur in a matter of days. If the cyst becomes infected, you may experience:\\n\\nA Bartholin's cyst or abscess typically occurs on only one side of the vaginal opening.\""
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df[\"Symptoms\"][2]"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"1 Hyperhidrosis\n",
"2 Bartholin's cyst\n",
"3 Infant reflux\n",
"4 Hidradenitis suppurativa\n",
"5 HIV/AIDS\n",
"6 Acute myelogenous leukemia\n",
"7 Guillain-Barre syndrome\n",
"8 Acute kidney injury\n",
"9 Acute lymphocytic leukemia\n",
"10 Acute lymphocytic leukemia\n",
"11 Acute myelogenous leukemia\n",
"12 Acute myelogenous leukemia\n",
"13 Acute myelogenous leukemia\n",
"14 Radiation sickness\n",
"15 Radiation sickness\n",
"16 Acute kidney injury\n",
"17 ARDS\n",
"18 Acute sinusitis\n",
"19 Autoimmune epilepsy\n",
"20 Alcohol use disorder\n",
"21 Compulsive gambling\n",
"22 Nicotine dependence\n",
"23 Mesenteric lymphadenitis\n",
"24 Attention-deficit/hyperactivity disorder (ADHD...\n",
"25 Adult attention-deficit/hyperactivity disorder...\n",
"26 Frozen shoulder\n",
"27 Childhood schizophrenia\n",
"28 Benign adrenal tumors\n",
"29 Autoimmune encephalitis\n",
"30 Acute flaccid myelitis (AFM)\n",
"31 Dry macular degeneration\n",
"32 Macular degeneration, wet\n",
"33 Myelofibrosis\n",
"34 Guillain-Barre syndrome\n",
"35 HIV/AIDS\n",
"36 Alcohol use disorder\n",
"37 Alcoholic hepatitis\n",
"38 Churg-Strauss syndrome\n",
"39 Churg-Strauss syndrome\n",
"40 Hay fever\n",
"41 Dust mite allergy\n",
"42 Egg allergy\n",
"43 Food allergy\n",
"44 Latex allergy\n",
"45 Milk allergy\n",
"46 Mold allergy\n",
"47 Nickel allergy\n",
"48 Peanut allergy\n",
"49 Penicillin allergy\n",
"50 Pet allergy\n",
"51 Shellfish allergy\n",
"52 Wheat allergy\n",
"53 Hair loss\n",
"54 Amyotrophic lateral sclerosis (ALS)\n",
"55 Dry socket\n",
"56 Atypical genitalia\n",
"57 Lazy eye (amblyopia)\n",
"58 Chagas disease\n",
"59 Transient global amnesia\n",
"Name: disease, dtype: object"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df[\"disease\"][1:60]"
]
},
{
"cell_type": "code",
"execution_count": 66,
"metadata": {},
"outputs": [],
"source": [
"user_input = \"I'm vomiting violently with skin burns after radiation therapy\""
]
},
{
"cell_type": "code",
"execution_count": 47,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Device set to use cpu\n"
]
}
],
"source": [
"sys.path.append(os.path.abspath(os.path.join(os.getcwd(), \"..\")))\n",
"\n",
"from backend.utils.text_cleaning import Text_Preprocessing\n",
"from backend.utils.filtering_with_ner import RemoveUselessWords\n",
"text_cleaner = Text_Preprocessing()\n",
"ner_filter = RemoveUselessWords()"
]
},
{
"cell_type": "code",
"execution_count": 67,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"['vomit', 'skin', 'radiation therapy']"
]
},
"execution_count": 67,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"text = text_cleaner.go_on(user_input)\n",
"text = ner_filter.process_entities(text)\n",
"text"
]
},
{
"cell_type": "code",
"execution_count": 68,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'vomit skin radiation therapy'"
]
},
"execution_count": 68,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"text = \" \".join(text)\n",
"text"
]
},
{
"cell_type": "code",
"execution_count": 69,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"🔍 Top 5 matches for: 'vomit skin radiation therapy'\n",
"\n",
"🏥 Match #1:\n",
" Disease: Peanut allergy\n",
" Confidence: 0.8991\n",
" Key Symptom: vomiting\n",
"\n",
"🏥 Match #2:\n",
" Disease: Alcohol use disorder\n",
" Confidence: 0.9163\n",
" Key Symptom: vomit\n",
"\n",
"🏥 Match #3:\n",
" Disease: Mesenteric lymphadenitis\n",
" Confidence: 0.9163\n",
" Key Symptom: vomit\n",
"\n",
"🏥 Match #4:\n",
" Disease: Alcohol use disorder\n",
" Confidence: 0.9163\n",
" Key Symptom: vomit\n",
"\n",
"🏥 Match #5:\n",
" Disease: Alcoholic hepatitis\n",
" Confidence: 0.9163\n",
" Key Symptom: vomit\n",
"\n",
"🏥 Match #6:\n",
" Disease: Food allergy\n",
" Confidence: 0.9163\n",
" Key Symptom: vomit\n",
"\n",
"🏥 Match #7:\n",
" Disease: Shellfish allergy\n",
" Confidence: 0.9163\n",
" Key Symptom: vomit\n",
"\n",
"🏥 Match #8:\n",
" Disease: Viral hemorrhagic fevers\n",
" Confidence: 0.9163\n",
" Key Symptom: vomit\n",
"\n",
"🏥 Match #9:\n",
" Disease: Viral hemorrhagic fevers\n",
" Confidence: 0.9163\n",
" Key Symptom: vomit\n",
"\n",
"🏥 Match #10:\n",
" Disease: Bird flu (avian influenza)\n",
" Confidence: 0.9163\n",
" Key Symptom: vomit\n",
"\n",
"🏥 Match #11:\n",
" Disease: Radiation sickness\n",
" Confidence: 0.9310\n",
" Key Symptom: radiation\n",
"\n",
"🏥 Match #12:\n",
" Disease: Radiation sickness\n",
" Confidence: 0.9310\n",
" Key Symptom: radiation\n",
"\n",
"🏥 Match #13:\n",
" Disease: Radiation sickness\n",
" Confidence: 0.9310\n",
" Key Symptom: radiation\n",
"\n",
"🏥 Match #14:\n",
" Disease: Radiation sickness\n",
" Confidence: 0.9310\n",
" Key Symptom: radiation\n",
"\n",
"🏥 Match #15:\n",
" Disease: Radiation sickness\n",
" Confidence: 0.9310\n",
" Key Symptom: radiation\n",
"\n"
]
}
],
"source": [
"from langchain_community.vectorstores import FAISS\n",
"from langchain_community.embeddings import HuggingFaceEmbeddings\n",
"\n",
"# 1. Load your saved vector store\n",
"save_path = \"Vector/symptom_faiss_db\"\n",
"vectorstore = FAISS.load_local(\n",
" folder_path=save_path,\n",
" embeddings=HuggingFaceEmbeddings(model_name=\"all-MiniLM-L6-v2\"),\n",
" allow_dangerous_deserialization=True # Required for loading your trusted local file\n",
")\n",
"\n",
"# 2. Your symptom text (replace with actual input)\n",
"symptom_text = text # Example input\n",
"\n",
"# 3. Find top 5 matches with scores\n",
"similar_docs = vectorstore.similarity_search_with_score(symptom_text, k=15) # Get top 5 matches\n",
"\n",
"if similar_docs:\n",
" print(f\"🔍 Top 5 matches for: '{symptom_text}'\\n\")\n",
" for rank, (doc, score) in enumerate(similar_docs, 1):\n",
" print(f\"🏥 Match #{rank}:\")\n",
" print(f\" Disease: {doc.metadata['disease']}\")\n",
" print(f\" Confidence: {score:.4f}\") # Higher = more similar\n",
" print(f\" Key Symptom: {doc.page_content}\\n\")\n",
"else:\n",
" print(\"❌ No matches found\")"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"('Symptoms', 87.5, 1)\n"
]
}
],
"source": [
"from rapidfuzz import fuzz, process\n",
"\n",
"query = \"I need symptoms for cold, how it works?\"\n",
"columns = [\"Overview\", \"Symptoms\", \"Causes\", \"Risk factors\", \"Treatment\"]\n",
"\n",
"best_match = process.extractOne(query, columns, scorer=fuzz.partial_ratio)\n",
"print(best_match)\n",
"# Example output: (\"Symptoms\", 86.0)\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"pip uninstall spacy scispacy en-ner-bc5cdr-md -y\n",
"pip install spacy==3.2.6\n",
"pip install scispacy==0.5.0\n",
"pip install https://s3-us-west-2.amazonaws.com/ai2-s2-scispacy/releases/v0.5.0/en_ner_bc5cdr_md-0.5.0.tar.gz\n"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"['shortness of breath']\n"
]
}
],
"source": [
"import spacy\n",
"\n",
"# Load the biomedical NER model\n",
"nlp = spacy.load(\"en_ner_bc5cdr_md\")\n",
"\n",
"def extract_symptoms(text):\n",
" doc = nlp(text)\n",
" symptoms = [ent.text for ent in doc.ents if ent.label_ == \"DISEASE\"]\n",
" return symptoms\n",
"\n",
"# Example usage\n",
"user_text = \"I have been coughing a lot and feeling shortness of breath.\"\n",
"print(extract_symptoms(user_text))\n"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"[nltk_data] Downloading package wordnet to /home/ml/nltk_data...\n"
]
}
],
"source": [
"import nltk\n",
"nltk.download('wordnet')\n",
"\n",
"from nltk.corpus import wordnet\n",
"\n",
"def get_synonyms(word):\n",
" synonyms = set()\n",
" for syn in wordnet.synsets(word):\n",
" for lemma in syn.lemmas():\n",
" synonyms.add(lemma.name().replace(\"_\", \" \"))\n",
" return list(synonyms)\n"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"['hint',\n",
" 'breathing space',\n",
" 'breath',\n",
" 'breathing place',\n",
" 'breathing spell',\n",
" 'intimation',\n",
" 'breathing time',\n",
" 'breather']"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"get_synonyms(\"breath\")"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'fever', 'cough'}\n",
"2\n"
]
}
],
"source": [
"A = {\"cough\", \"fever\", \"fatigue\"}\n",
"B = {\"cough\", \"sore throat\", \"fever\"}\n",
"\n",
"overlap = A.intersection(B)\n",
"print(overlap) # {'cough', 'fever'}\n",
"print(len(overlap)) # 2\n"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/home/ml/Documents/SmartHealth-LLM/myenv/lib/python3.9/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n",
" from .autonotebook import tqdm as notebook_tqdm\n",
"\n",
"A module that was compiled using NumPy 1.x cannot be run in\n",
"NumPy 2.0.2 as it may crash. To support both 1.x and 2.x\n",
"versions of NumPy, modules must be compiled with NumPy 2.0.\n",
"Some module may need to rebuild instead e.g. with 'pybind11>=2.12'.\n",
"\n",
"If you are a user of the module, the easiest solution will be to\n",
"downgrade to 'numpy<2' or try to upgrade the affected module.\n",
"We expect that some modules will need time to support NumPy 2.\n",
"\n",
"Traceback (most recent call last): File \"/usr/lib/python3.9/runpy.py\", line 197, in _run_module_as_main\n",
" return _run_code(code, main_globals, None,\n",
" File \"/usr/lib/python3.9/runpy.py\", line 87, in _run_code\n",
" exec(code, run_globals)\n",
" File \"/home/ml/Documents/SmartHealth-LLM/myenv/lib/python3.9/site-packages/ipykernel_launcher.py\", line 18, in \n",
" app.launch_new_instance()\n",
" File \"/home/ml/Documents/SmartHealth-LLM/myenv/lib/python3.9/site-packages/traitlets/config/application.py\", line 1075, in launch_instance\n",
" app.start()\n",
" File \"/home/ml/Documents/SmartHealth-LLM/myenv/lib/python3.9/site-packages/ipykernel/kernelapp.py\", line 739, in start\n",
" self.io_loop.start()\n",
" File \"/home/ml/Documents/SmartHealth-LLM/myenv/lib/python3.9/site-packages/tornado/platform/asyncio.py\", line 211, in start\n",
" self.asyncio_loop.run_forever()\n",
" File \"/usr/lib/python3.9/asyncio/base_events.py\", line 601, in run_forever\n",
" self._run_once()\n",
" File \"/usr/lib/python3.9/asyncio/base_events.py\", line 1905, in _run_once\n",
" handle._run()\n",
" File \"/usr/lib/python3.9/asyncio/events.py\", line 80, in _run\n",
" self._context.run(self._callback, *self._args)\n",
" File \"/home/ml/Documents/SmartHealth-LLM/myenv/lib/python3.9/site-packages/ipykernel/kernelbase.py\", line 519, in dispatch_queue\n",
" await self.process_one()\n",
" File \"/home/ml/Documents/SmartHealth-LLM/myenv/lib/python3.9/site-packages/ipykernel/kernelbase.py\", line 508, in process_one\n",
" await dispatch(*args)\n",
" File \"/home/ml/Documents/SmartHealth-LLM/myenv/lib/python3.9/site-packages/ipykernel/kernelbase.py\", line 400, in dispatch_shell\n",
" await result\n",
" File \"/home/ml/Documents/SmartHealth-LLM/myenv/lib/python3.9/site-packages/ipykernel/ipkernel.py\", line 368, in execute_request\n",
" await super().execute_request(stream, ident, parent)\n",
" File \"/home/ml/Documents/SmartHealth-LLM/myenv/lib/python3.9/site-packages/ipykernel/kernelbase.py\", line 767, in execute_request\n",
" reply_content = await reply_content\n",
" File \"/home/ml/Documents/SmartHealth-LLM/myenv/lib/python3.9/site-packages/ipykernel/ipkernel.py\", line 455, in do_execute\n",
" res = shell.run_cell(\n",
" File \"/home/ml/Documents/SmartHealth-LLM/myenv/lib/python3.9/site-packages/ipykernel/zmqshell.py\", line 577, in run_cell\n",
" return super().run_cell(*args, **kwargs)\n",
" File \"/home/ml/Documents/SmartHealth-LLM/myenv/lib/python3.9/site-packages/IPython/core/interactiveshell.py\", line 3048, in run_cell\n",
" result = self._run_cell(\n",
" File \"/home/ml/Documents/SmartHealth-LLM/myenv/lib/python3.9/site-packages/IPython/core/interactiveshell.py\", line 3103, in _run_cell\n",
" result = runner(coro)\n",
" File \"/home/ml/Documents/SmartHealth-LLM/myenv/lib/python3.9/site-packages/IPython/core/async_helpers.py\", line 129, in _pseudo_sync_runner\n",
" coro.send(None)\n",
" File \"/home/ml/Documents/SmartHealth-LLM/myenv/lib/python3.9/site-packages/IPython/core/interactiveshell.py\", line 3308, in run_cell_async\n",
" has_raised = await self.run_ast_nodes(code_ast.body, cell_name,\n",
" File \"/home/ml/Documents/SmartHealth-LLM/myenv/lib/python3.9/site-packages/IPython/core/interactiveshell.py\", line 3490, in run_ast_nodes\n",
" if await self.run_code(code, result, async_=asy):\n",
" File \"/home/ml/Documents/SmartHealth-LLM/myenv/lib/python3.9/site-packages/IPython/core/interactiveshell.py\", line 3550, in run_code\n",
" exec(code_obj, self.user_global_ns, self.user_ns)\n",
" File \"/tmp/ipykernel_11859/3834083871.py\", line 2, in \n",
" from transformers import pipeline\n",
" File \"/home/ml/Documents/SmartHealth-LLM/myenv/lib/python3.9/site-packages/transformers/utils/import_utils.py\", line 1174, in __getattr__\n",
" module = self._get_module(self._class_to_module[name])\n",
" File \"/home/ml/Documents/SmartHealth-LLM/myenv/lib/python3.9/site-packages/transformers/utils/import_utils.py\", line 1184, in _get_module\n",
" return importlib.import_module(\".\" + module_name, self.__name__)\n",
" File \"/usr/lib/python3.9/importlib/__init__.py\", line 127, in import_module\n",
" return _bootstrap._gcd_import(name[level:], package, level)\n",
" File \"/home/ml/Documents/SmartHealth-LLM/myenv/lib/python3.9/site-packages/transformers/pipelines/__init__.py\", line 28, in \n",
" from ..image_processing_utils import BaseImageProcessor\n",
" File \"/home/ml/Documents/SmartHealth-LLM/myenv/lib/python3.9/site-packages/transformers/image_processing_utils.py\", line 28, in \n",
" from .image_transforms import center_crop, normalize, rescale\n",
" File \"/home/ml/Documents/SmartHealth-LLM/myenv/lib/python3.9/site-packages/transformers/image_transforms.py\", line 44, in \n",
" import torch\n",
" File \"/home/ml/Documents/SmartHealth-LLM/myenv/lib/python3.9/site-packages/torch/__init__.py\", line 1471, in \n",
" from .functional import * # noqa: F403\n",
" File \"/home/ml/Documents/SmartHealth-LLM/myenv/lib/python3.9/site-packages/torch/functional.py\", line 9, in \n",
" import torch.nn.functional as F\n",
" File \"/home/ml/Documents/SmartHealth-LLM/myenv/lib/python3.9/site-packages/torch/nn/__init__.py\", line 1, in \n",
" from .modules import * # noqa: F403\n",
" File \"/home/ml/Documents/SmartHealth-LLM/myenv/lib/python3.9/site-packages/torch/nn/modules/__init__.py\", line 35, in \n",
" from .transformer import TransformerEncoder, TransformerDecoder, \\\n",
" File \"/home/ml/Documents/SmartHealth-LLM/myenv/lib/python3.9/site-packages/torch/nn/modules/transformer.py\", line 20, in \n",
" device: torch.device = torch.device(torch._C._get_default_device()), # torch.device('cpu'),\n",
"/home/ml/Documents/SmartHealth-LLM/myenv/lib/python3.9/site-packages/torch/nn/modules/transformer.py:20: UserWarning: Failed to initialize NumPy: _ARRAY_API not found (Triggered internally at ../torch/csrc/utils/tensor_numpy.cpp:84.)\n",
" device: torch.device = torch.device(torch._C._get_default_device()), # torch.device('cpu'),\n",
"/home/ml/Documents/SmartHealth-LLM/myenv/lib/python3.9/site-packages/transformers/utils/generic.py:311: UserWarning: torch.utils._pytree._register_pytree_node is deprecated. Please use torch.utils._pytree.register_pytree_node instead.\n",
" torch.utils._pytree._register_pytree_node(\n",
"/home/ml/Documents/SmartHealth-LLM/myenv/lib/python3.9/site-packages/huggingface_hub/file_download.py:945: FutureWarning: `resume_download` is deprecated and will be removed in version 1.0.0. Downloads always resume when possible. If you want to force a new download, use `force_download=True`.\n",
" warnings.warn(\n"
]
},
{
"ename": "OSError",
"evalue": "d4data/biobert_ner is not a local folder and is not a valid model identifier listed on 'https://huggingface.co/models'\nIf this is a private repository, make sure to pass a token having permission to this repo either by logging in with `huggingface-cli login` or by passing `token=`",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mHTTPError\u001b[0m Traceback (most recent call last)",
"File \u001b[0;32m~/Documents/SmartHealth-LLM/myenv/lib/python3.9/site-packages/huggingface_hub/utils/_http.py:409\u001b[0m, in \u001b[0;36mhf_raise_for_status\u001b[0;34m(response, endpoint_name)\u001b[0m\n\u001b[1;32m 408\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[0;32m--> 409\u001b[0m \u001b[43mresponse\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mraise_for_status\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 410\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m HTTPError \u001b[38;5;28;01mas\u001b[39;00m e:\n",
"File \u001b[0;32m~/Documents/SmartHealth-LLM/myenv/lib/python3.9/site-packages/requests/models.py:1026\u001b[0m, in \u001b[0;36mResponse.raise_for_status\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 1025\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m http_error_msg:\n\u001b[0;32m-> 1026\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m HTTPError(http_error_msg, response\u001b[38;5;241m=\u001b[39m\u001b[38;5;28mself\u001b[39m)\n",
"\u001b[0;31mHTTPError\u001b[0m: 401 Client Error: Unauthorized for url: https://huggingface.co/d4data/biobert_ner/resolve/main/tokenizer_config.json",
"\nThe above exception was the direct cause of the following exception:\n",
"\u001b[0;31mRepositoryNotFoundError\u001b[0m Traceback (most recent call last)",
"File \u001b[0;32m~/Documents/SmartHealth-LLM/myenv/lib/python3.9/site-packages/transformers/utils/hub.py:429\u001b[0m, in \u001b[0;36mcached_file\u001b[0;34m(path_or_repo_id, filename, cache_dir, force_download, resume_download, proxies, token, revision, local_files_only, subfolder, repo_type, user_agent, _raise_exceptions_for_missing_entries, _raise_exceptions_for_connection_errors, _commit_hash, **deprecated_kwargs)\u001b[0m\n\u001b[1;32m 427\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[1;32m 428\u001b[0m \u001b[38;5;66;03m# Load from URL or cache if already cached\u001b[39;00m\n\u001b[0;32m--> 429\u001b[0m resolved_file \u001b[38;5;241m=\u001b[39m \u001b[43mhf_hub_download\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m 430\u001b[0m \u001b[43m \u001b[49m\u001b[43mpath_or_repo_id\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 431\u001b[0m \u001b[43m \u001b[49m\u001b[43mfilename\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 432\u001b[0m \u001b[43m \u001b[49m\u001b[43msubfolder\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43;01mNone\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[38;5;28;43;01mif\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[38;5;28;43mlen\u001b[39;49m\u001b[43m(\u001b[49m\u001b[43msubfolder\u001b[49m\u001b[43m)\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m==\u001b[39;49m\u001b[43m \u001b[49m\u001b[38;5;241;43m0\u001b[39;49m\u001b[43m \u001b[49m\u001b[38;5;28;43;01melse\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[43msubfolder\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 433\u001b[0m \u001b[43m \u001b[49m\u001b[43mrepo_type\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mrepo_type\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 434\u001b[0m \u001b[43m \u001b[49m\u001b[43mrevision\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mrevision\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 435\u001b[0m \u001b[43m \u001b[49m\u001b[43mcache_dir\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mcache_dir\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 436\u001b[0m \u001b[43m \u001b[49m\u001b[43muser_agent\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43muser_agent\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 437\u001b[0m \u001b[43m \u001b[49m\u001b[43mforce_download\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mforce_download\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 438\u001b[0m \u001b[43m \u001b[49m\u001b[43mproxies\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mproxies\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 439\u001b[0m \u001b[43m \u001b[49m\u001b[43mresume_download\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mresume_download\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 440\u001b[0m \u001b[43m \u001b[49m\u001b[43mtoken\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mtoken\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 441\u001b[0m \u001b[43m \u001b[49m\u001b[43mlocal_files_only\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mlocal_files_only\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 442\u001b[0m \u001b[43m \u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 443\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m GatedRepoError \u001b[38;5;28;01mas\u001b[39;00m e:\n",
"File \u001b[0;32m~/Documents/SmartHealth-LLM/myenv/lib/python3.9/site-packages/huggingface_hub/utils/_validators.py:114\u001b[0m, in \u001b[0;36mvalidate_hf_hub_args.._inner_fn\u001b[0;34m(*args, **kwargs)\u001b[0m\n\u001b[1;32m 112\u001b[0m kwargs \u001b[38;5;241m=\u001b[39m smoothly_deprecate_use_auth_token(fn_name\u001b[38;5;241m=\u001b[39mfn\u001b[38;5;241m.\u001b[39m\u001b[38;5;18m__name__\u001b[39m, has_token\u001b[38;5;241m=\u001b[39mhas_token, kwargs\u001b[38;5;241m=\u001b[39mkwargs)\n\u001b[0;32m--> 114\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mfn\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43margs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n",
"File \u001b[0;32m~/Documents/SmartHealth-LLM/myenv/lib/python3.9/site-packages/huggingface_hub/file_download.py:1010\u001b[0m, in \u001b[0;36mhf_hub_download\u001b[0;34m(repo_id, filename, subfolder, repo_type, revision, library_name, library_version, cache_dir, local_dir, user_agent, force_download, proxies, etag_timeout, token, local_files_only, headers, endpoint, resume_download, force_filename, local_dir_use_symlinks)\u001b[0m\n\u001b[1;32m 1009\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[0;32m-> 1010\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43m_hf_hub_download_to_cache_dir\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m 1011\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;66;43;03m# Destination\u001b[39;49;00m\n\u001b[1;32m 1012\u001b[0m \u001b[43m \u001b[49m\u001b[43mcache_dir\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mcache_dir\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 1013\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;66;43;03m# File info\u001b[39;49;00m\n\u001b[1;32m 1014\u001b[0m \u001b[43m \u001b[49m\u001b[43mrepo_id\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mrepo_id\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 1015\u001b[0m \u001b[43m \u001b[49m\u001b[43mfilename\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mfilename\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 1016\u001b[0m \u001b[43m \u001b[49m\u001b[43mrepo_type\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mrepo_type\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 1017\u001b[0m \u001b[43m \u001b[49m\u001b[43mrevision\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mrevision\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 1018\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;66;43;03m# HTTP info\u001b[39;49;00m\n\u001b[1;32m 1019\u001b[0m \u001b[43m \u001b[49m\u001b[43mendpoint\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mendpoint\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 1020\u001b[0m \u001b[43m \u001b[49m\u001b[43metag_timeout\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43metag_timeout\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 1021\u001b[0m \u001b[43m \u001b[49m\u001b[43mheaders\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mhf_headers\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 1022\u001b[0m \u001b[43m \u001b[49m\u001b[43mproxies\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mproxies\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 1023\u001b[0m \u001b[43m \u001b[49m\u001b[43mtoken\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mtoken\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 1024\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;66;43;03m# Additional options\u001b[39;49;00m\n\u001b[1;32m 1025\u001b[0m \u001b[43m \u001b[49m\u001b[43mlocal_files_only\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mlocal_files_only\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 1026\u001b[0m \u001b[43m \u001b[49m\u001b[43mforce_download\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mforce_download\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 1027\u001b[0m \u001b[43m \u001b[49m\u001b[43m)\u001b[49m\n",
"File \u001b[0;32m~/Documents/SmartHealth-LLM/myenv/lib/python3.9/site-packages/huggingface_hub/file_download.py:1117\u001b[0m, in \u001b[0;36m_hf_hub_download_to_cache_dir\u001b[0;34m(cache_dir, repo_id, filename, repo_type, revision, endpoint, etag_timeout, headers, proxies, token, local_files_only, force_download)\u001b[0m\n\u001b[1;32m 1116\u001b[0m \u001b[38;5;66;03m# Otherwise, raise appropriate error\u001b[39;00m\n\u001b[0;32m-> 1117\u001b[0m \u001b[43m_raise_on_head_call_error\u001b[49m\u001b[43m(\u001b[49m\u001b[43mhead_call_error\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mforce_download\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mlocal_files_only\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 1119\u001b[0m \u001b[38;5;66;03m# From now on, etag, commit_hash, url and size are not None.\u001b[39;00m\n",
"File \u001b[0;32m~/Documents/SmartHealth-LLM/myenv/lib/python3.9/site-packages/huggingface_hub/file_download.py:1658\u001b[0m, in \u001b[0;36m_raise_on_head_call_error\u001b[0;34m(head_call_error, force_download, local_files_only)\u001b[0m\n\u001b[1;32m 1653\u001b[0m \u001b[38;5;28;01melif\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(head_call_error, (RepositoryNotFoundError, GatedRepoError)) \u001b[38;5;129;01mor\u001b[39;00m (\n\u001b[1;32m 1654\u001b[0m \u001b[38;5;28misinstance\u001b[39m(head_call_error, HfHubHTTPError) \u001b[38;5;129;01mand\u001b[39;00m head_call_error\u001b[38;5;241m.\u001b[39mresponse\u001b[38;5;241m.\u001b[39mstatus_code \u001b[38;5;241m==\u001b[39m \u001b[38;5;241m401\u001b[39m\n\u001b[1;32m 1655\u001b[0m ):\n\u001b[1;32m 1656\u001b[0m \u001b[38;5;66;03m# Repo not found or gated => let's raise the actual error\u001b[39;00m\n\u001b[1;32m 1657\u001b[0m \u001b[38;5;66;03m# Unauthorized => likely a token issue => let's raise the actual error\u001b[39;00m\n\u001b[0;32m-> 1658\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m head_call_error\n\u001b[1;32m 1659\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[1;32m 1660\u001b[0m \u001b[38;5;66;03m# Otherwise: most likely a connection issue or Hub downtime => let's warn the user\u001b[39;00m\n",
"File \u001b[0;32m~/Documents/SmartHealth-LLM/myenv/lib/python3.9/site-packages/huggingface_hub/file_download.py:1546\u001b[0m, in \u001b[0;36m_get_metadata_or_catch_error\u001b[0;34m(repo_id, filename, repo_type, revision, endpoint, proxies, etag_timeout, headers, token, local_files_only, relative_filename, storage_folder)\u001b[0m\n\u001b[1;32m 1545\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[0;32m-> 1546\u001b[0m metadata \u001b[38;5;241m=\u001b[39m \u001b[43mget_hf_file_metadata\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m 1547\u001b[0m \u001b[43m \u001b[49m\u001b[43murl\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43murl\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mproxies\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mproxies\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mtimeout\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43metag_timeout\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mheaders\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mheaders\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mtoken\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mtoken\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mendpoint\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mendpoint\u001b[49m\n\u001b[1;32m 1548\u001b[0m \u001b[43m \u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 1549\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m EntryNotFoundError \u001b[38;5;28;01mas\u001b[39;00m http_error:\n",
"File \u001b[0;32m~/Documents/SmartHealth-LLM/myenv/lib/python3.9/site-packages/huggingface_hub/utils/_validators.py:114\u001b[0m, in \u001b[0;36mvalidate_hf_hub_args.._inner_fn\u001b[0;34m(*args, **kwargs)\u001b[0m\n\u001b[1;32m 112\u001b[0m kwargs \u001b[38;5;241m=\u001b[39m smoothly_deprecate_use_auth_token(fn_name\u001b[38;5;241m=\u001b[39mfn\u001b[38;5;241m.\u001b[39m\u001b[38;5;18m__name__\u001b[39m, has_token\u001b[38;5;241m=\u001b[39mhas_token, kwargs\u001b[38;5;241m=\u001b[39mkwargs)\n\u001b[0;32m--> 114\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mfn\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43margs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n",
"File \u001b[0;32m~/Documents/SmartHealth-LLM/myenv/lib/python3.9/site-packages/huggingface_hub/file_download.py:1463\u001b[0m, in \u001b[0;36mget_hf_file_metadata\u001b[0;34m(url, token, proxies, timeout, library_name, library_version, user_agent, headers, endpoint)\u001b[0m\n\u001b[1;32m 1462\u001b[0m \u001b[38;5;66;03m# Retrieve metadata\u001b[39;00m\n\u001b[0;32m-> 1463\u001b[0m r \u001b[38;5;241m=\u001b[39m \u001b[43m_request_wrapper\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m 1464\u001b[0m \u001b[43m \u001b[49m\u001b[43mmethod\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mHEAD\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m,\u001b[49m\n\u001b[1;32m 1465\u001b[0m \u001b[43m \u001b[49m\u001b[43murl\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43murl\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 1466\u001b[0m \u001b[43m \u001b[49m\u001b[43mheaders\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mhf_headers\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 1467\u001b[0m \u001b[43m \u001b[49m\u001b[43mallow_redirects\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43;01mFalse\u001b[39;49;00m\u001b[43m,\u001b[49m\n\u001b[1;32m 1468\u001b[0m \u001b[43m \u001b[49m\u001b[43mfollow_relative_redirects\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43;01mTrue\u001b[39;49;00m\u001b[43m,\u001b[49m\n\u001b[1;32m 1469\u001b[0m \u001b[43m \u001b[49m\u001b[43mproxies\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mproxies\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 1470\u001b[0m \u001b[43m \u001b[49m\u001b[43mtimeout\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mtimeout\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 1471\u001b[0m \u001b[43m\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 1472\u001b[0m hf_raise_for_status(r)\n",
"File \u001b[0;32m~/Documents/SmartHealth-LLM/myenv/lib/python3.9/site-packages/huggingface_hub/file_download.py:286\u001b[0m, in \u001b[0;36m_request_wrapper\u001b[0;34m(method, url, follow_relative_redirects, **params)\u001b[0m\n\u001b[1;32m 285\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m follow_relative_redirects:\n\u001b[0;32m--> 286\u001b[0m response \u001b[38;5;241m=\u001b[39m \u001b[43m_request_wrapper\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m 287\u001b[0m \u001b[43m \u001b[49m\u001b[43mmethod\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mmethod\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 288\u001b[0m \u001b[43m \u001b[49m\u001b[43murl\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43murl\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 289\u001b[0m \u001b[43m \u001b[49m\u001b[43mfollow_relative_redirects\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43;01mFalse\u001b[39;49;00m\u001b[43m,\u001b[49m\n\u001b[1;32m 290\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mparams\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 291\u001b[0m \u001b[43m \u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 293\u001b[0m \u001b[38;5;66;03m# If redirection, we redirect only relative paths.\u001b[39;00m\n\u001b[1;32m 294\u001b[0m \u001b[38;5;66;03m# This is useful in case of a renamed repository.\u001b[39;00m\n",
"File \u001b[0;32m~/Documents/SmartHealth-LLM/myenv/lib/python3.9/site-packages/huggingface_hub/file_download.py:310\u001b[0m, in \u001b[0;36m_request_wrapper\u001b[0;34m(method, url, follow_relative_redirects, **params)\u001b[0m\n\u001b[1;32m 309\u001b[0m response \u001b[38;5;241m=\u001b[39m http_backoff(method\u001b[38;5;241m=\u001b[39mmethod, url\u001b[38;5;241m=\u001b[39murl, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mparams, retry_on_exceptions\u001b[38;5;241m=\u001b[39m(), retry_on_status_codes\u001b[38;5;241m=\u001b[39m(\u001b[38;5;241m429\u001b[39m,))\n\u001b[0;32m--> 310\u001b[0m \u001b[43mhf_raise_for_status\u001b[49m\u001b[43m(\u001b[49m\u001b[43mresponse\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 311\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m response\n",
"File \u001b[0;32m~/Documents/SmartHealth-LLM/myenv/lib/python3.9/site-packages/huggingface_hub/utils/_http.py:459\u001b[0m, in \u001b[0;36mhf_raise_for_status\u001b[0;34m(response, endpoint_name)\u001b[0m\n\u001b[1;32m 450\u001b[0m message \u001b[38;5;241m=\u001b[39m (\n\u001b[1;32m 451\u001b[0m \u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;132;01m{\u001b[39;00mresponse\u001b[38;5;241m.\u001b[39mstatus_code\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m Client Error.\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m 452\u001b[0m \u001b[38;5;241m+\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124m\"\u001b[39m\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 457\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m https://huggingface.co/docs/huggingface_hub/authentication\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m 458\u001b[0m )\n\u001b[0;32m--> 459\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m _format(RepositoryNotFoundError, message, response) \u001b[38;5;28;01mfrom\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;21;01me\u001b[39;00m\n\u001b[1;32m 461\u001b[0m \u001b[38;5;28;01melif\u001b[39;00m response\u001b[38;5;241m.\u001b[39mstatus_code \u001b[38;5;241m==\u001b[39m \u001b[38;5;241m400\u001b[39m:\n",
"\u001b[0;31mRepositoryNotFoundError\u001b[0m: 401 Client Error. (Request ID: Root=1-68b8cd7a-282fd379594fd81d21c9690d;b51f2694-395d-4048-b950-c346acb1de66)\n\nRepository Not Found for url: https://huggingface.co/d4data/biobert_ner/resolve/main/tokenizer_config.json.\nPlease make sure you specified the correct `repo_id` and `repo_type`.\nIf you are trying to access a private or gated repo, make sure you are authenticated. For more details, see https://huggingface.co/docs/huggingface_hub/authentication\nInvalid username or password.",
"\nThe above exception was the direct cause of the following exception:\n",
"\u001b[0;31mOSError\u001b[0m Traceback (most recent call last)",
"Cell \u001b[0;32mIn[1], line 4\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;21;01mtransformers\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;28;01mimport\u001b[39;00m AutoTokenizer, AutoModelForTokenClassification\n\u001b[1;32m 2\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;21;01mtransformers\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;28;01mimport\u001b[39;00m pipeline\n\u001b[0;32m----> 4\u001b[0m tokenizer \u001b[38;5;241m=\u001b[39m \u001b[43mAutoTokenizer\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mfrom_pretrained\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43md4data/biobert_ner\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m)\u001b[49m\n\u001b[1;32m 5\u001b[0m model \u001b[38;5;241m=\u001b[39m AutoModelForTokenClassification\u001b[38;5;241m.\u001b[39mfrom_pretrained(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124md4data/biobert_ner\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[1;32m 6\u001b[0m nlp \u001b[38;5;241m=\u001b[39m pipeline(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mner\u001b[39m\u001b[38;5;124m\"\u001b[39m, model\u001b[38;5;241m=\u001b[39mmodel, tokenizer\u001b[38;5;241m=\u001b[39mtokenizer)\n",
"File \u001b[0;32m~/Documents/SmartHealth-LLM/myenv/lib/python3.9/site-packages/transformers/models/auto/tokenization_auto.py:686\u001b[0m, in \u001b[0;36mAutoTokenizer.from_pretrained\u001b[0;34m(cls, pretrained_model_name_or_path, *inputs, **kwargs)\u001b[0m\n\u001b[1;32m 683\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m tokenizer_class\u001b[38;5;241m.\u001b[39mfrom_pretrained(pretrained_model_name_or_path, \u001b[38;5;241m*\u001b[39minputs, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs)\n\u001b[1;32m 685\u001b[0m \u001b[38;5;66;03m# Next, let's try to use the tokenizer_config file to get the tokenizer class.\u001b[39;00m\n\u001b[0;32m--> 686\u001b[0m tokenizer_config \u001b[38;5;241m=\u001b[39m \u001b[43mget_tokenizer_config\u001b[49m\u001b[43m(\u001b[49m\u001b[43mpretrained_model_name_or_path\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 687\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m_commit_hash\u001b[39m\u001b[38;5;124m\"\u001b[39m \u001b[38;5;129;01min\u001b[39;00m tokenizer_config:\n\u001b[1;32m 688\u001b[0m kwargs[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m_commit_hash\u001b[39m\u001b[38;5;124m\"\u001b[39m] \u001b[38;5;241m=\u001b[39m tokenizer_config[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m_commit_hash\u001b[39m\u001b[38;5;124m\"\u001b[39m]\n",
"File \u001b[0;32m~/Documents/SmartHealth-LLM/myenv/lib/python3.9/site-packages/transformers/models/auto/tokenization_auto.py:519\u001b[0m, in \u001b[0;36mget_tokenizer_config\u001b[0;34m(pretrained_model_name_or_path, cache_dir, force_download, resume_download, proxies, token, revision, local_files_only, subfolder, **kwargs)\u001b[0m\n\u001b[1;32m 516\u001b[0m token \u001b[38;5;241m=\u001b[39m use_auth_token\n\u001b[1;32m 518\u001b[0m commit_hash \u001b[38;5;241m=\u001b[39m kwargs\u001b[38;5;241m.\u001b[39mget(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m_commit_hash\u001b[39m\u001b[38;5;124m\"\u001b[39m, \u001b[38;5;28;01mNone\u001b[39;00m)\n\u001b[0;32m--> 519\u001b[0m resolved_config_file \u001b[38;5;241m=\u001b[39m \u001b[43mcached_file\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m 520\u001b[0m \u001b[43m \u001b[49m\u001b[43mpretrained_model_name_or_path\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 521\u001b[0m \u001b[43m \u001b[49m\u001b[43mTOKENIZER_CONFIG_FILE\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 522\u001b[0m \u001b[43m \u001b[49m\u001b[43mcache_dir\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mcache_dir\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 523\u001b[0m \u001b[43m \u001b[49m\u001b[43mforce_download\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mforce_download\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 524\u001b[0m \u001b[43m \u001b[49m\u001b[43mresume_download\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mresume_download\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 525\u001b[0m \u001b[43m \u001b[49m\u001b[43mproxies\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mproxies\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 526\u001b[0m \u001b[43m \u001b[49m\u001b[43mtoken\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mtoken\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 527\u001b[0m \u001b[43m \u001b[49m\u001b[43mrevision\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mrevision\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 528\u001b[0m \u001b[43m \u001b[49m\u001b[43mlocal_files_only\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mlocal_files_only\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 529\u001b[0m \u001b[43m \u001b[49m\u001b[43msubfolder\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43msubfolder\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 530\u001b[0m \u001b[43m \u001b[49m\u001b[43m_raise_exceptions_for_missing_entries\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43;01mFalse\u001b[39;49;00m\u001b[43m,\u001b[49m\n\u001b[1;32m 531\u001b[0m \u001b[43m \u001b[49m\u001b[43m_raise_exceptions_for_connection_errors\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43;01mFalse\u001b[39;49;00m\u001b[43m,\u001b[49m\n\u001b[1;32m 532\u001b[0m \u001b[43m \u001b[49m\u001b[43m_commit_hash\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mcommit_hash\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 533\u001b[0m \u001b[43m\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 534\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m resolved_config_file \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m:\n\u001b[1;32m 535\u001b[0m logger\u001b[38;5;241m.\u001b[39minfo(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mCould not locate the tokenizer configuration file, will try to use the model config instead.\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n",
"File \u001b[0;32m~/Documents/SmartHealth-LLM/myenv/lib/python3.9/site-packages/transformers/utils/hub.py:450\u001b[0m, in \u001b[0;36mcached_file\u001b[0;34m(path_or_repo_id, filename, cache_dir, force_download, resume_download, proxies, token, revision, local_files_only, subfolder, repo_type, user_agent, _raise_exceptions_for_missing_entries, _raise_exceptions_for_connection_errors, _commit_hash, **deprecated_kwargs)\u001b[0m\n\u001b[1;32m 444\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mEnvironmentError\u001b[39;00m(\n\u001b[1;32m 445\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mYou are trying to access a gated repo.\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124mMake sure to request access at \u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m 446\u001b[0m \u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mhttps://huggingface.co/\u001b[39m\u001b[38;5;132;01m{\u001b[39;00mpath_or_repo_id\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m and pass a token having permission to this repo either \u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m 447\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mby logging in with `huggingface-cli login` or by passing `token=`.\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m 448\u001b[0m ) \u001b[38;5;28;01mfrom\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;21;01me\u001b[39;00m\n\u001b[1;32m 449\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m RepositoryNotFoundError \u001b[38;5;28;01mas\u001b[39;00m e:\n\u001b[0;32m--> 450\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mEnvironmentError\u001b[39;00m(\n\u001b[1;32m 451\u001b[0m \u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;132;01m{\u001b[39;00mpath_or_repo_id\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m is not a local folder and is not a valid model identifier \u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m 452\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mlisted on \u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mhttps://huggingface.co/models\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124mIf this is a private repository, make sure to pass a token \u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m 453\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mhaving permission to this repo either by logging in with `huggingface-cli login` or by passing \u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m 454\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m`token=`\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m 455\u001b[0m ) \u001b[38;5;28;01mfrom\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;21;01me\u001b[39;00m\n\u001b[1;32m 456\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m RevisionNotFoundError \u001b[38;5;28;01mas\u001b[39;00m e:\n\u001b[1;32m 457\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mEnvironmentError\u001b[39;00m(\n\u001b[1;32m 458\u001b[0m \u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;132;01m{\u001b[39;00mrevision\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m is not a valid git identifier (branch name, tag name or commit id) that exists \u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m 459\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mfor this model name. Check the model page at \u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m 460\u001b[0m \u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mhttps://huggingface.co/\u001b[39m\u001b[38;5;132;01m{\u001b[39;00mpath_or_repo_id\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m for available revisions.\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m 461\u001b[0m ) \u001b[38;5;28;01mfrom\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;21;01me\u001b[39;00m\n",
"\u001b[0;31mOSError\u001b[0m: d4data/biobert_ner is not a local folder and is not a valid model identifier listed on 'https://huggingface.co/models'\nIf this is a private repository, make sure to pass a token having permission to this repo either by logging in with `huggingface-cli login` or by passing `token=`"
]
}
],
"source": [
"from transformers import AutoTokenizer, AutoModelForTokenClassification\n",
"from transformers import pipeline\n",
"\n",
"tokenizer = AutoTokenizer.from_pretrained(\"d4data/biobert_ner\")\n",
"model = AutoModelForTokenClassification.from_pretrained(\"d4data/biobert_ner\")\n",
"nlp = pipeline(\"ner\", model=model, tokenizer=tokenizer)\n",
"\n",
"text = \"The patient has cough and high fever.\"\n",
"symptoms = [ent['word'] for ent in nlp(text) if ent['entity'].startswith('B-')]\n"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"from dotenv import load_dotenv\n",
"import os\n",
"\n",
"load_dotenv()\n",
"groq_api_key = os.getenv(\"GROQ_API_KEY\")\n"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"import getpass\n",
"import os\n",
"\n",
"if not os.environ.get(\"GROQ_API_KEY\"):\n",
" os.environ[\"GROQ_API_KEY\"] = groq_api_key\n",
"\n",
"from langchain.chat_models import init_chat_model\n",
"\n",
"model = init_chat_model(\"llama-3.3-70b-versatile\", model_provider=\"groq\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"AIMessage(content='The name \"Harmesh\" is of Indian origin, specifically from the Punjabi and Hindi languages. It is a masculine given name that is composed of two words: \"Har\" and \"Mesh.\"\\n\\n\"Har\" is a common prefix in many Indian names, and it is derived from the Sanskrit word \"Hara,\" which means \"lord\" or \"God.\" In Hindu mythology, \"Har\" is also another name for Lord Shiva.\\n\\n\"Mesh\" is derived from the Sanskrit word \"Mesa,\" which means \"ram\" or \"Aries\" (the zodiac sign). In Indian astrology, \"Mesh\" is the first sign of the zodiac, representing strength, courage, and leadership.\\n\\nTogether, the name \"Harmesh\" can be interpreted to mean \"Lord of the Ram\" or \"God of Aries.\" It is a name that symbolizes strength, courage, and leadership, and is often associated with qualities such as confidence, determination, and adventurousness.\\n\\nIn Indian culture, the name \"Harmesh\" is often given to boys born under the sign of Aries, which is considered a strong and energetic sign. The name is also associated with the Hindu god Lord Shiva, who is revered as a powerful and destructive deity.\\n\\nOverall, the name \"Harmesh\" is a unique and meaningful name that reflects the cultural and spiritual heritage of India.', additional_kwargs={}, response_metadata={'token_usage': {'completion_tokens': 284, 'prompt_tokens': 44, 'total_tokens': 328, 'completion_time': 0.722106355, 'prompt_time': 0.017828118, 'queue_time': 0.046120782, 'total_time': 0.739934473}, 'model_name': 'llama-3.3-70b-versatile', 'system_fingerprint': 'fp_3f3b593e33', 'service_tier': 'on_demand', 'finish_reason': 'stop', 'logprobs': None}, id='run--d3d334cd-a8c1-4179-b6dd-a7a7f34ec1ab-0', usage_metadata={'input_tokens': 44, 'output_tokens': 284, 'total_tokens': 328})"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"model.invoke(\"\")"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/home/mcqueen/Documents/SmartHealth-LLM/venv/lib/python3.12/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n",
" from .autonotebook import tqdm as notebook_tqdm\n",
"Device set to use cpu\n"
]
}
],
"source": [
"# Use a pipeline as a high-level helper\n",
"from transformers import pipeline\n",
"\n",
"pipe = pipeline(\"text-classification\", model=\"Lech-Iyoko/bert-symptom-checker\")"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"result = pipe(\"I have severe headache and nausea\")"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[{'label': 'LABEL_52', 'score': 0.06071842461824417}]"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"result"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"ename": "OSError",
"evalue": "You are trying to access a gated repo.\nMake sure to have access to it at https://huggingface.co/piyush23111991/bert-base-uncased-symptom-to-disease-prediction.\n401 Client Error. (Request ID: Root=1-68d7bc1d-228e0c3505b6313a47e781e0;5b61a1d4-fd25-4c77-ae36-736db8560a2a)\n\nCannot access gated repo for url https://huggingface.co/piyush23111991/bert-base-uncased-symptom-to-disease-prediction/resolve/main/config.json.\nAccess to model piyush23111991/bert-base-uncased-symptom-to-disease-prediction is restricted. You must have access to it and be authenticated to access it. Please log in.",
"output_type": "error",
"traceback": [
"\u001b[31m---------------------------------------------------------------------------\u001b[39m",
"\u001b[31mHTTPError\u001b[39m Traceback (most recent call last)",
"\u001b[36mFile \u001b[39m\u001b[32m~/Documents/SmartHealth-LLM/venv/lib/python3.12/site-packages/huggingface_hub/utils/_http.py:407\u001b[39m, in \u001b[36mhf_raise_for_status\u001b[39m\u001b[34m(response, endpoint_name)\u001b[39m\n\u001b[32m 406\u001b[39m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[32m--> \u001b[39m\u001b[32m407\u001b[39m \u001b[43mresponse\u001b[49m\u001b[43m.\u001b[49m\u001b[43mraise_for_status\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n\u001b[32m 408\u001b[39m \u001b[38;5;28;01mexcept\u001b[39;00m HTTPError \u001b[38;5;28;01mas\u001b[39;00m e:\n",
"\u001b[36mFile \u001b[39m\u001b[32m~/Documents/SmartHealth-LLM/venv/lib/python3.12/site-packages/requests/models.py:1026\u001b[39m, in \u001b[36mResponse.raise_for_status\u001b[39m\u001b[34m(self)\u001b[39m\n\u001b[32m 1025\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m http_error_msg:\n\u001b[32m-> \u001b[39m\u001b[32m1026\u001b[39m \u001b[38;5;28;01mraise\u001b[39;00m HTTPError(http_error_msg, response=\u001b[38;5;28mself\u001b[39m)\n",
"\u001b[31mHTTPError\u001b[39m: 401 Client Error: Unauthorized for url: https://huggingface.co/piyush23111991/bert-base-uncased-symptom-to-disease-prediction/resolve/main/config.json",
"\nThe above exception was the direct cause of the following exception:\n",
"\u001b[31mGatedRepoError\u001b[39m Traceback (most recent call last)",
"\u001b[36mFile \u001b[39m\u001b[32m~/Documents/SmartHealth-LLM/venv/lib/python3.12/site-packages/transformers/utils/hub.py:478\u001b[39m, in \u001b[36mcached_files\u001b[39m\u001b[34m(path_or_repo_id, filenames, cache_dir, force_download, resume_download, proxies, token, revision, local_files_only, subfolder, repo_type, user_agent, _raise_exceptions_for_gated_repo, _raise_exceptions_for_missing_entries, _raise_exceptions_for_connection_errors, _commit_hash, **deprecated_kwargs)\u001b[39m\n\u001b[32m 476\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mlen\u001b[39m(full_filenames) == \u001b[32m1\u001b[39m:\n\u001b[32m 477\u001b[39m \u001b[38;5;66;03m# This is slightly better for only 1 file\u001b[39;00m\n\u001b[32m--> \u001b[39m\u001b[32m478\u001b[39m \u001b[43mhf_hub_download\u001b[49m\u001b[43m(\u001b[49m\n\u001b[32m 479\u001b[39m \u001b[43m \u001b[49m\u001b[43mpath_or_repo_id\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 480\u001b[39m \u001b[43m \u001b[49m\u001b[43mfilenames\u001b[49m\u001b[43m[\u001b[49m\u001b[32;43m0\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 481\u001b[39m \u001b[43m \u001b[49m\u001b[43msubfolder\u001b[49m\u001b[43m=\u001b[49m\u001b[38;5;28;43;01mNone\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[38;5;28;43;01mif\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[38;5;28;43mlen\u001b[39;49m\u001b[43m(\u001b[49m\u001b[43msubfolder\u001b[49m\u001b[43m)\u001b[49m\u001b[43m \u001b[49m\u001b[43m==\u001b[49m\u001b[43m \u001b[49m\u001b[32;43m0\u001b[39;49m\u001b[43m \u001b[49m\u001b[38;5;28;43;01melse\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[43msubfolder\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 482\u001b[39m \u001b[43m \u001b[49m\u001b[43mrepo_type\u001b[49m\u001b[43m=\u001b[49m\u001b[43mrepo_type\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 483\u001b[39m \u001b[43m \u001b[49m\u001b[43mrevision\u001b[49m\u001b[43m=\u001b[49m\u001b[43mrevision\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 484\u001b[39m \u001b[43m \u001b[49m\u001b[43mcache_dir\u001b[49m\u001b[43m=\u001b[49m\u001b[43mcache_dir\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 485\u001b[39m \u001b[43m \u001b[49m\u001b[43muser_agent\u001b[49m\u001b[43m=\u001b[49m\u001b[43muser_agent\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 486\u001b[39m \u001b[43m \u001b[49m\u001b[43mforce_download\u001b[49m\u001b[43m=\u001b[49m\u001b[43mforce_download\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 487\u001b[39m \u001b[43m \u001b[49m\u001b[43mproxies\u001b[49m\u001b[43m=\u001b[49m\u001b[43mproxies\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 488\u001b[39m \u001b[43m \u001b[49m\u001b[43mresume_download\u001b[49m\u001b[43m=\u001b[49m\u001b[43mresume_download\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 489\u001b[39m \u001b[43m \u001b[49m\u001b[43mtoken\u001b[49m\u001b[43m=\u001b[49m\u001b[43mtoken\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 490\u001b[39m \u001b[43m \u001b[49m\u001b[43mlocal_files_only\u001b[49m\u001b[43m=\u001b[49m\u001b[43mlocal_files_only\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 491\u001b[39m \u001b[43m \u001b[49m\u001b[43m)\u001b[49m\n\u001b[32m 492\u001b[39m \u001b[38;5;28;01melse\u001b[39;00m:\n",
"\u001b[36mFile \u001b[39m\u001b[32m~/Documents/SmartHealth-LLM/venv/lib/python3.12/site-packages/huggingface_hub/utils/_validators.py:114\u001b[39m, in \u001b[36mvalidate_hf_hub_args.._inner_fn\u001b[39m\u001b[34m(*args, **kwargs)\u001b[39m\n\u001b[32m 112\u001b[39m kwargs = smoothly_deprecate_use_auth_token(fn_name=fn.\u001b[34m__name__\u001b[39m, has_token=has_token, kwargs=kwargs)\n\u001b[32m--> \u001b[39m\u001b[32m114\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mfn\u001b[49m\u001b[43m(\u001b[49m\u001b[43m*\u001b[49m\u001b[43margs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43m*\u001b[49m\u001b[43m*\u001b[49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n",
"\u001b[36mFile \u001b[39m\u001b[32m~/Documents/SmartHealth-LLM/venv/lib/python3.12/site-packages/huggingface_hub/file_download.py:1010\u001b[39m, in \u001b[36mhf_hub_download\u001b[39m\u001b[34m(repo_id, filename, subfolder, repo_type, revision, library_name, library_version, cache_dir, local_dir, user_agent, force_download, proxies, etag_timeout, token, local_files_only, headers, endpoint, resume_download, force_filename, local_dir_use_symlinks)\u001b[39m\n\u001b[32m 1009\u001b[39m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[32m-> \u001b[39m\u001b[32m1010\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43m_hf_hub_download_to_cache_dir\u001b[49m\u001b[43m(\u001b[49m\n\u001b[32m 1011\u001b[39m \u001b[43m \u001b[49m\u001b[38;5;66;43;03m# Destination\u001b[39;49;00m\n\u001b[32m 1012\u001b[39m \u001b[43m \u001b[49m\u001b[43mcache_dir\u001b[49m\u001b[43m=\u001b[49m\u001b[43mcache_dir\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 1013\u001b[39m \u001b[43m \u001b[49m\u001b[38;5;66;43;03m# File info\u001b[39;49;00m\n\u001b[32m 1014\u001b[39m \u001b[43m \u001b[49m\u001b[43mrepo_id\u001b[49m\u001b[43m=\u001b[49m\u001b[43mrepo_id\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 1015\u001b[39m \u001b[43m \u001b[49m\u001b[43mfilename\u001b[49m\u001b[43m=\u001b[49m\u001b[43mfilename\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 1016\u001b[39m \u001b[43m \u001b[49m\u001b[43mrepo_type\u001b[49m\u001b[43m=\u001b[49m\u001b[43mrepo_type\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 1017\u001b[39m \u001b[43m \u001b[49m\u001b[43mrevision\u001b[49m\u001b[43m=\u001b[49m\u001b[43mrevision\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 1018\u001b[39m \u001b[43m \u001b[49m\u001b[38;5;66;43;03m# HTTP info\u001b[39;49;00m\n\u001b[32m 1019\u001b[39m \u001b[43m \u001b[49m\u001b[43mendpoint\u001b[49m\u001b[43m=\u001b[49m\u001b[43mendpoint\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 1020\u001b[39m \u001b[43m \u001b[49m\u001b[43metag_timeout\u001b[49m\u001b[43m=\u001b[49m\u001b[43metag_timeout\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 1021\u001b[39m \u001b[43m \u001b[49m\u001b[43mheaders\u001b[49m\u001b[43m=\u001b[49m\u001b[43mhf_headers\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 1022\u001b[39m \u001b[43m \u001b[49m\u001b[43mproxies\u001b[49m\u001b[43m=\u001b[49m\u001b[43mproxies\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 1023\u001b[39m \u001b[43m \u001b[49m\u001b[43mtoken\u001b[49m\u001b[43m=\u001b[49m\u001b[43mtoken\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 1024\u001b[39m \u001b[43m \u001b[49m\u001b[38;5;66;43;03m# Additional options\u001b[39;49;00m\n\u001b[32m 1025\u001b[39m \u001b[43m \u001b[49m\u001b[43mlocal_files_only\u001b[49m\u001b[43m=\u001b[49m\u001b[43mlocal_files_only\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 1026\u001b[39m \u001b[43m \u001b[49m\u001b[43mforce_download\u001b[49m\u001b[43m=\u001b[49m\u001b[43mforce_download\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 1027\u001b[39m \u001b[43m \u001b[49m\u001b[43m)\u001b[49m\n",
"\u001b[36mFile \u001b[39m\u001b[32m~/Documents/SmartHealth-LLM/venv/lib/python3.12/site-packages/huggingface_hub/file_download.py:1117\u001b[39m, in \u001b[36m_hf_hub_download_to_cache_dir\u001b[39m\u001b[34m(cache_dir, repo_id, filename, repo_type, revision, endpoint, etag_timeout, headers, proxies, token, local_files_only, force_download)\u001b[39m\n\u001b[32m 1116\u001b[39m \u001b[38;5;66;03m# Otherwise, raise appropriate error\u001b[39;00m\n\u001b[32m-> \u001b[39m\u001b[32m1117\u001b[39m \u001b[43m_raise_on_head_call_error\u001b[49m\u001b[43m(\u001b[49m\u001b[43mhead_call_error\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mforce_download\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mlocal_files_only\u001b[49m\u001b[43m)\u001b[49m\n\u001b[32m 1119\u001b[39m \u001b[38;5;66;03m# From now on, etag, commit_hash, url and size are not None.\u001b[39;00m\n",
"\u001b[36mFile \u001b[39m\u001b[32m~/Documents/SmartHealth-LLM/venv/lib/python3.12/site-packages/huggingface_hub/file_download.py:1658\u001b[39m, in \u001b[36m_raise_on_head_call_error\u001b[39m\u001b[34m(head_call_error, force_download, local_files_only)\u001b[39m\n\u001b[32m 1653\u001b[39m \u001b[38;5;28;01melif\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(head_call_error, (RepositoryNotFoundError, GatedRepoError)) \u001b[38;5;129;01mor\u001b[39;00m (\n\u001b[32m 1654\u001b[39m \u001b[38;5;28misinstance\u001b[39m(head_call_error, HfHubHTTPError) \u001b[38;5;129;01mand\u001b[39;00m head_call_error.response.status_code == \u001b[32m401\u001b[39m\n\u001b[32m 1655\u001b[39m ):\n\u001b[32m 1656\u001b[39m \u001b[38;5;66;03m# Repo not found or gated => let's raise the actual error\u001b[39;00m\n\u001b[32m 1657\u001b[39m \u001b[38;5;66;03m# Unauthorized => likely a token issue => let's raise the actual error\u001b[39;00m\n\u001b[32m-> \u001b[39m\u001b[32m1658\u001b[39m \u001b[38;5;28;01mraise\u001b[39;00m head_call_error\n\u001b[32m 1659\u001b[39m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[32m 1660\u001b[39m \u001b[38;5;66;03m# Otherwise: most likely a connection issue or Hub downtime => let's warn the user\u001b[39;00m\n",
"\u001b[36mFile \u001b[39m\u001b[32m~/Documents/SmartHealth-LLM/venv/lib/python3.12/site-packages/huggingface_hub/file_download.py:1546\u001b[39m, in \u001b[36m_get_metadata_or_catch_error\u001b[39m\u001b[34m(repo_id, filename, repo_type, revision, endpoint, proxies, etag_timeout, headers, token, local_files_only, relative_filename, storage_folder)\u001b[39m\n\u001b[32m 1545\u001b[39m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[32m-> \u001b[39m\u001b[32m1546\u001b[39m metadata = \u001b[43mget_hf_file_metadata\u001b[49m\u001b[43m(\u001b[49m\n\u001b[32m 1547\u001b[39m \u001b[43m \u001b[49m\u001b[43murl\u001b[49m\u001b[43m=\u001b[49m\u001b[43murl\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mproxies\u001b[49m\u001b[43m=\u001b[49m\u001b[43mproxies\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mtimeout\u001b[49m\u001b[43m=\u001b[49m\u001b[43metag_timeout\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mheaders\u001b[49m\u001b[43m=\u001b[49m\u001b[43mheaders\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mtoken\u001b[49m\u001b[43m=\u001b[49m\u001b[43mtoken\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mendpoint\u001b[49m\u001b[43m=\u001b[49m\u001b[43mendpoint\u001b[49m\n\u001b[32m 1548\u001b[39m \u001b[43m \u001b[49m\u001b[43m)\u001b[49m\n\u001b[32m 1549\u001b[39m \u001b[38;5;28;01mexcept\u001b[39;00m EntryNotFoundError \u001b[38;5;28;01mas\u001b[39;00m http_error:\n",
"\u001b[36mFile \u001b[39m\u001b[32m~/Documents/SmartHealth-LLM/venv/lib/python3.12/site-packages/huggingface_hub/utils/_validators.py:114\u001b[39m, in \u001b[36mvalidate_hf_hub_args.._inner_fn\u001b[39m\u001b[34m(*args, **kwargs)\u001b[39m\n\u001b[32m 112\u001b[39m kwargs = smoothly_deprecate_use_auth_token(fn_name=fn.\u001b[34m__name__\u001b[39m, has_token=has_token, kwargs=kwargs)\n\u001b[32m--> \u001b[39m\u001b[32m114\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mfn\u001b[49m\u001b[43m(\u001b[49m\u001b[43m*\u001b[49m\u001b[43margs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43m*\u001b[49m\u001b[43m*\u001b[49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n",
"\u001b[36mFile \u001b[39m\u001b[32m~/Documents/SmartHealth-LLM/venv/lib/python3.12/site-packages/huggingface_hub/file_download.py:1463\u001b[39m, in \u001b[36mget_hf_file_metadata\u001b[39m\u001b[34m(url, token, proxies, timeout, library_name, library_version, user_agent, headers, endpoint)\u001b[39m\n\u001b[32m 1462\u001b[39m \u001b[38;5;66;03m# Retrieve metadata\u001b[39;00m\n\u001b[32m-> \u001b[39m\u001b[32m1463\u001b[39m r = \u001b[43m_request_wrapper\u001b[49m\u001b[43m(\u001b[49m\n\u001b[32m 1464\u001b[39m \u001b[43m \u001b[49m\u001b[43mmethod\u001b[49m\u001b[43m=\u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mHEAD\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m,\u001b[49m\n\u001b[32m 1465\u001b[39m \u001b[43m \u001b[49m\u001b[43murl\u001b[49m\u001b[43m=\u001b[49m\u001b[43murl\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 1466\u001b[39m \u001b[43m \u001b[49m\u001b[43mheaders\u001b[49m\u001b[43m=\u001b[49m\u001b[43mhf_headers\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 1467\u001b[39m \u001b[43m \u001b[49m\u001b[43mallow_redirects\u001b[49m\u001b[43m=\u001b[49m\u001b[38;5;28;43;01mFalse\u001b[39;49;00m\u001b[43m,\u001b[49m\n\u001b[32m 1468\u001b[39m \u001b[43m \u001b[49m\u001b[43mfollow_relative_redirects\u001b[49m\u001b[43m=\u001b[49m\u001b[38;5;28;43;01mTrue\u001b[39;49;00m\u001b[43m,\u001b[49m\n\u001b[32m 1469\u001b[39m \u001b[43m \u001b[49m\u001b[43mproxies\u001b[49m\u001b[43m=\u001b[49m\u001b[43mproxies\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 1470\u001b[39m \u001b[43m \u001b[49m\u001b[43mtimeout\u001b[49m\u001b[43m=\u001b[49m\u001b[43mtimeout\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 1471\u001b[39m \u001b[43m\u001b[49m\u001b[43m)\u001b[49m\n\u001b[32m 1472\u001b[39m hf_raise_for_status(r)\n",
"\u001b[36mFile \u001b[39m\u001b[32m~/Documents/SmartHealth-LLM/venv/lib/python3.12/site-packages/huggingface_hub/file_download.py:286\u001b[39m, in \u001b[36m_request_wrapper\u001b[39m\u001b[34m(method, url, follow_relative_redirects, **params)\u001b[39m\n\u001b[32m 285\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m follow_relative_redirects:\n\u001b[32m--> \u001b[39m\u001b[32m286\u001b[39m response = \u001b[43m_request_wrapper\u001b[49m\u001b[43m(\u001b[49m\n\u001b[32m 287\u001b[39m \u001b[43m \u001b[49m\u001b[43mmethod\u001b[49m\u001b[43m=\u001b[49m\u001b[43mmethod\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 288\u001b[39m \u001b[43m \u001b[49m\u001b[43murl\u001b[49m\u001b[43m=\u001b[49m\u001b[43murl\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 289\u001b[39m \u001b[43m \u001b[49m\u001b[43mfollow_relative_redirects\u001b[49m\u001b[43m=\u001b[49m\u001b[38;5;28;43;01mFalse\u001b[39;49;00m\u001b[43m,\u001b[49m\n\u001b[32m 290\u001b[39m \u001b[43m \u001b[49m\u001b[43m*\u001b[49m\u001b[43m*\u001b[49m\u001b[43mparams\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 291\u001b[39m \u001b[43m \u001b[49m\u001b[43m)\u001b[49m\n\u001b[32m 293\u001b[39m \u001b[38;5;66;03m# If redirection, we redirect only relative paths.\u001b[39;00m\n\u001b[32m 294\u001b[39m \u001b[38;5;66;03m# This is useful in case of a renamed repository.\u001b[39;00m\n",
"\u001b[36mFile \u001b[39m\u001b[32m~/Documents/SmartHealth-LLM/venv/lib/python3.12/site-packages/huggingface_hub/file_download.py:310\u001b[39m, in \u001b[36m_request_wrapper\u001b[39m\u001b[34m(method, url, follow_relative_redirects, **params)\u001b[39m\n\u001b[32m 309\u001b[39m response = http_backoff(method=method, url=url, **params)\n\u001b[32m--> \u001b[39m\u001b[32m310\u001b[39m \u001b[43mhf_raise_for_status\u001b[49m\u001b[43m(\u001b[49m\u001b[43mresponse\u001b[49m\u001b[43m)\u001b[49m\n\u001b[32m 311\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m response\n",
"\u001b[36mFile \u001b[39m\u001b[32m~/Documents/SmartHealth-LLM/venv/lib/python3.12/site-packages/huggingface_hub/utils/_http.py:424\u001b[39m, in \u001b[36mhf_raise_for_status\u001b[39m\u001b[34m(response, endpoint_name)\u001b[39m\n\u001b[32m 421\u001b[39m message = (\n\u001b[32m 422\u001b[39m \u001b[33mf\u001b[39m\u001b[33m\"\u001b[39m\u001b[38;5;132;01m{\u001b[39;00mresponse.status_code\u001b[38;5;132;01m}\u001b[39;00m\u001b[33m Client Error.\u001b[39m\u001b[33m\"\u001b[39m + \u001b[33m\"\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[33m\"\u001b[39m + \u001b[33mf\u001b[39m\u001b[33m\"\u001b[39m\u001b[33mCannot access gated repo for url \u001b[39m\u001b[38;5;132;01m{\u001b[39;00mresponse.url\u001b[38;5;132;01m}\u001b[39;00m\u001b[33m.\u001b[39m\u001b[33m\"\u001b[39m\n\u001b[32m 423\u001b[39m )\n\u001b[32m--> \u001b[39m\u001b[32m424\u001b[39m \u001b[38;5;28;01mraise\u001b[39;00m _format(GatedRepoError, message, response) \u001b[38;5;28;01mfrom\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01me\u001b[39;00m\n\u001b[32m 426\u001b[39m \u001b[38;5;28;01melif\u001b[39;00m error_message == \u001b[33m\"\u001b[39m\u001b[33mAccess to this resource is disabled.\u001b[39m\u001b[33m\"\u001b[39m:\n",
"\u001b[31mGatedRepoError\u001b[39m: 401 Client Error. (Request ID: Root=1-68d7bc1d-228e0c3505b6313a47e781e0;5b61a1d4-fd25-4c77-ae36-736db8560a2a)\n\nCannot access gated repo for url https://huggingface.co/piyush23111991/bert-base-uncased-symptom-to-disease-prediction/resolve/main/config.json.\nAccess to model piyush23111991/bert-base-uncased-symptom-to-disease-prediction is restricted. You must have access to it and be authenticated to access it. Please log in.",
"\nThe above exception was the direct cause of the following exception:\n",
"\u001b[31mOSError\u001b[39m Traceback (most recent call last)",
"\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[5]\u001b[39m\u001b[32m, line 2\u001b[39m\n\u001b[32m 1\u001b[39m \u001b[38;5;28;01mfrom\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01mtransformers\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;28;01mimport\u001b[39;00m pipeline\n\u001b[32m----> \u001b[39m\u001b[32m2\u001b[39m classifier = \u001b[43mpipeline\u001b[49m\u001b[43m(\u001b[49m\u001b[33;43m'\u001b[39;49m\u001b[33;43mtext-classification\u001b[39;49m\u001b[33;43m'\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mmodel\u001b[49m\u001b[43m=\u001b[49m\u001b[43m \u001b[49m\u001b[33;43m'\u001b[39;49m\u001b[33;43mpiyush23111991/bert-base-uncased-symptom-to-disease-prediction\u001b[39;49m\u001b[33;43m'\u001b[39;49m\u001b[43m)\u001b[49m\n\u001b[32m 3\u001b[39m classifier([\u001b[33m'\u001b[39m\u001b[33mI am experiencing too many cramps in the last couple of days. I think something is not right. I believe there is a small bruise on my calves, but I am not sure about it.\u001b[39m\u001b[33m'\u001b[39m])\n",
"\u001b[36mFile \u001b[39m\u001b[32m~/Documents/SmartHealth-LLM/venv/lib/python3.12/site-packages/transformers/pipelines/__init__.py:922\u001b[39m, in \u001b[36mpipeline\u001b[39m\u001b[34m(task, model, config, tokenizer, feature_extractor, image_processor, processor, framework, revision, use_fast, token, device, device_map, dtype, trust_remote_code, model_kwargs, pipeline_class, **kwargs)\u001b[39m\n\u001b[32m 919\u001b[39m adapter_path = model\n\u001b[32m 920\u001b[39m model = adapter_config[\u001b[33m\"\u001b[39m\u001b[33mbase_model_name_or_path\u001b[39m\u001b[33m\"\u001b[39m]\n\u001b[32m--> \u001b[39m\u001b[32m922\u001b[39m config = \u001b[43mAutoConfig\u001b[49m\u001b[43m.\u001b[49m\u001b[43mfrom_pretrained\u001b[49m\u001b[43m(\u001b[49m\n\u001b[32m 923\u001b[39m \u001b[43m \u001b[49m\u001b[43mmodel\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43m_from_pipeline\u001b[49m\u001b[43m=\u001b[49m\u001b[43mtask\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mcode_revision\u001b[49m\u001b[43m=\u001b[49m\u001b[43mcode_revision\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43m*\u001b[49m\u001b[43m*\u001b[49m\u001b[43mhub_kwargs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43m*\u001b[49m\u001b[43m*\u001b[49m\u001b[43mmodel_kwargs\u001b[49m\n\u001b[32m 924\u001b[39m \u001b[43m \u001b[49m\u001b[43m)\u001b[49m\n\u001b[32m 925\u001b[39m hub_kwargs[\u001b[33m\"\u001b[39m\u001b[33m_commit_hash\u001b[39m\u001b[33m\"\u001b[39m] = config._commit_hash\n\u001b[32m 927\u001b[39m custom_tasks = {}\n",
"\u001b[36mFile \u001b[39m\u001b[32m~/Documents/SmartHealth-LLM/venv/lib/python3.12/site-packages/transformers/models/auto/configuration_auto.py:1288\u001b[39m, in \u001b[36mAutoConfig.from_pretrained\u001b[39m\u001b[34m(cls, pretrained_model_name_or_path, **kwargs)\u001b[39m\n\u001b[32m 1285\u001b[39m trust_remote_code = kwargs.pop(\u001b[33m\"\u001b[39m\u001b[33mtrust_remote_code\u001b[39m\u001b[33m\"\u001b[39m, \u001b[38;5;28;01mNone\u001b[39;00m)\n\u001b[32m 1286\u001b[39m code_revision = kwargs.pop(\u001b[33m\"\u001b[39m\u001b[33mcode_revision\u001b[39m\u001b[33m\"\u001b[39m, \u001b[38;5;28;01mNone\u001b[39;00m)\n\u001b[32m-> \u001b[39m\u001b[32m1288\u001b[39m config_dict, unused_kwargs = \u001b[43mPretrainedConfig\u001b[49m\u001b[43m.\u001b[49m\u001b[43mget_config_dict\u001b[49m\u001b[43m(\u001b[49m\u001b[43mpretrained_model_name_or_path\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43m*\u001b[49m\u001b[43m*\u001b[49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n\u001b[32m 1289\u001b[39m has_remote_code = \u001b[33m\"\u001b[39m\u001b[33mauto_map\u001b[39m\u001b[33m\"\u001b[39m \u001b[38;5;129;01min\u001b[39;00m config_dict \u001b[38;5;129;01mand\u001b[39;00m \u001b[33m\"\u001b[39m\u001b[33mAutoConfig\u001b[39m\u001b[33m\"\u001b[39m \u001b[38;5;129;01min\u001b[39;00m config_dict[\u001b[33m\"\u001b[39m\u001b[33mauto_map\u001b[39m\u001b[33m\"\u001b[39m]\n\u001b[32m 1290\u001b[39m has_local_code = \u001b[33m\"\u001b[39m\u001b[33mmodel_type\u001b[39m\u001b[33m\"\u001b[39m \u001b[38;5;129;01min\u001b[39;00m config_dict \u001b[38;5;129;01mand\u001b[39;00m config_dict[\u001b[33m\"\u001b[39m\u001b[33mmodel_type\u001b[39m\u001b[33m\"\u001b[39m] \u001b[38;5;129;01min\u001b[39;00m CONFIG_MAPPING\n",
"\u001b[36mFile \u001b[39m\u001b[32m~/Documents/SmartHealth-LLM/venv/lib/python3.12/site-packages/transformers/configuration_utils.py:662\u001b[39m, in \u001b[36mPretrainedConfig.get_config_dict\u001b[39m\u001b[34m(cls, pretrained_model_name_or_path, **kwargs)\u001b[39m\n\u001b[32m 660\u001b[39m original_kwargs = copy.deepcopy(kwargs)\n\u001b[32m 661\u001b[39m \u001b[38;5;66;03m# Get config dict associated with the base config file\u001b[39;00m\n\u001b[32m--> \u001b[39m\u001b[32m662\u001b[39m config_dict, kwargs = \u001b[38;5;28;43mcls\u001b[39;49m\u001b[43m.\u001b[49m\u001b[43m_get_config_dict\u001b[49m\u001b[43m(\u001b[49m\u001b[43mpretrained_model_name_or_path\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43m*\u001b[49m\u001b[43m*\u001b[49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n\u001b[32m 663\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m config_dict \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m:\n\u001b[32m 664\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m {}, kwargs\n",
"\u001b[36mFile \u001b[39m\u001b[32m~/Documents/SmartHealth-LLM/venv/lib/python3.12/site-packages/transformers/configuration_utils.py:721\u001b[39m, in \u001b[36mPretrainedConfig._get_config_dict\u001b[39m\u001b[34m(cls, pretrained_model_name_or_path, **kwargs)\u001b[39m\n\u001b[32m 717\u001b[39m configuration_file = kwargs.pop(\u001b[33m\"\u001b[39m\u001b[33m_configuration_file\u001b[39m\u001b[33m\"\u001b[39m, CONFIG_NAME) \u001b[38;5;28;01mif\u001b[39;00m gguf_file \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m \u001b[38;5;28;01melse\u001b[39;00m gguf_file\n\u001b[32m 719\u001b[39m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[32m 720\u001b[39m \u001b[38;5;66;03m# Load from local folder or from cache or download from model Hub and cache\u001b[39;00m\n\u001b[32m--> \u001b[39m\u001b[32m721\u001b[39m resolved_config_file = \u001b[43mcached_file\u001b[49m\u001b[43m(\u001b[49m\n\u001b[32m 722\u001b[39m \u001b[43m \u001b[49m\u001b[43mpretrained_model_name_or_path\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 723\u001b[39m \u001b[43m \u001b[49m\u001b[43mconfiguration_file\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 724\u001b[39m \u001b[43m \u001b[49m\u001b[43mcache_dir\u001b[49m\u001b[43m=\u001b[49m\u001b[43mcache_dir\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 725\u001b[39m \u001b[43m \u001b[49m\u001b[43mforce_download\u001b[49m\u001b[43m=\u001b[49m\u001b[43mforce_download\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 726\u001b[39m \u001b[43m \u001b[49m\u001b[43mproxies\u001b[49m\u001b[43m=\u001b[49m\u001b[43mproxies\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 727\u001b[39m \u001b[43m \u001b[49m\u001b[43mresume_download\u001b[49m\u001b[43m=\u001b[49m\u001b[43mresume_download\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 728\u001b[39m \u001b[43m \u001b[49m\u001b[43mlocal_files_only\u001b[49m\u001b[43m=\u001b[49m\u001b[43mlocal_files_only\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 729\u001b[39m \u001b[43m \u001b[49m\u001b[43mtoken\u001b[49m\u001b[43m=\u001b[49m\u001b[43mtoken\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 730\u001b[39m \u001b[43m \u001b[49m\u001b[43muser_agent\u001b[49m\u001b[43m=\u001b[49m\u001b[43muser_agent\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 731\u001b[39m \u001b[43m \u001b[49m\u001b[43mrevision\u001b[49m\u001b[43m=\u001b[49m\u001b[43mrevision\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 732\u001b[39m \u001b[43m \u001b[49m\u001b[43msubfolder\u001b[49m\u001b[43m=\u001b[49m\u001b[43msubfolder\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 733\u001b[39m \u001b[43m \u001b[49m\u001b[43m_commit_hash\u001b[49m\u001b[43m=\u001b[49m\u001b[43mcommit_hash\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 734\u001b[39m \u001b[43m \u001b[49m\u001b[43m)\u001b[49m\n\u001b[32m 735\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m resolved_config_file \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m:\n\u001b[32m 736\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m, kwargs\n",
"\u001b[36mFile \u001b[39m\u001b[32m~/Documents/SmartHealth-LLM/venv/lib/python3.12/site-packages/transformers/utils/hub.py:321\u001b[39m, in \u001b[36mcached_file\u001b[39m\u001b[34m(path_or_repo_id, filename, **kwargs)\u001b[39m\n\u001b[32m 263\u001b[39m \u001b[38;5;28;01mdef\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34mcached_file\u001b[39m(\n\u001b[32m 264\u001b[39m path_or_repo_id: Union[\u001b[38;5;28mstr\u001b[39m, os.PathLike],\n\u001b[32m 265\u001b[39m filename: \u001b[38;5;28mstr\u001b[39m,\n\u001b[32m 266\u001b[39m **kwargs,\n\u001b[32m 267\u001b[39m ) -> Optional[\u001b[38;5;28mstr\u001b[39m]:\n\u001b[32m 268\u001b[39m \u001b[38;5;250m \u001b[39m\u001b[33;03m\"\"\"\u001b[39;00m\n\u001b[32m 269\u001b[39m \u001b[33;03m Tries to locate a file in a local folder and repo, downloads and cache it if necessary.\u001b[39;00m\n\u001b[32m 270\u001b[39m \n\u001b[32m (...)\u001b[39m\u001b[32m 319\u001b[39m \u001b[33;03m ```\u001b[39;00m\n\u001b[32m 320\u001b[39m \u001b[33;03m \"\"\"\u001b[39;00m\n\u001b[32m--> \u001b[39m\u001b[32m321\u001b[39m file = \u001b[43mcached_files\u001b[49m\u001b[43m(\u001b[49m\u001b[43mpath_or_repo_id\u001b[49m\u001b[43m=\u001b[49m\u001b[43mpath_or_repo_id\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mfilenames\u001b[49m\u001b[43m=\u001b[49m\u001b[43m[\u001b[49m\u001b[43mfilename\u001b[49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43m*\u001b[49m\u001b[43m*\u001b[49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n\u001b[32m 322\u001b[39m file = file[\u001b[32m0\u001b[39m] \u001b[38;5;28;01mif\u001b[39;00m file \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m \u001b[38;5;28;01melse\u001b[39;00m file\n\u001b[32m 323\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m file\n",
"\u001b[36mFile \u001b[39m\u001b[32m~/Documents/SmartHealth-LLM/venv/lib/python3.12/site-packages/transformers/utils/hub.py:542\u001b[39m, in \u001b[36mcached_files\u001b[39m\u001b[34m(path_or_repo_id, filenames, cache_dir, force_download, resume_download, proxies, token, revision, local_files_only, subfolder, repo_type, user_agent, _raise_exceptions_for_gated_repo, _raise_exceptions_for_missing_entries, _raise_exceptions_for_connection_errors, _commit_hash, **deprecated_kwargs)\u001b[39m\n\u001b[32m 540\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m _raise_exceptions_for_gated_repo:\n\u001b[32m 541\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m\n\u001b[32m--> \u001b[39m\u001b[32m542\u001b[39m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mOSError\u001b[39;00m(\n\u001b[32m 543\u001b[39m \u001b[33m\"\u001b[39m\u001b[33mYou are trying to access a gated repo.\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[33mMake sure to have access to it at \u001b[39m\u001b[33m\"\u001b[39m\n\u001b[32m 544\u001b[39m \u001b[33mf\u001b[39m\u001b[33m\"\u001b[39m\u001b[33mhttps://huggingface.co/\u001b[39m\u001b[38;5;132;01m{\u001b[39;00mpath_or_repo_id\u001b[38;5;132;01m}\u001b[39;00m\u001b[33m.\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;132;01m{\u001b[39;00m\u001b[38;5;28mstr\u001b[39m(e)\u001b[38;5;132;01m}\u001b[39;00m\u001b[33m\"\u001b[39m\n\u001b[32m 545\u001b[39m ) \u001b[38;5;28;01mfrom\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01me\u001b[39;00m\n\u001b[32m 546\u001b[39m \u001b[38;5;28;01melif\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(e, LocalEntryNotFoundError):\n\u001b[32m 547\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m _raise_exceptions_for_connection_errors:\n",
"\u001b[31mOSError\u001b[39m: You are trying to access a gated repo.\nMake sure to have access to it at https://huggingface.co/piyush23111991/bert-base-uncased-symptom-to-disease-prediction.\n401 Client Error. (Request ID: Root=1-68d7bc1d-228e0c3505b6313a47e781e0;5b61a1d4-fd25-4c77-ae36-736db8560a2a)\n\nCannot access gated repo for url https://huggingface.co/piyush23111991/bert-base-uncased-symptom-to-disease-prediction/resolve/main/config.json.\nAccess to model piyush23111991/bert-base-uncased-symptom-to-disease-prediction is restricted. You must have access to it and be authenticated to access it. Please log in."
]
}
],
"source": [
"from transformers import pipeline\n",
"classifier = pipeline('text-classification', model= 'piyush23111991/bert-base-uncased-symptom-to-disease-prediction')\n",
"classifier(['I am experiencing too many cramps in the last couple of days. I think something is not right. I believe there is a small bruise on my calves, but I am not sure about it.'])"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"`torch_dtype` is deprecated! Use `dtype` instead!\n"
]
},
{
"ename": "OSError",
"evalue": "biololab/tinyllama-symptom-extractor_4bit does not appear to have a file named pytorch_model.bin, model.safetensors, tf_model.h5, model.ckpt or flax_model.msgpack.",
"output_type": "error",
"traceback": [
"\u001b[31m---------------------------------------------------------------------------\u001b[39m",
"\u001b[31mOSError\u001b[39m Traceback (most recent call last)",
"\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[6]\u001b[39m\u001b[32m, line 3\u001b[39m\n\u001b[32m 1\u001b[39m \u001b[38;5;66;03m# Load model directly\u001b[39;00m\n\u001b[32m 2\u001b[39m \u001b[38;5;28;01mfrom\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01mtransformers\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;28;01mimport\u001b[39;00m AutoModel\n\u001b[32m----> \u001b[39m\u001b[32m3\u001b[39m model = \u001b[43mAutoModel\u001b[49m\u001b[43m.\u001b[49m\u001b[43mfrom_pretrained\u001b[49m\u001b[43m(\u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mbiololab/tinyllama-symptom-extractor_4bit\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mtorch_dtype\u001b[49m\u001b[43m=\u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mauto\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m)\u001b[49m\n",
"\u001b[36mFile \u001b[39m\u001b[32m~/Documents/SmartHealth-LLM/venv/lib/python3.12/site-packages/transformers/models/auto/auto_factory.py:604\u001b[39m, in \u001b[36m_BaseAutoModelClass.from_pretrained\u001b[39m\u001b[34m(cls, pretrained_model_name_or_path, *model_args, **kwargs)\u001b[39m\n\u001b[32m 602\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m model_class.config_class == config.sub_configs.get(\u001b[33m\"\u001b[39m\u001b[33mtext_config\u001b[39m\u001b[33m\"\u001b[39m, \u001b[38;5;28;01mNone\u001b[39;00m):\n\u001b[32m 603\u001b[39m config = config.get_text_config()\n\u001b[32m--> \u001b[39m\u001b[32m604\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mmodel_class\u001b[49m\u001b[43m.\u001b[49m\u001b[43mfrom_pretrained\u001b[49m\u001b[43m(\u001b[49m\n\u001b[32m 605\u001b[39m \u001b[43m \u001b[49m\u001b[43mpretrained_model_name_or_path\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43m*\u001b[49m\u001b[43mmodel_args\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mconfig\u001b[49m\u001b[43m=\u001b[49m\u001b[43mconfig\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43m*\u001b[49m\u001b[43m*\u001b[49m\u001b[43mhub_kwargs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43m*\u001b[49m\u001b[43m*\u001b[49m\u001b[43mkwargs\u001b[49m\n\u001b[32m 606\u001b[39m \u001b[43m \u001b[49m\u001b[43m)\u001b[49m\n\u001b[32m 607\u001b[39m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mValueError\u001b[39;00m(\n\u001b[32m 608\u001b[39m \u001b[33mf\u001b[39m\u001b[33m\"\u001b[39m\u001b[33mUnrecognized configuration class \u001b[39m\u001b[38;5;132;01m{\u001b[39;00mconfig.\u001b[34m__class__\u001b[39m\u001b[38;5;132;01m}\u001b[39;00m\u001b[33m for this kind of AutoModel: \u001b[39m\u001b[38;5;132;01m{\u001b[39;00m\u001b[38;5;28mcls\u001b[39m.\u001b[34m__name__\u001b[39m\u001b[38;5;132;01m}\u001b[39;00m\u001b[33m.\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[33m\"\u001b[39m\n\u001b[32m 609\u001b[39m \u001b[33mf\u001b[39m\u001b[33m\"\u001b[39m\u001b[33mModel type should be one of \u001b[39m\u001b[38;5;132;01m{\u001b[39;00m\u001b[33m'\u001b[39m\u001b[33m, \u001b[39m\u001b[33m'\u001b[39m.join(c.\u001b[34m__name__\u001b[39m\u001b[38;5;250m \u001b[39m\u001b[38;5;28;01mfor\u001b[39;00m\u001b[38;5;250m \u001b[39mc\u001b[38;5;250m \u001b[39m\u001b[38;5;129;01min\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;28mcls\u001b[39m._model_mapping)\u001b[38;5;132;01m}\u001b[39;00m\u001b[33m.\u001b[39m\u001b[33m\"\u001b[39m\n\u001b[32m 610\u001b[39m )\n",
"\u001b[36mFile \u001b[39m\u001b[32m~/Documents/SmartHealth-LLM/venv/lib/python3.12/site-packages/transformers/modeling_utils.py:288\u001b[39m, in \u001b[36mrestore_default_dtype.._wrapper\u001b[39m\u001b[34m(*args, **kwargs)\u001b[39m\n\u001b[32m 286\u001b[39m old_dtype = torch.get_default_dtype()\n\u001b[32m 287\u001b[39m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[32m--> \u001b[39m\u001b[32m288\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mfunc\u001b[49m\u001b[43m(\u001b[49m\u001b[43m*\u001b[49m\u001b[43margs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43m*\u001b[49m\u001b[43m*\u001b[49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n\u001b[32m 289\u001b[39m \u001b[38;5;28;01mfinally\u001b[39;00m:\n\u001b[32m 290\u001b[39m torch.set_default_dtype(old_dtype)\n",
"\u001b[36mFile \u001b[39m\u001b[32m~/Documents/SmartHealth-LLM/venv/lib/python3.12/site-packages/transformers/modeling_utils.py:5030\u001b[39m, in \u001b[36mPreTrainedModel.from_pretrained\u001b[39m\u001b[34m(cls, pretrained_model_name_or_path, config, cache_dir, ignore_mismatched_sizes, force_download, local_files_only, token, revision, use_safetensors, weights_only, *model_args, **kwargs)\u001b[39m\n\u001b[32m 5020\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m (\n\u001b[32m 5021\u001b[39m gguf_file\n\u001b[32m 5022\u001b[39m \u001b[38;5;129;01mand\u001b[39;00m device_map \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m\n\u001b[32m 5023\u001b[39m \u001b[38;5;129;01mand\u001b[39;00m ((\u001b[38;5;28misinstance\u001b[39m(device_map, \u001b[38;5;28mdict\u001b[39m) \u001b[38;5;129;01mand\u001b[39;00m \u001b[33m\"\u001b[39m\u001b[33mdisk\u001b[39m\u001b[33m\"\u001b[39m \u001b[38;5;129;01min\u001b[39;00m device_map.values()) \u001b[38;5;129;01mor\u001b[39;00m \u001b[33m\"\u001b[39m\u001b[33mdisk\u001b[39m\u001b[33m\"\u001b[39m \u001b[38;5;129;01min\u001b[39;00m device_map)\n\u001b[32m 5024\u001b[39m ):\n\u001b[32m 5025\u001b[39m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mRuntimeError\u001b[39;00m(\n\u001b[32m 5026\u001b[39m \u001b[33m\"\u001b[39m\u001b[33mOne or more modules is configured to be mapped to disk. Disk offload is not supported for models \u001b[39m\u001b[33m\"\u001b[39m\n\u001b[32m 5027\u001b[39m \u001b[33m\"\u001b[39m\u001b[33mloaded from GGUF files.\u001b[39m\u001b[33m\"\u001b[39m\n\u001b[32m 5028\u001b[39m )\n\u001b[32m-> \u001b[39m\u001b[32m5030\u001b[39m checkpoint_files, sharded_metadata = \u001b[43m_get_resolved_checkpoint_files\u001b[49m\u001b[43m(\u001b[49m\n\u001b[32m 5031\u001b[39m \u001b[43m \u001b[49m\u001b[43mpretrained_model_name_or_path\u001b[49m\u001b[43m=\u001b[49m\u001b[43mpretrained_model_name_or_path\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 5032\u001b[39m \u001b[43m \u001b[49m\u001b[43msubfolder\u001b[49m\u001b[43m=\u001b[49m\u001b[43msubfolder\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 5033\u001b[39m \u001b[43m \u001b[49m\u001b[43mvariant\u001b[49m\u001b[43m=\u001b[49m\u001b[43mvariant\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 5034\u001b[39m \u001b[43m \u001b[49m\u001b[43mgguf_file\u001b[49m\u001b[43m=\u001b[49m\u001b[43mgguf_file\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 5035\u001b[39m \u001b[43m \u001b[49m\u001b[43mfrom_tf\u001b[49m\u001b[43m=\u001b[49m\u001b[43mfrom_tf\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 5036\u001b[39m \u001b[43m \u001b[49m\u001b[43mfrom_flax\u001b[49m\u001b[43m=\u001b[49m\u001b[43mfrom_flax\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 5037\u001b[39m \u001b[43m \u001b[49m\u001b[43muse_safetensors\u001b[49m\u001b[43m=\u001b[49m\u001b[43muse_safetensors\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 5038\u001b[39m \u001b[43m \u001b[49m\u001b[43mcache_dir\u001b[49m\u001b[43m=\u001b[49m\u001b[43mcache_dir\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 5039\u001b[39m \u001b[43m \u001b[49m\u001b[43mforce_download\u001b[49m\u001b[43m=\u001b[49m\u001b[43mforce_download\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 5040\u001b[39m \u001b[43m \u001b[49m\u001b[43mproxies\u001b[49m\u001b[43m=\u001b[49m\u001b[43mproxies\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 5041\u001b[39m \u001b[43m \u001b[49m\u001b[43mlocal_files_only\u001b[49m\u001b[43m=\u001b[49m\u001b[43mlocal_files_only\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 5042\u001b[39m \u001b[43m \u001b[49m\u001b[43mtoken\u001b[49m\u001b[43m=\u001b[49m\u001b[43mtoken\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 5043\u001b[39m \u001b[43m \u001b[49m\u001b[43muser_agent\u001b[49m\u001b[43m=\u001b[49m\u001b[43muser_agent\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 5044\u001b[39m \u001b[43m \u001b[49m\u001b[43mrevision\u001b[49m\u001b[43m=\u001b[49m\u001b[43mrevision\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 5045\u001b[39m \u001b[43m \u001b[49m\u001b[43mcommit_hash\u001b[49m\u001b[43m=\u001b[49m\u001b[43mcommit_hash\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 5046\u001b[39m \u001b[43m \u001b[49m\u001b[43mis_remote_code\u001b[49m\u001b[43m=\u001b[49m\u001b[38;5;28;43mcls\u001b[39;49m\u001b[43m.\u001b[49m\u001b[43m_auto_class\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;129;43;01mis\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[38;5;129;43;01mnot\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[38;5;28;43;01mNone\u001b[39;49;00m\u001b[43m,\u001b[49m\n\u001b[32m 5047\u001b[39m \u001b[43m \u001b[49m\u001b[43mtransformers_explicit_filename\u001b[49m\u001b[43m=\u001b[49m\u001b[43mtransformers_explicit_filename\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 5048\u001b[39m \u001b[43m\u001b[49m\u001b[43m)\u001b[49m\n\u001b[32m 5050\u001b[39m is_sharded = sharded_metadata \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m\n\u001b[32m 5051\u001b[39m is_quantized = hf_quantizer \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m\n",
"\u001b[36mFile \u001b[39m\u001b[32m~/Documents/SmartHealth-LLM/venv/lib/python3.12/site-packages/transformers/modeling_utils.py:1256\u001b[39m, in \u001b[36m_get_resolved_checkpoint_files\u001b[39m\u001b[34m(pretrained_model_name_or_path, subfolder, variant, gguf_file, from_tf, from_flax, use_safetensors, cache_dir, force_download, proxies, local_files_only, token, user_agent, revision, commit_hash, is_remote_code, transformers_explicit_filename)\u001b[39m\n\u001b[32m 1250\u001b[39m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mOSError\u001b[39;00m(\n\u001b[32m 1251\u001b[39m \u001b[33mf\u001b[39m\u001b[33m\"\u001b[39m\u001b[38;5;132;01m{\u001b[39;00mpretrained_model_name_or_path\u001b[38;5;132;01m}\u001b[39;00m\u001b[33m does not appear to have a file named\u001b[39m\u001b[33m\"\u001b[39m\n\u001b[32m 1252\u001b[39m \u001b[33mf\u001b[39m\u001b[33m\"\u001b[39m\u001b[33m \u001b[39m\u001b[38;5;132;01m{\u001b[39;00m_add_variant(WEIGHTS_NAME,\u001b[38;5;250m \u001b[39mvariant)\u001b[38;5;132;01m}\u001b[39;00m\u001b[33m but there is a file without the variant\u001b[39m\u001b[33m\"\u001b[39m\n\u001b[32m 1253\u001b[39m \u001b[33mf\u001b[39m\u001b[33m\"\u001b[39m\u001b[33m \u001b[39m\u001b[38;5;132;01m{\u001b[39;00mvariant\u001b[38;5;132;01m}\u001b[39;00m\u001b[33m. Use `variant=None` to load this model from those weights.\u001b[39m\u001b[33m\"\u001b[39m\n\u001b[32m 1254\u001b[39m )\n\u001b[32m 1255\u001b[39m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[32m-> \u001b[39m\u001b[32m1256\u001b[39m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mOSError\u001b[39;00m(\n\u001b[32m 1257\u001b[39m \u001b[33mf\u001b[39m\u001b[33m\"\u001b[39m\u001b[38;5;132;01m{\u001b[39;00mpretrained_model_name_or_path\u001b[38;5;132;01m}\u001b[39;00m\u001b[33m does not appear to have a file named\u001b[39m\u001b[33m\"\u001b[39m\n\u001b[32m 1258\u001b[39m \u001b[33mf\u001b[39m\u001b[33m\"\u001b[39m\u001b[33m \u001b[39m\u001b[38;5;132;01m{\u001b[39;00m_add_variant(WEIGHTS_NAME,\u001b[38;5;250m \u001b[39mvariant)\u001b[38;5;132;01m}\u001b[39;00m\u001b[33m, \u001b[39m\u001b[38;5;132;01m{\u001b[39;00m_add_variant(SAFE_WEIGHTS_NAME,\u001b[38;5;250m \u001b[39mvariant)\u001b[38;5;132;01m}\u001b[39;00m\u001b[33m,\u001b[39m\u001b[33m\"\u001b[39m\n\u001b[32m 1259\u001b[39m \u001b[33mf\u001b[39m\u001b[33m\"\u001b[39m\u001b[33m \u001b[39m\u001b[38;5;132;01m{\u001b[39;00mTF2_WEIGHTS_NAME\u001b[38;5;132;01m}\u001b[39;00m\u001b[33m, \u001b[39m\u001b[38;5;132;01m{\u001b[39;00mTF_WEIGHTS_NAME\u001b[38;5;132;01m}\u001b[39;00m\u001b[33m or \u001b[39m\u001b[38;5;132;01m{\u001b[39;00mFLAX_WEIGHTS_NAME\u001b[38;5;132;01m}\u001b[39;00m\u001b[33m.\u001b[39m\u001b[33m\"\u001b[39m\n\u001b[32m 1260\u001b[39m )\n\u001b[32m 1262\u001b[39m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mOSError\u001b[39;00m:\n\u001b[32m 1263\u001b[39m \u001b[38;5;66;03m# Raise any environment error raise by `cached_file`. It will have a helpful error message adapted\u001b[39;00m\n\u001b[32m 1264\u001b[39m \u001b[38;5;66;03m# to the original exception.\u001b[39;00m\n\u001b[32m 1265\u001b[39m \u001b[38;5;28;01mraise\u001b[39;00m\n",
"\u001b[31mOSError\u001b[39m: biololab/tinyllama-symptom-extractor_4bit does not appear to have a file named pytorch_model.bin, model.safetensors, tf_model.h5, model.ckpt or flax_model.msgpack."
]
}
],
"source": [
"# Load model directly\n",
"from transformers import AutoModel\n",
"model = AutoModel.from_pretrained(\"biololab/tinyllama-symptom-extractor_4bit\", torch_dtype=\"auto\")"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"huggingface/tokenizers: The current process just got forked, after parallelism has already been used. Disabling parallelism to avoid deadlocks...\n",
"To disable this warning, you can either:\n",
"\t- Avoid using `tokenizers` before the fork if possible\n",
"\t- Explicitly set the environment variable TOKENIZERS_PARALLELISM=(true | false)\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Requirement already satisfied: torch in /home/mcqueen/Documents/SmartHealth-LLM/venv/lib/python3.12/site-packages (2.8.0+cpu)\n",
"Requirement already satisfied: transformers in /home/mcqueen/Documents/SmartHealth-LLM/venv/lib/python3.12/site-packages (4.56.2)\n",
"Requirement already satisfied: filelock in /home/mcqueen/Documents/SmartHealth-LLM/venv/lib/python3.12/site-packages (from torch) (3.19.1)\n",
"Requirement already satisfied: typing-extensions>=4.10.0 in /home/mcqueen/Documents/SmartHealth-LLM/venv/lib/python3.12/site-packages (from torch) (4.15.0)\n",
"Requirement already satisfied: setuptools in /home/mcqueen/Documents/SmartHealth-LLM/venv/lib/python3.12/site-packages (from torch) (70.2.0)\n",
"Requirement already satisfied: sympy>=1.13.3 in /home/mcqueen/Documents/SmartHealth-LLM/venv/lib/python3.12/site-packages (from torch) (1.13.3)\n",
"Requirement already satisfied: networkx in /home/mcqueen/Documents/SmartHealth-LLM/venv/lib/python3.12/site-packages (from torch) (3.3)\n",
"Requirement already satisfied: jinja2 in /home/mcqueen/Documents/SmartHealth-LLM/venv/lib/python3.12/site-packages (from torch) (3.1.6)\n",
"Requirement already satisfied: fsspec in /home/mcqueen/Documents/SmartHealth-LLM/venv/lib/python3.12/site-packages (from torch) (2025.9.0)\n",
"Requirement already satisfied: huggingface-hub<1.0,>=0.34.0 in /home/mcqueen/Documents/SmartHealth-LLM/venv/lib/python3.12/site-packages (from transformers) (0.35.1)\n",
"Requirement already satisfied: numpy>=1.17 in /home/mcqueen/Documents/SmartHealth-LLM/venv/lib/python3.12/site-packages (from transformers) (2.3.3)\n",
"Requirement already satisfied: packaging>=20.0 in /home/mcqueen/Documents/SmartHealth-LLM/venv/lib/python3.12/site-packages (from transformers) (25.0)\n",
"Requirement already satisfied: pyyaml>=5.1 in /home/mcqueen/Documents/SmartHealth-LLM/venv/lib/python3.12/site-packages (from transformers) (6.0.3)\n",
"Requirement already satisfied: regex!=2019.12.17 in /home/mcqueen/Documents/SmartHealth-LLM/venv/lib/python3.12/site-packages (from transformers) (2025.9.18)\n",
"Requirement already satisfied: requests in /home/mcqueen/Documents/SmartHealth-LLM/venv/lib/python3.12/site-packages (from transformers) (2.32.5)\n",
"Requirement already satisfied: tokenizers<=0.23.0,>=0.22.0 in /home/mcqueen/Documents/SmartHealth-LLM/venv/lib/python3.12/site-packages (from transformers) (0.22.1)\n",
"Requirement already satisfied: safetensors>=0.4.3 in /home/mcqueen/Documents/SmartHealth-LLM/venv/lib/python3.12/site-packages (from transformers) (0.6.2)\n",
"Requirement already satisfied: tqdm>=4.27 in /home/mcqueen/Documents/SmartHealth-LLM/venv/lib/python3.12/site-packages (from transformers) (4.67.1)\n",
"Requirement already satisfied: hf-xet<2.0.0,>=1.1.3 in /home/mcqueen/Documents/SmartHealth-LLM/venv/lib/python3.12/site-packages (from huggingface-hub<1.0,>=0.34.0->transformers) (1.1.10)\n",
"Requirement already satisfied: mpmath<1.4,>=1.1.0 in /home/mcqueen/Documents/SmartHealth-LLM/venv/lib/python3.12/site-packages (from sympy>=1.13.3->torch) (1.3.0)\n",
"Requirement already satisfied: MarkupSafe>=2.0 in /home/mcqueen/Documents/SmartHealth-LLM/venv/lib/python3.12/site-packages (from jinja2->torch) (3.0.2)\n",
"Requirement already satisfied: charset_normalizer<4,>=2 in /home/mcqueen/Documents/SmartHealth-LLM/venv/lib/python3.12/site-packages (from requests->transformers) (3.4.3)\n",
"Requirement already satisfied: idna<4,>=2.5 in /home/mcqueen/Documents/SmartHealth-LLM/venv/lib/python3.12/site-packages (from requests->transformers) (3.10)\n",
"Requirement already satisfied: urllib3<3,>=1.21.1 in /home/mcqueen/Documents/SmartHealth-LLM/venv/lib/python3.12/site-packages (from requests->transformers) (2.5.0)\n",
"Requirement already satisfied: certifi>=2017.4.17 in /home/mcqueen/Documents/SmartHealth-LLM/venv/lib/python3.12/site-packages (from requests->transformers) (2025.8.3)\n",
"Note: you may need to restart the kernel to use updated packages.\n"
]
}
],
"source": [
"pip install torch transformers\n"
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Device set to use cpu\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"[{'entity_group': 'Diagnostic_procedure', 'score': np.float32(0.4340941), 'word': 'barack', 'start': 0, 'end': 6}]\n"
]
}
],
"source": [
"from transformers import AutoTokenizer, AutoModelForTokenClassification, pipeline\n",
"\n",
"model_path = \"/home/mcqueen/Documents/SmartHealth-LLM/biomedicalnerall\" # <-- full path or correct relative path\n",
"\n",
"tokenizer = AutoTokenizer.from_pretrained(model_path, local_files_only=True)\n",
"model = AutoModelForTokenClassification.from_pretrained(model_path, local_files_only=True)\n",
"\n",
"ner = pipeline(\n",
" \"ner\",\n",
" model=model,\n",
" tokenizer=tokenizer,\n",
" aggregation_strategy=\"simple\"\n",
")\n",
"\n",
"print(ner(\"Barack Obama was born in Hawaii.\"))\n"
]
},
{
"cell_type": "code",
"execution_count": 23,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"cough -> Sign_symptom (score: 0.721)\n"
]
}
],
"source": [
"text = \"\"\"cough\"\"\"\n",
"results = ner(text)\n",
"\n",
"# Print each detected entity and its label\n",
"for ent in results:\n",
" print(f\"{ent['word']:<30} -> {ent['entity_group']} (score: {ent['score']:.3f})\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{0: 'O', 1: 'B-Activity', 2: 'B-Administration', 3: 'B-Age', 4: 'B-Area', 5: 'B-Biological_attribute', 6: 'B-Biological_structure', 7: 'B-Clinical_event', 8: 'B-Color', 9: 'B-Coreference', 10: 'B-Date', 11: 'B-Detailed_description', 12: 'B-Diagnostic_procedure', 13: 'B-Disease_disorder', 14: 'B-Distance', 15: 'B-Dosage', 16: 'B-Duration', 17: 'B-Family_history', 18: 'B-Frequency', 19: 'B-Height', 20: 'B-History', 21: 'B-Lab_value', 22: 'B-Mass', 23: 'B-Medication', 24: 'B-Non[biological](Detailed_description', 25: 'B-Nonbiological_location', 26: 'B-Occupation', 27: 'B-Other_entity', 28: 'B-Other_event', 29: 'B-Outcome', 30: 'B-Personal_[back](Biological_structure', 31: 'B-Personal_background', 32: 'B-Qualitative_concept', 33: 'B-Quantitative_concept', 34: 'B-Severity', 35: 'B-Sex', 36: 'B-Shape', 37: 'B-Sign_symptom', 38: 'B-Subject', 39: 'B-Texture', 40: 'B-Therapeutic_procedure', 41: 'B-Time', 42: 'B-Volume', 43: 'B-Weight', 44: 'I-Activity', 45: 'I-Administration', 46: 'I-Age', 47: 'I-Area', 48: 'I-Biological_attribute', 49: 'I-Biological_structure', 50: 'I-Clinical_event', 51: 'I-Color', 52: 'I-Coreference', 53: 'I-Date', 54: 'I-Detailed_description', 55: 'I-Diagnostic_procedure', 56: 'I-Disease_disorder', 57: 'I-Distance', 58: 'I-Dosage', 59: 'I-Duration', 60: 'I-Family_history', 61: 'I-Frequency', 62: 'I-Height', 63: 'I-History', 64: 'I-Lab_value', 65: 'I-Mass', 66: 'I-Medication', 67: 'I-Nonbiological_location', 68: 'I-Occupation', 69: 'I-Other_entity', 70: 'I-Other_event', 71: 'I-Outcome', 72: 'I-Personal_background', 73: 'I-Qualitative_concept', 74: 'I-Quantitative_concept', 75: 'I-Severity', 76: 'I-Shape', 77: 'I-Sign_symptom', 78: 'I-Subject', 79: 'I-Texture', 80: 'I-Therapeutic_procedure', 81: 'I-Time', 82: 'I-Volume', 83: 'I-Weight'}\n"
]
}
],
"source": [
"print(model.config.id2label)\n"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Device set to use cpu\n"
]
}
],
"source": [
"# Use a pipeline as a high-level helper\n",
"from transformers import pipeline\n",
"\n",
"pipe = pipeline(\"token-classification\", model=\"d4data/biomedical-ner-all\")"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[{'entity': 'B-Sign_symptom',\n",
" 'score': np.float32(0.49143293),\n",
" 'index': 4,\n",
" 'word': 'cold',\n",
" 'start': 12,\n",
" 'end': 16},\n",
" {'entity': 'B-Sign_symptom',\n",
" 'score': np.float32(0.9995566),\n",
" 'index': 11,\n",
" 'word': 's',\n",
" 'start': 38,\n",
" 'end': 39},\n",
" {'entity': 'B-Sign_symptom',\n",
" 'score': np.float32(0.9910192),\n",
" 'index': 12,\n",
" 'word': '##nee',\n",
" 'start': 39,\n",
" 'end': 42},\n",
" {'entity': 'I-Sign_symptom',\n",
" 'score': np.float32(0.9908077),\n",
" 'index': 13,\n",
" 'word': '##zing',\n",
" 'start': 42,\n",
" 'end': 46},\n",
" {'entity': 'B-Sign_symptom',\n",
" 'score': np.float32(0.9976502),\n",
" 'index': 15,\n",
" 'word': 'not',\n",
" 'start': 51,\n",
" 'end': 54},\n",
" {'entity': 'I-Sign_symptom',\n",
" 'score': np.float32(0.90227133),\n",
" 'index': 16,\n",
" 'word': 'tired',\n",
" 'start': 55,\n",
" 'end': 60}]"
]
},
"execution_count": 17,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"pipe(\"i am having cold, cough, nose block , sneezing but not tired\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/home/mcqueen/Documents/SmartHealth-LLM/venv/lib/python3.12/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n",
" from .autonotebook import tqdm as notebook_tqdm\n",
"Device set to use cpu\n"
]
},
{
"data": {
"text/plain": [
"[{'entity_group': 'Sign_symptom',\n",
" 'score': np.float32(0.9999311),\n",
" 'word': 'pal',\n",
" 'start': 38,\n",
" 'end': 41},\n",
" {'entity_group': 'Sign_symptom',\n",
" 'score': np.float32(0.9063307),\n",
" 'word': '##pitations',\n",
" 'start': 41,\n",
" 'end': 50},\n",
" {'entity_group': 'Clinical_event',\n",
" 'score': np.float32(0.99975544),\n",
" 'word': 'follow',\n",
" 'start': 54,\n",
" 'end': 60},\n",
" {'entity_group': 'Date',\n",
" 'score': np.float32(0.999867),\n",
" 'word': '6 months after',\n",
" 'start': 64,\n",
" 'end': 78}]"
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from transformers import pipeline\n",
"from transformers import AutoTokenizer, AutoModelForTokenClassification\n",
"\n",
"tokenizer = AutoTokenizer.from_pretrained(\"d4data/biomedical-ner-all\")\n",
"model = AutoModelForTokenClassification.from_pretrained(\"d4data/biomedical-ner-all\")\n",
"\n",
"pipe = pipeline(\"ner\", model=model, tokenizer=tokenizer, aggregation_strategy=\"simple\") # pass device=0 if using gpu\n",
"pipe(\"\"\"The patient reported no recurrence of palpitations at follow-up 6 months after the ablation.\"\"\")\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/home/mcqueen/Documents/SmartHealth-LLM/venv/lib/python3.12/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n",
" from .autonotebook import tqdm as notebook_tqdm\n"
]
},
{
"ename": "ModuleNotFoundError",
"evalue": "No module named 'backend'",
"output_type": "error",
"traceback": [
"\u001b[31m---------------------------------------------------------------------------\u001b[39m",
"\u001b[31mModuleNotFoundError\u001b[39m Traceback (most recent call last)",
"\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[1]\u001b[39m\u001b[32m, line 6\u001b[39m\n\u001b[32m 3\u001b[39m \u001b[38;5;28;01mfrom\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01mlangchain\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;28;01mimport\u001b[39;00m hub\n\u001b[32m 5\u001b[39m \u001b[38;5;66;03m# Your tools\u001b[39;00m\n\u001b[32m----> \u001b[39m\u001b[32m6\u001b[39m \u001b[38;5;28;01mfrom\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01mbackend\u001b[39;00m\u001b[34;01m.\u001b[39;00m\u001b[34;01mtools\u001b[39;00m\u001b[34;01m.\u001b[39;00m\u001b[34;01mdisease_info_retriever\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;28;01mimport\u001b[39;00m disease_info_retriever_func\n\u001b[32m 7\u001b[39m \u001b[38;5;28;01mfrom\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01mbackend\u001b[39;00m\u001b[34;01m.\u001b[39;00m\u001b[34;01mtools\u001b[39;00m\u001b[34;01m.\u001b[39;00m\u001b[34;01mgoogle_search\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;28;01mimport\u001b[39;00m google_search\n\u001b[32m 8\u001b[39m \u001b[38;5;28;01mfrom\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01mbackend\u001b[39;00m\u001b[34;01m.\u001b[39;00m\u001b[34;01mtools\u001b[39;00m\u001b[34;01m.\u001b[39;00m\u001b[34;01mbiomedical_ner_tool\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;28;01mimport\u001b[39;00m extract_data\n",
"\u001b[31mModuleNotFoundError\u001b[39m: No module named 'backend'"
]
}
],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "venv",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.3"
}
},
"nbformat": 4,
"nbformat_minor": 2
}