Browse Source

update day2 exercise

pull/52/head
Madhul Sachdeva 5 months ago
parent
commit
1891028ca8
  1. 177
      Madhul-Solutions/MS-PDF-Analyser.ipynb
  2. 443
      week1/day1.ipynb
  3. 116
      week1/day2 EXERCISE.ipynb
  4. 2
      week1/solutions/day2 SOLUTION.ipynb

177
Madhul-Solutions/MS-PDF-Analyser.ipynb

@ -26,7 +26,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 1,
"id": "14e98361-f302-423d-87a5-f2f5d570f4ac",
"metadata": {},
"outputs": [],
@ -37,7 +37,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 2,
"id": "06b63787-c6c8-4868-8a71-eb56b7618626",
"metadata": {},
"outputs": [],
@ -55,10 +55,18 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 3,
"id": "284ca770-5da4-495c-b1cf-637727a8609f",
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"API key found and looks good so far!\n"
]
}
],
"source": [
"# Load environment variables in a file called .env\n",
"\n",
@ -79,7 +87,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 4,
"id": "d4c316d7-d9c9-4400-b03e-1dd629c6b2ad",
"metadata": {},
"outputs": [],
@ -93,7 +101,7 @@
},
{
"cell_type": "code",
"execution_count": 60,
"execution_count": 5,
"id": "b6f2967e-4779-458f-aea8-c47147528f77",
"metadata": {},
"outputs": [],
@ -173,11 +181,9 @@
]
},
{
"cell_type": "code",
"execution_count": 61,
"id": "821acbfa-ad06-4afd-9ac1-b9f68b7a418e",
"cell_type": "markdown",
"id": "1510e4df-b15f-4411-924c-feca1c72419a",
"metadata": {},
"outputs": [],
"source": [
"# General Research Analyst\n",
"#### Step 1: Create your prompts\n",
@ -199,7 +205,33 @@
},
{
"cell_type": "code",
"execution_count": 62,
"execution_count": 10,
"id": "f71a47af-5f16-4b8f-880d-7fc41727564b",
"metadata": {},
"outputs": [],
"source": [
"# Financial Report Analyst\n",
"#### Step 1: Create your prompts\n",
"\n",
"def craft_user_prompt(article):\n",
" user_prompt = f\"You are looking at a document titled {article.title}\\n Based on the body of the document, provide an impactful summary. Call out important points as bullets and highlughts . The body of the article is as follows.\"\n",
" user_prompt += article.text\n",
" return user_prompt\n",
"\n",
"#### Step 2: Make the messages list\n",
"def craft_messages(article):\n",
" system_prompt = '''You are a financial report research assistant that specialises in analysing the contents of a financial report and provide summary for investors to \\ \n",
" help adjust investment strategies. Call out important points as bullets and highlights. \\\n",
" Ignore text that doesn't belong to the article, like headers or navigation related text. Respond in markdown. Structure your text in the form of question/answer.'''\n",
" return [\n",
" {\"role\": \"system\", \"content\": system_prompt},\n",
" {\"role\": \"user\", \"content\": craft_user_prompt(article)}\n",
" ]"
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "81ab896e-1ba9-4964-a477-2a0608b7036c",
"metadata": {},
"outputs": [],
@ -224,7 +256,7 @@
},
{
"cell_type": "code",
"execution_count": 63,
"execution_count": 12,
"id": "008c03fd-9cc5-4449-a054-7bbef1863b01",
"metadata": {},
"outputs": [
@ -233,64 +265,55 @@
"output_type": "stream",
"text": [
"Please input the pdf URL: \n",
" https://www.binasss.sa.cr/bibliotecas/bhm/ago22/32.pdf\n"
" https://www.spandanasphoorty.com/images_gallary/1714392044-256403-20242904050444-0195731001714392044.pdf\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"/home/msachdeva/anaconda3/envs/llms/lib/python3.11/site-packages/urllib3/connectionpool.py:1099: InsecureRequestWarning: Unverified HTTPS request is being made to host 'www.spandanasphoorty.com'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#tls-warnings\n",
" warnings.warn(\n"
]
},
{
"data": {
"text/markdown": [
"## Summary of **Bronchiectasis — A Clinical Review**\n",
"\n",
"### What is bronchiectasis?\n",
"- Bronchiectasis is a clinical syndrome characterized by:\n",
" - Chronic cough \n",
" - Sputum production\n",
" - Abnormal thickening and dilation of bronchial walls, visible on lung imaging.\n",
"\n",
"### Historical Background\n",
"- First reported by René Laënnec in 1819.\n",
"- Radiographic characteristics understood more clearly since the 1950s.\n",
"\n",
"### Current Trends\n",
"- Significantly increasing incidence and prevalence over the last 20 years.\n",
"- Diagnosed across a wide age range, with geographic variability in prevalence (as high as 1.5% in some populations).\n",
"- Improved recognition, partly due to advanced imaging technologies like CT scans.\n",
" \n",
"### Clinical Presentation\n",
"- Symptoms include chronic productive cough, chest pain, and shortness of breath.\n",
"- Often misdiagnosed as chronic bronchitis or asthma, leading to delayed diagnosis.\n",
"- Intermittent exacerbations are common, defined by a worsening of cough and sputum characteristics for 48 hours or more.\n",
"\n",
"### Diagnostic Approaches\n",
"- High-resolution CT scans are essential for diagnosis, seeking specific airway abnormalities.\n",
"- A systematic evaluation to identify underlying causes (such as congenital disorders or autoimmune diseases) is critical.\n",
"\n",
"### Pathobiology\n",
"- Multiple factors lead to airway dysfunction, inflammatory responses, and cyclical deterioration.\n",
"- Neutrophils and neutrophil elastase play significant roles in disease progression and exacerbations.\n",
"\n",
"### Microbiological Features\n",
"- **Common pathogens**:\n",
" - Pseudomonas aeruginosa (notably linked to exacerbations and worse prognosis)\n",
" - Staphylococcus aureus and other bacteria.\n",
"- Non-tuberculous mycobacterial infections are reported increasingly.\n",
"\n",
"### Treatment Strategies\n",
"- Emphasizes education about the disease and its management.\n",
"- Goals include symptom management, quality of life improvement, and reduction of exacerbation frequency.\n",
"- Options include:\n",
" - Airway-clearance therapies\n",
" - Antibiotics (macrolides or inhaled antibiotics)\n",
" - Addressing any treatable underlying conditions.\n",
"\n",
"### Prognostic Indicators\n",
"- Disease severity scores like the Bronchiectasis Severity Index and FACED scale are used for predicting outcomes.\n",
"\n",
"### Future Directions\n",
"- Emphasis on research into novel therapies targeting inflamatory pathways and innovative diagnostic tools.\n",
"\n",
"### Conclusion\n",
"- Bronchiectasis represents a complex clinical challenge that requires a multidisciplinary approach for effective management and treatment improvements. Further understanding of the disease mechanisms, enhancing diagnostic processes, and tailored therapies are vital for future advancements in the care of patients."
"## Summary of Spandana Sphoorty Financial Limited's Financial Results for FY24\n",
"\n",
"### What are the key financial highlights for FY24?\n",
"- **Profit After Tax (PAT):** Achieved an all-time high of **₹501 Cr**, significantly up from **₹12 Cr** in FY23.\n",
"- **Assets Under Management (AUM):** Increased by **41%**, reaching **₹11,973 Cr**, up from **₹8,511 Cr** in FY23.\n",
"- **New Customer Acquisition:** Grew by **59%**, adding **13.9 lac** customers in FY24 compared to **8.8 lac** in FY23.\n",
"- **Disbursement:** Total of **₹10,688 Cr**, up **32%** from **₹8,125 Cr** in FY23.\n",
"- **Asset Quality:** \n",
" - **Gross Non-Performing Assets (GNPA):** Improved to **1.50%** from **2.07%** in FY23.\n",
" - **Net Non-Performing Assets (NNPA):** Reduced to **0.30%** from **0.64%** in FY23.\n",
"- **Total Income:** Rose **72%** to **₹2,534 Cr** from **₹1,477 Cr** in FY23.\n",
"- **Net Interest Income (NII):** Increased by **59%** to **₹1,289 Cr** from **₹810 Cr** in FY23.\n",
"\n",
"### How did performance change in Q4FY24?\n",
"- **AUM:** Increased **15% QoQ** and **41% YoY**.\n",
"- **New Customer Acquisition:** Added **4.4 lac** customers in Q4, a **30%** increase QoQ.\n",
"- **Disbursement:** **₹3,970 Cr** in Q4FY24, a **56% QoQ** and **30% YoY** growth.\n",
"- **GNPA & NNPA:** Further improved to **1.50%** and **0.30%** respectively.\n",
"\n",
"### What are the operational efficiencies noted in the report?\n",
"- **Collection Efficiency:** \n",
" - Gross collection efficiency stood at **99.3%**.\n",
" - Net collection efficiency at **96.5%**.\n",
"- **Funding & Borrowings:** \n",
" - Total borrowings increased by **81%** to **₹10,441 Cr** compared to **₹5,775 Cr** in FY23.\n",
"\n",
"### What does the management say about the future?\n",
"- Mr. Shalabh Saxena, CEO, indicates continued focus on sustaining growth and improving efficiencies for FY25. The strategy incorporates managing multiple organizational priorities, including branch expansion and portfolio quality improvement.\n",
"\n",
"### What are the implications for investors?\n",
"- **Strong Growth Indicators:** The noteworthy increase in revenue, profits, and customer acquisition positions Spandana as a promising investment within the microfinance sector.\n",
"- **Reduced Risk Profile:** Improved asset quality metrics (GNPA and NNPA) suggest better risk management and opportunity for long-term stability.\n",
"- **Focus on Operational Efficiency:** The commitment to enhancing distribution productivity may enhance profitability, further benefiting shareholders.\n",
"\n",
"Investors might consider these highlights to evaluate or adjust their investment strategies regarding microfinance and rural-focused financial services in India."
],
"text/plain": [
"<IPython.core.display.Markdown object>"
@ -307,30 +330,6 @@
"display(Markdown(summary))"
]
},
{
"cell_type": "markdown",
"id": "fd2cb395-9e29-438e-9388-5555673b4689",
"metadata": {},
"source": [
"# Financial Report Analyst\n",
"#### Step 1: Create your prompts\n",
"\n",
"def craft_user_prompt(article):\n",
" user_prompt = f\"You are looking at a document titled {article.title}\\n Based on the body of the document, provide an impactful summary. Call out important points as bullets and highlughts . The body of the article is as follows.\"\n",
" user_prompt += article.text\n",
" return user_prompt\n",
"\n",
"#### Step 2: Make the messages list\n",
"def craft_messages(article):\n",
" system_prompt = '''You are a financial report research assistant that specialises in analysing the contents of a financial report and provide summary for investors to \\ \n",
" help adjust investment strategies. Call out important points as bullets and highlights. \\\n",
" Ignore text that doesn't belong to the article, like headers or navigation related text. Respond in markdown. Structure your text in the form of question/answer.'''\n",
" return [\n",
" {\"role\": \"system\", \"content\": system_prompt},\n",
" {\"role\": \"user\", \"content\": craft_user_prompt(article)}\n",
" ]"
]
},
{
"cell_type": "markdown",
"id": "70cbbffd-bf70-47d1-b5d6-5f929bdd89eb",

443
week1/day1.ipynb

File diff suppressed because one or more lines are too long

116
week1/day2 EXERCISE.ipynb

@ -90,6 +90,7 @@
"# Constants\n",
"\n",
"OLLAMA_API = \"http://localhost:11434/api/chat\"\n",
"#OLLAMA_API = \"http://192.168.0.207:11434/api/chat\"\n",
"HEADERS = {\"Content-Type\": \"application/json\"}\n",
"MODEL = \"llama3.2\""
]
@ -199,7 +200,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 24,
"id": "402d5686-4e76-4110-b65a-b3906c35c0a4",
"metadata": {},
"outputs": [],
@ -216,22 +217,22 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 25,
"id": "9cfeb2c1-a2e1-47af-bd62-253b703d8130",
"metadata": {},
"outputs": [],
"source": [
"# Constants\n",
"\n",
"OLLAMA_API = \"http://localhost:11434/api/chat\"\n",
"OLLAMA_API = \"http://192.168.0.207:11434/api/chat\"\n",
"HEADERS = {\"Content-Type\": \"application/json\"}\n",
"MODEL = \"llama3.2\"\n",
"ollama_via_openai = OpenAI(base_url='http://localhost:11434/v1', api_key='ollama')"
"ollama_via_openai = OpenAI(base_url='http://192.168.0.207:11434/v1', api_key='ollama')"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 26,
"id": "76991489-946f-492c-9f62-9f73a9e53b43",
"metadata": {},
"outputs": [],
@ -312,7 +313,19 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 27,
"id": "68f20224-0ede-47c4-8ed4-7d5752374232",
"metadata": {},
"outputs": [],
"source": [
"system_prompt = \"You are an assistant that analyzes the contents of a website \\\n",
"and provides a short summary, ignoring text that might be navigation related. \\\n",
"Respond in markdown.\""
]
},
{
"cell_type": "code",
"execution_count": 28,
"id": "d5fe4e6a-24f4-483a-ae24-1e7ed1bf2a6f",
"metadata": {},
"outputs": [],
@ -341,7 +354,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 29,
"id": "f2369302-7b8c-465e-8606-b9cc0a51cb78",
"metadata": {},
"outputs": [],
@ -349,6 +362,7 @@
"# Create a messages list using the same format that we used for OpenAI\n",
"def messages_for(website):\n",
" return [\n",
" {\"role\": \"system\", \"content\": system_prompt},\n",
" {\"role\": \"user\", \"content\": user_prompt_for(website)}\n",
" ]"
]
@ -366,7 +380,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 30,
"id": "16ae9026-1684-4cc3-9859-f2cd7d22fb52",
"metadata": {},
"outputs": [],
@ -387,7 +401,29 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 31,
"id": "bcbd5962-3a75-4e94-a07e-463e874c9131",
"metadata": {},
"outputs": [],
"source": [
"import ollama\n",
"\n",
"def summarise(url):\n",
" try:\n",
" aWebsite = Website(url)\n",
" response = ollama.chat(model=MODEL, messages=messages_for(aWebsite))\n",
" return response['message']['content']\n",
" except ConnectionError as e:\n",
" return f\"Error: {str(e)}\"\n",
" except Exception as e:\n",
" return f\"An unexpected error occurred: {str(e)}\"\n",
"\n",
"#print(response['message']['content'])"
]
},
{
"cell_type": "code",
"execution_count": 32,
"id": "4e0f7264-9622-4751-83b9-a31c3c0c4589",
"metadata": {},
"outputs": [],
@ -413,10 +449,68 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 35,
"id": "d8659653-d3a1-4cc1-bbd8-a003fb22041f",
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdin",
"output_type": "stream",
"text": [
"Enter URL: https://aquasec.com\n"
]
},
{
"data": {
"text/markdown": [
"**Aqua Cloud Native Security**\n",
"\n",
"Aqua is a pioneer in securing containerized cloud native applications from development to production. Their full lifecycle solution prevents attacks by enforcing pre-deployment hygiene and mitigating attacks in real time in production, reducing mean time to repair and overall business risk.\n",
"\n",
"**Recent News**\n",
"\n",
"* **300,000+ Prometheus Servers and Exporters Exposed to DoS Attacks**: Matrix Unleashes A New Widespread DDoS Campaign\n",
"* **Aqua Nautilus research team is uniquely focused on the cloud native threat landscape**, with a sole mission to analyze threats targeting cloud native environments and protect customers from those threats.\n",
"\n",
"**Key Features**\n",
"\n",
"* **Cloud Native Application Protection Platform (CNAPP)**: Integrates security from Code to Cloud, combining agent and agentless technology into a single solution.\n",
"* **Automate DevSecOps**: Modernize Security with CNDR Cloud Native Detection & Response.\n",
"* **Compliance and Auditing**: Serverless Containers & Functions, Hybrid and Multi Cloud, Federal Cloud Native Security.\n",
"\n",
"**Use Cases**\n",
"\n",
"* **Automate DevSecOps**\n",
"* **Modernize Security**\n",
"* **CNDR Cloud Native Detection & Response**\n",
"* **Compliance and Auditing**\n",
"* **Serverless Containers & Functions**\n",
"* **Hybrid and Multi Cloud**\n",
"* **Federal Cloud Native Security**\n",
"\n",
"**Partners**\n",
"\n",
"* **Technology Partners**: Partner With Us\n",
"* **Resources**: Aqua Security Research, The Cloud Native Wiki, Kubernetes 101\n",
"\n",
"**About Us**\n",
"\n",
"Aqua is a leading provider of cloud native security solutions, founded in 2015. They protect over 500 of the world's largest enterprises with their enterprise scale solution that doesn’t slow development pipelines.\n",
"\n",
"**Contact Us**\n",
"\n",
"* **Aqua Blog**: Learn more about Aqua Security\n",
"* **Get in Touch**: Professional services and support.\n",
"* **Careers**: Join the Aqua team"
],
"text/plain": [
"<IPython.core.display.Markdown object>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"address=input(\"Enter URL: \")\n",
"display_summary(address)"

2
week1/solutions/day2 SOLUTION.ipynb

@ -455,7 +455,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.10"
"version": "3.11.11"
}
},
"nbformat": 4,

Loading…
Cancel
Save