|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "code", |
| 5 | + "execution_count": 1, |
| 6 | + "id": "a9e05d2a", |
| 7 | + "metadata": {}, |
| 8 | + "outputs": [], |
| 9 | + "source": [ |
| 10 | + "# ----- (My project)\n", |
| 11 | + "# Date: 09.01.25\n", |
| 12 | + "# Plan: Make a Gradio UI, that lets you pick a job on seek.com, then scape key words and come up with a \n", |
| 13 | + "# plan on how to land jobs of the type selected." |
| 14 | + ] |
| 15 | + }, |
| 16 | + { |
| 17 | + "cell_type": "markdown", |
| 18 | + "id": "312c3746", |
| 19 | + "metadata": {}, |
| 20 | + "source": [ |
| 21 | + "# My project" |
| 22 | + ] |
| 23 | + }, |
| 24 | + { |
| 25 | + "cell_type": "code", |
| 26 | + "execution_count": null, |
| 27 | + "id": "394dbcfc", |
| 28 | + "metadata": {}, |
| 29 | + "outputs": [], |
| 30 | + "source": [ |
| 31 | + "#pip install markdown" |
| 32 | + ] |
| 33 | + }, |
| 34 | + { |
| 35 | + "cell_type": "code", |
| 36 | + "execution_count": null, |
| 37 | + "id": "15f1024d", |
| 38 | + "metadata": {}, |
| 39 | + "outputs": [], |
| 40 | + "source": [ |
| 41 | + "\n", |
| 42 | + "import os\n", |
| 43 | + "import requests\n", |
| 44 | + "import json\n", |
| 45 | + "from typing import List\n", |
| 46 | + "from dotenv import load_dotenv\n", |
| 47 | + "from bs4 import BeautifulSoup\n", |
| 48 | + "from IPython.display import Markdown, display, update_display\n", |
| 49 | + "import gradio as gr\n", |
| 50 | + "import markdown\n", |
| 51 | + "\n", |
| 52 | + "# ---- 1\n", |
| 53 | + "# Initialize and constants & set up Gemini Flash LLM\n", |
| 54 | + "load_dotenv()\n", |
| 55 | + "api_key = os.getenv('GOOGLE_API_KEY')\n", |
| 56 | + "import os\n", |
| 57 | + "import google.generativeai as genai\n", |
| 58 | + "genai.configure(api_key= api_key)\n", |
| 59 | + "# Create the model\n", |
| 60 | + "generation_config = {\n", |
| 61 | + " \"temperature\": 1,\n", |
| 62 | + " \"top_p\": 0.95,\n", |
| 63 | + " \"top_k\": 40,\n", |
| 64 | + " \"max_output_tokens\": 8192,\n", |
| 65 | + " \"response_mime_type\": \"text/plain\",}\n", |
| 66 | + "model = genai.GenerativeModel(model_name=\"gemini-1.5-flash\",\n", |
| 67 | + " generation_config=generation_config,)\n", |
| 68 | + "chat_session = model.start_chat(history=[ ])\n", |
| 69 | + "\n", |
| 70 | + "\n", |
| 71 | + "# ---- 2\n", |
| 72 | + "# A class to represent a Webpage\n", |
| 73 | + "# Some websites need you to use proper headers when fetching them:\n", |
| 74 | + "headers = {\n", |
| 75 | + " \"User-Agent\": \"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36\"\n", |
| 76 | + "}\n", |
| 77 | + "\n", |
| 78 | + "class Website:\n", |
| 79 | + " \"\"\"\n", |
| 80 | + " A utility class to represent a Website that we have scraped, now with links\n", |
| 81 | + " \"\"\"\n", |
| 82 | + "\n", |
| 83 | + " def __init__(self, url):\n", |
| 84 | + " self.url = url\n", |
| 85 | + " response = requests.get(url, headers=headers)\n", |
| 86 | + " self.body = response.content\n", |
| 87 | + " soup = BeautifulSoup(self.body, 'html.parser')\n", |
| 88 | + " self.title = soup.title.string if soup.title else \"No title found\"\n", |
| 89 | + " if soup.body:\n", |
| 90 | + " for irrelevant in soup.body([\"script\", \"style\", \"img\", \"input\"]):\n", |
| 91 | + " irrelevant.decompose()\n", |
| 92 | + " self.text = soup.body.get_text(separator=\"\\n\", strip=True)\n", |
| 93 | + " else:\n", |
| 94 | + " self.text = \"\"\n", |
| 95 | + " links = [link.get('href') for link in soup.find_all('a')]\n", |
| 96 | + " self.links = [link for link in links if link]\n", |
| 97 | + "\n", |
| 98 | + " def get_contents(self):\n", |
| 99 | + " return f\"Webpage Title:\\n{self.title}\\nWebpage Contents:\\n{self.text}\\n\\n\"\n", |
| 100 | + "\n", |
| 101 | + "\n", |
| 102 | + "# ---- 3\n", |
| 103 | + "# Data + set up\n", |
| 104 | + "def get_all_details(url):\n", |
| 105 | + " result = \"Landing page:\\n\"\n", |
| 106 | + " result += Website(url).get_contents()\n", |
| 107 | + " return result\n", |
| 108 | + "\n", |
| 109 | + "system_prompt = \"You are an experience recrutiment and talent management assistant, who will be provided a list of roles on offer.\\\n", |
| 110 | + "You will display those roles along with a high level summary of the key steps you suggest to land those roles. \\\n", |
| 111 | + "Output is to be in markdown (i.e. a professional format, with bold headders, proper spacing between different sections, etc.)\\\n", |
| 112 | + "Include suggested next steps on how to successfully apply for and land each of these jobs.\"\n", |
| 113 | + "\n", |
| 114 | + "def get_brochure_user_prompt(url):\n", |
| 115 | + " user_prompt = f\"Here are the contents of your recruitment search. Please list out individual roles and your best advise on landing those roles.\"\n", |
| 116 | + " user_prompt += f\"Please provide output in a professional style with bold text for headings, content nicely layed out under headings, different content split out into sections, etc.)\\n\"\n", |
| 117 | + " user_prompt += get_all_details(url)\n", |
| 118 | + " #user_prompt = user_prompt[:5_000] # Truncate if more than 5,000 characters\n", |
| 119 | + " user_prompt = user_prompt[:7_500] # Truncate if more than 5,000 characters\n", |
| 120 | + " return user_prompt\n", |
| 121 | + "\n", |
| 122 | + "def create_brochure(url):\n", |
| 123 | + " response = chat_session.send_message(system_prompt + get_brochure_user_prompt(url))\n", |
| 124 | + " result = response.text\n", |
| 125 | + " html_output = markdown.markdown(result)\n", |
| 126 | + " return html_output\n", |
| 127 | + "\n", |
| 128 | + "# ---- 4 \n", |
| 129 | + "# Gradio UI\n", |
| 130 | + "with gr.Blocks(css=\"\"\"\n", |
| 131 | + " #header-container { text-align: left; position: fixed; top: 10px; left: 0; padding: 10px; background-color: #f0f0f0; }\n", |
| 132 | + " #input-container { text-align: left; position: fixed; top: 100px; left: 0; right: 0; background: white; z-index: 100; padding: 8px; line-height: 0.5;}\n", |
| 133 | + " #output-container { margin-top: 160px; height: calc(100vh - 280px); overflow-y: auto; }\n", |
| 134 | + " #output-html { white-space: pre-wrap; font-family: monospace; border: 1px solid #ccc; padding: 5px; line-height: 1.2;}\n", |
| 135 | + " .button-container { margin-top: 10px; } /* Space above the button */\n", |
| 136 | + " .output-label { margin-top: 10px; font-weight: bold; } /* Style for output label */\n", |
| 137 | + "\"\"\") as iface:\n", |
| 138 | + " with gr.Column(elem_id=\"main-container\"):\n", |
| 139 | + " # Add header and description\n", |
| 140 | + " with gr.Row(elem_id=\"header-container\"):\n", |
| 141 | + " gr.Markdown(\"# Job seeker guide\")\n", |
| 142 | + " gr.Markdown(\"1.0 Works best with recruitment site https://www.seek.com.au/ (but can try others).\")\n", |
| 143 | + " gr.Markdown(\"2.0 Search for jobs of your choice, copy URL from that search & paste in input field below to get helpful advice on how to land those roles.\")\n", |
| 144 | + "\n", |
| 145 | + "\n", |
| 146 | + " \n", |
| 147 | + " with gr.Row(elem_id=\"input-container\"):\n", |
| 148 | + " input_text = gr.Textbox(label=\"Input\", elem_id=\"input-box\")\n", |
| 149 | + " \n", |
| 150 | + " with gr.Column(elem_id=\"output-container\"):\n", |
| 151 | + " output_label = gr.Markdown(\"<div class='output-label'>Output:</div>\")\n", |
| 152 | + " output_text = gr.HTML(elem_id=\"output-html\")\n", |
| 153 | + " \n", |
| 154 | + " # Move the button below the output box\n", |
| 155 | + " submit_btn = gr.Button(\"Generate\", elem_id=\"generate-button\", elem_classes=\"button-container\")\n", |
| 156 | + " \n", |
| 157 | + " submit_btn.click(fn=create_brochure, inputs=input_text, outputs=output_text)\n", |
| 158 | + "\n", |
| 159 | + "iface.launch(share=True)\n", |
| 160 | + "\n" |
| 161 | + ] |
| 162 | + }, |
| 163 | + { |
| 164 | + "cell_type": "code", |
| 165 | + "execution_count": null, |
| 166 | + "id": "21c4b557", |
| 167 | + "metadata": {}, |
| 168 | + "outputs": [], |
| 169 | + "source": [] |
| 170 | + } |
| 171 | + ], |
| 172 | + "metadata": { |
| 173 | + "kernelspec": { |
| 174 | + "display_name": ".venv", |
| 175 | + "language": "python", |
| 176 | + "name": "python3" |
| 177 | + }, |
| 178 | + "language_info": { |
| 179 | + "codemirror_mode": { |
| 180 | + "name": "ipython", |
| 181 | + "version": 3 |
| 182 | + }, |
| 183 | + "file_extension": ".py", |
| 184 | + "mimetype": "text/x-python", |
| 185 | + "name": "python", |
| 186 | + "nbconvert_exporter": "python", |
| 187 | + "pygments_lexer": "ipython3", |
| 188 | + "version": "3.12.8" |
| 189 | + } |
| 190 | + }, |
| 191 | + "nbformat": 4, |
| 192 | + "nbformat_minor": 5 |
| 193 | +} |
0 commit comments