Browse Source

Added my contributions to community-contributions

pull/93/head
kanitvural 4 months ago
parent
commit
dffb995e7e
  1. 714
      week1/community-contributions/day2 EXERCISE_llama_on_my_web_page.ipynb

714
week1/community-contributions/day2 EXERCISE_llama_on_my_web_page.ipynb

@ -0,0 +1,714 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "d15d8294-3328-4e07-ad16-8a03e9bbfdb9",
"metadata": {},
"source": [
"# Welcome to your first assignment!\n",
"\n",
"Instructions are below. Please give this a try, and look in the solutions folder if you get stuck (or feel free to ask me!)"
]
},
{
"cell_type": "markdown",
"id": "ada885d9-4d42-4d9b-97f0-74fbbbfe93a9",
"metadata": {},
"source": [
"<table style=\"margin: 0; text-align: left;\">\n",
" <tr>\n",
" <td style=\"width: 150px; height: 150px; vertical-align: middle;\">\n",
" <img src=\"../resources.jpg\" width=\"150\" height=\"150\" style=\"display: block;\" />\n",
" </td>\n",
" <td>\n",
" <h2 style=\"color:#f71;\">Just before we get to the assignment --</h2>\n",
" <span style=\"color:#f71;\">I thought I'd take a second to point you at this page of useful resources for the course. This includes links to all the slides.<br/>\n",
" <a href=\"https://edwarddonner.com/2024/11/13/llm-engineering-resources/\">https://edwarddonner.com/2024/11/13/llm-engineering-resources/</a><br/>\n",
" Please keep this bookmarked, and I'll continue to add more useful links there over time.\n",
" </span>\n",
" </td>\n",
" </tr>\n",
"</table>"
]
},
{
"cell_type": "markdown",
"id": "6e9fa1fc-eac5-4d1d-9be4-541b3f2b3458",
"metadata": {},
"source": [
"# HOMEWORK EXERCISE ASSIGNMENT\n",
"\n",
"Upgrade the day 1 project to summarize a webpage to use an Open Source model running locally via Ollama rather than OpenAI\n",
"\n",
"You'll be able to use this technique for all subsequent projects if you'd prefer not to use paid APIs.\n",
"\n",
"**Benefits:**\n",
"1. No API charges - open-source\n",
"2. Data doesn't leave your box\n",
"\n",
"**Disadvantages:**\n",
"1. Significantly less power than Frontier Model\n",
"\n",
"## Recap on installation of Ollama\n",
"\n",
"Simply visit [ollama.com](https://ollama.com) and install!\n",
"\n",
"Once complete, the ollama server should already be running locally. \n",
"If you visit: \n",
"[http://localhost:11434/](http://localhost:11434/)\n",
"\n",
"You should see the message `Ollama is running`. \n",
"\n",
"If not, bring up a new Terminal (Mac) or Powershell (Windows) and enter `ollama serve` \n",
"And in another Terminal (Mac) or Powershell (Windows), enter `ollama pull llama3.2` \n",
"Then try [http://localhost:11434/](http://localhost:11434/) again.\n",
"\n",
"If Ollama is slow on your machine, try using `llama3.2:1b` as an alternative. Run `ollama pull llama3.2:1b` from a Terminal or Powershell, and change the code below from `MODEL = \"llama3.2\"` to `MODEL = \"llama3.2:1b\"`"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "4e2a9393-7767-488e-a8bf-27c12dca35bd",
"metadata": {},
"outputs": [],
"source": [
"# imports\n",
"\n",
"import requests\n",
"from bs4 import BeautifulSoup\n",
"from IPython.display import Markdown, display"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "29ddd15d-a3c5-4f4e-a678-873f56162724",
"metadata": {},
"outputs": [],
"source": [
"# Constants\n",
"\n",
"OLLAMA_API = \"http://localhost:11434/api/chat\"\n",
"HEADERS = {\"Content-Type\": \"application/json\"}\n",
"MODEL = \"llama3.2\""
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "dac0a679-599c-441f-9bf2-ddc73d35b940",
"metadata": {},
"outputs": [],
"source": [
"# Create a messages list using the same format that we used for OpenAI\n",
"\n",
"messages = [\n",
" {\"role\": \"user\", \"content\": \"Describe some of the business applications of Generative AI\"}\n",
"]"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "7bb9c624-14f0-4945-a719-8ddb64f66f47",
"metadata": {},
"outputs": [],
"source": [
"payload = {\n",
" \"model\": MODEL,\n",
" \"messages\": messages,\n",
" \"stream\": False\n",
" }"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "479ff514-e8bd-4985-a572-2ea28bb4fa40",
"metadata": {},
"outputs": [],
"source": [
"# Let's just make sure the model is loaded\n",
"\n",
"!ollama pull llama3.2"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "42b9f644-522d-4e05-a691-56e7658c0ea9",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Generative AI has numerous business applications across various industries. Here are some examples:\n",
"\n",
"1. **Content Creation**: Generative AI can generate high-quality content such as:\n",
"\t* Articles and blog posts\n",
"\t* Social media posts and captions\n",
"\t* Product descriptions and e-commerce content\n",
"\t* Music and audio tracks\n",
"2. **Product Design and Development**: Generative AI can assist in product design, prototyping, and development by:\n",
"\t* Generating 3D models and CAD designs\n",
"\t* Creating prototypes and mockups\n",
"\t* Optimizing product performance and functionality\n",
"3. **Marketing and Advertising**: Generative AI can help with marketing and advertising efforts by:\n",
"\t* Generating personalized ad copy and landing pages\n",
"\t* Creating social media ads and promotions\n",
"\t* Analyzing customer behavior and sentiment to inform marketing strategies\n",
"4. **Data Analysis and Visualization**: Generative AI can aid in data analysis and visualization by:\n",
"\t* Generating insights and recommendations from large datasets\n",
"\t* Creating visualizations and reports to communicate findings\n",
"\t* Identifying patterns and trends in complex data\n",
"5. **Customer Service and Support**: Generative AI can be used to power chatbots and virtual assistants that:\n",
"\t* Provide customer support and answer frequently asked questions\n",
"\t* Route customers to human representatives when needed\n",
"\t* Analyze customer feedback and sentiment to improve service\n",
"6. **Personalized Recommendations**: Generative AI can generate personalized product recommendations for e-commerce platforms, streaming services, and more.\n",
"7. **Content Moderation and Review**: Generative AI can assist in content moderation by:\n",
"\t* Analyzing online content for hate speech, harassment, or explicit material\n",
"\t* Generating reviews and ratings for products or services\n",
"8. **Supply Chain Optimization**: Generative AI can help optimize supply chains by:\n",
"\t* Predicting demand and inventory levels\n",
"\t* Identifying bottlenecks and inefficiencies in logistics and transportation\n",
"9. **Financial Analysis and Modeling**: Generative AI can aid in financial analysis and modeling by:\n",
"\t* Generating forecasts and predictions for sales, revenue, and expenses\n",
"\t* Analyzing financial data to identify trends and patterns\n",
"10. **Creative Writing and Copywriting**: Generative AI can generate high-quality creative writing and copywriting content, such as:\n",
"\t* Blog posts and articles\n",
"\t* Social media posts and captions\n",
"\t* Advertisements and marketing materials\n",
"\n",
"These are just a few examples of the many business applications of Generative AI. As the technology continues to evolve, we can expect to see even more innovative uses in various industries.\n"
]
}
],
"source": [
"# If this doesn't work for any reason, try the 2 versions in the following cells\n",
"# And double check the instructions in the 'Recap on installation of Ollama' at the top of this lab\n",
"# And if none of that works - contact me!\n",
"\n",
"response = requests.post(OLLAMA_API, json=payload, headers=HEADERS)\n",
"print(response.json()['message']['content'])"
]
},
{
"cell_type": "markdown",
"id": "6a021f13-d6a1-4b96-8e18-4eae49d876fe",
"metadata": {},
"source": [
"# Introducing the ollama package\n",
"\n",
"And now we'll do the same thing, but using the elegant ollama python package instead of a direct HTTP call.\n",
"\n",
"Under the hood, it's making the same call as above to the ollama server running at localhost:11434"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "7745b9c4-57dc-4867-9180-61fa5db55eb8",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Generative AI has numerous business applications across various industries. Here are some examples:\n",
"\n",
"1. **Content Generation**: Generative AI can be used to generate high-quality content such as articles, social media posts, product descriptions, and even entire books. This can help businesses save time and resources while maintaining a consistent tone and style.\n",
"2. **Product Design**: Generative AI can aid in the design of products such as 3D models, logos, and packaging designs. It can also be used to generate new product ideas based on existing product lines.\n",
"3. **Marketing Campaigns**: Generative AI can help create personalized marketing campaigns by generating targeted content, social media posts, and even entire ad campaigns.\n",
"4. **Image and Video Generation**: Generative AI can be used to generate high-quality images and videos for businesses such as e-commerce websites, social media platforms, and advertising agencies.\n",
"5. **Customer Service Chatbots**: Generative AI-powered chatbots can provide personalized customer service experiences by generating responses based on the customer's query or intent.\n",
"6. **Financial Analysis**: Generative AI can be used to analyze financial data, generate forecasts, and even create investment strategies for businesses and investors.\n",
"7. **Supply Chain Optimization**: Generative AI can help optimize supply chain operations by predicting demand, identifying bottlenecks, and optimizing logistics.\n",
"8. **Human Resources Management**: Generative AI can aid in HR tasks such as talent acquisition, resume screening, and employee performance analysis.\n",
"9. **Cybersecurity Threat Detection**: Generative AI-powered systems can detect and predict cyber threats by analyzing network traffic, system logs, and other data sources.\n",
"10. **Data Journalism**: Generative AI can be used to generate leads for investigative journalism projects, analyze large datasets, and even create visualizations of complex data.\n",
"\n",
"Some industries that are heavily impacted by generative AI include:\n",
"\n",
"1. **Media and Entertainment**: Generative AI is being used in content creation, music production, and video editing.\n",
"2. **E-commerce**: Generative AI can aid in product design, image generation, and customer service chatbots.\n",
"3. **Finance and Banking**: Generative AI can be used for financial analysis, risk assessment, and portfolio optimization.\n",
"4. **Healthcare**: Generative AI is being used to analyze medical data, generate new treatments, and optimize patient outcomes.\n",
"5. **Manufacturing**: Generative AI can aid in product design, supply chain optimization, and predictive maintenance.\n",
"\n",
"Overall, generative AI has the potential to transform businesses across various industries by automating repetitive tasks, providing new insights, and enhancing customer experiences.\n"
]
}
],
"source": [
"import ollama\n",
"\n",
"response = ollama.chat(model=MODEL, messages=messages)\n",
"print(response['message']['content'])"
]
},
{
"cell_type": "markdown",
"id": "a4704e10-f5fb-4c15-a935-f046c06fb13d",
"metadata": {},
"source": [
"## Alternative approach - using OpenAI python library to connect to Ollama"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "23057e00-b6fc-4678-93a9-6b31cb704bff",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Generative AI has numerous business applications across various industries, including:\n",
"\n",
"1. **Content Creation**: Generative AI can generate high-quality content such as text, images, and videos, reducing the need for manual labor and increasing efficiency.\n",
"2. **Marketing and Advertising**: Generative AI can create personalized marketing campaigns, product recommendations, and ad copy, improving customer engagement and conversion rates.\n",
"3. **Product Design**: Generative AI can design products, prototypes, and even entire product lines, streamlining the innovation process and reducing development costs.\n",
"4. **Virtual Productization**: Generative AI can generate digital twins of physical products, allowing for testing, iteration, and virtual marketing without the need for physical prototyping.\n",
"5. **Chatbots and Customer Service**: Generative AI-powered chatbots can provide personalized customer support, answer frequently asked questions, and handle routine tasks, freeing up human customer service agents to focus on complex issues.\n",
"6. **Data Analytics**: Generative AI can analyze large datasets, identify patterns, and predict trends, providing actionable insights for business decision-making.\n",
"7. **Predictive Maintenance**: Generative AI can predict equipment failures, schedule maintenance, and optimize resource allocation, reducing downtime and increasing overall efficiency.\n",
"8. **Image Recognition**: Generative AI can recognize and classify images, enabling applications such as self-driving cars, security monitoring, and medical diagnosis.\n",
"9. **Voice Assistants**: Generative AI can power voice assistants, providing users with personalized recommendations, scheduling appointments, and controlling smart home devices.\n",
"10. **Research and Development**: Generative AI can generate hypotheses, simulate experiments, and predict outcomes, accelerating the pace of innovation and discovery.\n",
"\n",
"Some specific business use cases include:\n",
"\n",
"* **Automated content writing**: Generative AI can write articles, blog posts, and social media content for news agencies, publishers, and marketing firms.\n",
"* **Virtual fashion designers**: Generative AI can design clothing, accessories, and even entire fashion collections, reducing the need for human designers and enabling mass customization.\n",
"* **Personal finance advisors**: Generative AI can provide personalized financial planning, budgeting, and investment advice to individuals and businesses.\n",
"* **Intelligent transportation systems**: Generative AI can optimize traffic flow, predict maintenance needs, and improve overall safety and efficiency in urban areas.\n",
"\n",
"These are just a few examples of the many business applications of Generative AI. As the technology continues to evolve, we can expect to see even more innovative solutions emerge across various industries.\n"
]
}
],
"source": [
"# There's actually an alternative approach that some people might prefer\n",
"# You can use the OpenAI client python library to call Ollama:\n",
"\n",
"from openai import OpenAI\n",
"ollama_via_openai = OpenAI(base_url='http://localhost:11434/v1', api_key='ollama')\n",
"\n",
"response = ollama_via_openai.chat.completions.create(\n",
" model=MODEL,\n",
" messages=messages\n",
")\n",
"\n",
"print(response.choices[0].message.content)"
]
},
{
"cell_type": "markdown",
"id": "1622d9bb-5c68-4d4e-9ca4-b492c751f898",
"metadata": {},
"source": [
"# NOW the exercise for you\n",
"\n",
"Take the code from day1 and incorporate it here, to build a website summarizer that uses Llama 3.2 running locally instead of OpenAI; use either of the above approaches."
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "402d5686-4e76-4110-b65a-b3906c35c0a4",
"metadata": {},
"outputs": [],
"source": [
"class Website:\n",
" \n",
" def __init__(self, url):\n",
" \n",
" self.url = url\n",
" HEADERS = {\"Content-Type\": \"application/json\"}\n",
" response = requests.get(self.url, headers = HEADERS)\n",
" soup = BeautifulSoup(response.content, \"html.parser\")\n",
" \n",
" self.title = soup.title.string if soup.title else \"No Title Found!\"\n",
" \n",
" for item in soup.body([\"img\",\"script\",\"style\",\"input\"]):\n",
" item.decompose() \n",
" \n",
" self.text = soup.body.get_text(separator=\"\\n\", strip=True)"
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "5f4bc0a1",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Kanit Vural | Data Scientist & ML Engineer\n",
"Home\n",
"About\n",
"Skills\n",
"Projects\n",
"Blog\n",
"Contact\n",
"Kanıt Vural\n",
"|\n",
"Transforming data into actionable insights and building intelligent solutions\n",
"Get in Touch\n",
"About Me\n",
"Data Scientist & Mine Research & Development Engineer with expertise in AI-driven solutions\n",
"He began his career in 2008 at Erdemir Mining Company as a Mining R&D Engineer, part of Oyak Mining Metallurgy Group in Divriği, Turkey. Early on, he worked on geophysical gravity and magnetic iron ore exploration and learned Surpac software to create 3D solid models from drill data. He enhanced his skills in Geostatistics through training at Hacettepe University.\n",
"With this expertise, he created block models and conducted reserve classifications, improving the company’s cost-efficiency and profits. He played a key role in discovering new fields and developing existing reserves, contributing to significant financial gains.\n",
"In 2020, he joined Tosyalı Iron Steel Angola, a subsidiary of Tosyalı Holding, in Jamba, Angola. He continued reserve classifications using Datamine software and discovered new iron and gold fields. He also mentored junior engineers by providing Datamine training.\n",
"Software has always been his passion, starting in high school and continuing throughout his career. He pursued courses in web development, mobile app development, cybersecurity, and data science, eventually discovering his true passion for data science. He took a career break to intensively train in this field, and continues to learn and work on projects daily.\n",
"Key Achievements\n",
"Discovered iron ore deposits totaling more than 300 million tons across multiple sites.\n",
"Applied AI-driven approaches to his work, boosting efficiency.\n",
"Passionately mentored junior engineers, empowering them to grow and reach their full potential.\n",
"With all the knowledge and experience gained over 15 years, he is ready to create added value by applying it in both the mining and IT industries.\n",
"Download CV\n",
"GitHub\n",
"AI/ML\n",
"Cloud\n",
"Data\n",
"MLOps\n",
"Skills & Expertise\n",
"Data Analysis\n",
"Statistical Analysis\n",
"Data Visualization\n",
"CRM Analytics\n",
"Machine & Deep Learning\n",
"Machine Learning Models\n",
"Computer Vision\n",
"Natural Language Processing\n",
"Cloud & Infrastructure\n",
"AWS Services\n",
"MLOps\n",
"Data Engineering\n",
"Generative AI\n",
"Large Language Models\n",
"Prompt Engineering\n",
"AI Applications\n",
"Mine Research & Development\n",
"Mine Exploration\n",
"Geostatistics\n",
"Solid & Block Modeling\n",
"Technologies I Work With\n",
"Python\n",
"NumPy\n",
"Pandas\n",
"Scikit-learn\n",
"TensorFlow\n",
"PyTorch\n",
"PySpark\n",
"Power BI\n",
"ChatGPT\n",
"Claude\n",
"LangChain\n",
"HuggingFace\n",
"FastAPI\n",
"Streamlit\n",
"Gradio\n",
"PostgreSQL\n",
"MLflow\n",
"Docker\n",
"Kubernetes\n",
"Git\n",
"GitHub\n",
"Red Hat\n",
"Jenkins\n",
"AWS\n",
"Terraform\n",
"Hadoop\n",
"Kafka\n",
"Airflow\n",
"JavaScript\n",
"Node.js\n",
"Datamine\n",
"Surpac\n",
"Qgis\n",
"Featured Projects\n",
"Smile-Based Face Recognition Access Control System\n",
"A facial recognition application using AWS infrastructure that activates with your smile and grants\n",
" access to registered users. Features email notifications, entry logging, and optional ChatGPT\n",
" integration.\n",
"AWS\n",
"Terraform\n",
"Python\n",
"Face Recognition\n",
"Learn More\n",
"Voice2Image AI Generator\n",
"An innovative application that transforms voice into images using AI. Record your voice to generate\n",
" text via\n",
" OpenAI's Whisper, create images with DALL·E, and enhance results using Gemini 1.5 Pro for\n",
" regeneration.\n",
"OpenAI\n",
"DALL·E\n",
"Python\n",
"Gemini\n",
"Learn More\n",
"Chat with YouTube Video\n",
"A powerful application that allows you to interact with YouTube videos by converting them into text\n",
" and asking\n",
" questions about their content. Uses OpenAI's Whisper for speech-to-text, LangChain's RAG for Q&A, and\n",
" Gemini\n",
" Pro for chat.\n",
"OpenAI Whisper\n",
"LangChain\n",
"Gemini Pro\n",
"Streamlit\n",
"Learn More\n",
"Data Analyzer with LLM Agents\n",
"An intelligent application that analyzes CSV files using advanced language models. Features automatic\n",
" descriptive statistics, data visualization, and LLM-powered Q&A about datasets. Supports multiple\n",
" models like\n",
" Gemini, Claude, and GPT.\n",
"LangChain\n",
"Streamlit\n",
"Data Analysis\n",
"LLM Agents\n",
"Learn More\n",
"Evolution of Sentiment Analysis\n",
"A comprehensive exploration of NLP techniques from rule-based to transformer models, analyzing IMDB\n",
" reviews.\n",
" Features machine learning, deep learning (LSTM, CNN), and BERT implementations with detailed\n",
" performance comparisons.\n",
"NLP\n",
"BERT\n",
"Deep Learning\n",
"TensorFlow\n",
"Learn More\n",
"Fish Species Classification with ANN\n",
"An image classification project using Artificial Neural Networks to identify 9 different fish\n",
" species. Features\n",
" smart cropping, PCA dimensionality reduction, and K-means clustering for image preprocessing,\n",
" achieving 91%\n",
" accuracy.\n",
"TensorFlow\n",
"Computer Vision\n",
"Neural Networks\n",
"Image Processing\n",
"Learn More\n",
"Cardiovascular Disease Prediction\n",
"A machine learning model for predicting cardiovascular diseases using patient attributes. Features\n",
" MLflow for\n",
" model tracking, Gradio for UI, and FastAPI backend. Analyzes various health metrics including ECG\n",
" results,\n",
" blood pressure, and cholesterol levels.\n",
"MLflow\n",
"FastAPI\n",
"Gradio\n",
"Machine Learning\n",
"Learn More\n",
"Vegetable Image Classification\n",
"A deep learning project that classifies 15 different types of vegetables using transfer learning with\n",
" EfficientNet B0. Features a Gradio interface for easy interaction, PyTorch implementation, and high\n",
" accuracy\n",
" image recognition.\n",
"PyTorch\n",
"EfficientNet\n",
"Gradio\n",
"Transfer Learning\n",
"Learn More\n",
"CRM Analytics & Customer Segmentation\n",
"A comprehensive CRM analysis project featuring cohort analysis, customer lifetime value prediction\n",
" using\n",
" BG-NBD and Gamma-Gamma models, RFM analysis, and purchase propensity prediction. Includes customer\n",
" segmentation and targeted marketing strategies.\n",
"Customer Analytics\n",
"Machine Learning\n",
"RFM Analysis\n",
"CLTV Prediction\n",
"Learn More\n",
"Amazon Multi-Model Analysis\n",
"A comprehensive project combining sentiment analysis (LSTM with self-attention), image classification\n",
" (EfficientNetB0), and recommendation systems. Features transfer learning, BERT embeddings, and\n",
" FAISS/ChromaDB\n",
" for similarity search.\n",
"Deep Learning\n",
"BERT\n",
"AWS\n",
"TensorFlow\n",
"Learn More\n",
"Latest Blog Posts\n",
"Tracing the Evolution of Natural Language Processing Through Sentiment Analysis\n",
"An exploration of NLP's journey and its applications in sentiment\n",
" analysis...\n",
"Read on Medium\n",
"Building a Smile-Based Access Control System Using AWS\n",
"Let your smile be your password - A unique approach to access\n",
" control\n",
" using AWS services and facial recognition...\n",
"Read on Medium\n",
"Get in Touch\n",
"Interested in collaboration? Let's connect!\n",
"[email protected]\n",
"© 2025 Kanıt Vural. All rights reserved.\n"
]
}
],
"source": [
"kanit = Website(\"https://kanitvural.com\")\n",
"print(kanit.title)\n",
"print(kanit.text)"
]
},
{
"cell_type": "code",
"execution_count": 12,
"id": "c5e0d4e9",
"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": 13,
"id": "a6256788",
"metadata": {},
"outputs": [],
"source": [
"def user_prompt_for(website):\n",
" user_prompt = f\"You are looking at a website titled {website.title}\"\n",
" user_prompt += \"\\nThe contents of this website is as follows; \\\n",
"please provide a short summary of this website in markdown. \\\n",
"If it includes news or announcements, then summarize these too.\\n\\n\"\n",
" user_prompt += website.text\n",
" return user_prompt"
]
},
{
"cell_type": "code",
"execution_count": 14,
"id": "280d319c",
"metadata": {},
"outputs": [],
"source": [
"def messages_for(website):\n",
" return [\n",
" {\"role\": \"system\", \"content\": system_prompt},\n",
" {\"role\": \"user\", \"content\": user_prompt_for(website)}\n",
" ]"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "696c6316",
"metadata": {},
"outputs": [],
"source": [
"\n",
"MODEL = \"llama3.2\"\n",
"ollama_via_openai = OpenAI(base_url='http://localhost:11434/v1', api_key='ollama')"
]
},
{
"cell_type": "code",
"execution_count": 15,
"id": "da1928f8",
"metadata": {},
"outputs": [],
"source": [
"def summarize(url):\n",
" website = Website(url)\n",
" response = ollama_via_openai.chat.completions.create(\n",
" model=MODEL,\n",
" messages=messages_for(website)\n",
" )\n",
" return response.choices[0].message.content\n",
"\n",
"def display_summary(url):\n",
" summary = summarize(url)\n",
" display(Markdown(summary))"
]
},
{
"cell_type": "code",
"execution_count": 16,
"id": "4b87d41d",
"metadata": {},
"outputs": [
{
"data": {
"text/markdown": [
"### Summary of Kanit Vural's Website\n",
"\n",
"Kanit Vural is a Data Scientist & ML Engineer with expertise in AI-driven solutions. His website provides an overview of his skills, experience, and projects.\n",
"\n",
"#### Key Insights\n",
"\n",
"* **15+ years of experience**: Starting as a Mining R&D Engineer in 2008.\n",
"* **Strong foundation in geostatistics** through Hacettepe University training.\n",
"* **Wide range of technologies**: Python, NumPy, Pandas, Scikit-learn, TensorFlow, PyTorch, and more.\n",
"* **Variety of projects**:\n",
"\t+ Face recognition application\n",
"\t+ Voice-to-image converter using AI\n",
"\t+ Chatbot for YouTube videos\n",
"\t+ Intelligent data analysis with LLM agents\n",
"\t+ Comprehensive exploration of sentiment analysis and NLP techniques.\n",
"\n",
"#### Featured Projects\n",
"\n",
"1. Smile-Based Face Recognition Access Control System\n",
"2. Data Analyzer with LLM Agents\n",
"3. Evolution of Sentiment Analysis\n",
"4. Fish Species Classification with ANN\n",
"5. Cardiovascular Disease Prediction\n",
"6. Vegetable Image Classification\n",
"7. CRM Analytics & Customer Segmentation\n",
"8. Amazon Multi-Model Analysis"
],
"text/plain": [
"<IPython.core.display.Markdown object>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"display_summary(\"https://kanitvural.com\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "9f072c77",
"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.6"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Loading…
Cancel
Save