Spaces:
Runtime error
Runtime error
File size: 6,594 Bytes
bde8b55 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 |
{
"cells": [
{
"cell_type": "code",
"execution_count": 91,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"https://ollama.com/library\n"
]
}
],
"source": [
"from bs4 import BeautifulSoup\n",
"from requests import get\n",
"# download the HTML content\n",
"\n",
"base_url = 'https://ollama.com'\n",
"library_url = f'{base_url}/library'\n",
"print(library_url)\n",
"html_content = get(library_url).text\n",
"\n",
"\n",
"# Parse the HTML content with BeautifulSoup\n",
"soup = BeautifulSoup(html_content, 'html.parser')\n",
"\n",
"# Extract all the li elements within the ul\n",
"li_items = soup.select('ul[role=\"list\"] > li')\n",
"\n",
"models = []\n",
"\n",
"# Iterate over the extracted li elements and print them\n",
"for li in li_items:\n",
" # get first a tag text\n",
" sizes = li.div.div.select('span')\n",
" sizes = [size.text for size in sizes]\n",
"\n",
" pulls = li.div.select('p')[1].select('span')\n",
" # remove svg tags from pulls\n",
" pulls = [pull.text[:-1] for pull in pulls]\n",
" pulls = pulls[0].split('\\xa0')[0].strip()\n",
"\n",
" model = {\n",
" \"name\": li.h2.text.strip(),\n",
" \"description\": li.p.text.strip(),\n",
" \"url\": f\"{base_url}{li.a['href']}\",\n",
" \"params\": sizes,\n",
" \"pulls\": pulls \n",
" }\n",
" models.append(model)\n",
"import json\n",
"with open('models.json', 'w', encoding=\"utf-8\") as file:\n",
" file.write(json.dumps(models, indent=4, ensure_ascii=False))"
]
},
{
"cell_type": "code",
"execution_count": 97,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Model: llama3\n",
"Model: phi3\n",
"Model: wizardlm2\n",
"Model: mistral\n",
"Model: gemma\n",
"Model: mixtral\n",
"Model: llama2\n",
"Model: codegemma\n",
"Model: command-r\n",
"Model: command-r-plus\n",
"Model: llava\n",
"Model: dbrx\n",
"Model: codellama\n",
"Model: qwen\n",
"Model: dolphin-mixtral\n",
"Model: llama2-uncensored\n",
"Model: deepseek-coder\n",
"Model: mistral-openorca\n",
"Model: nomic-embed-text\n",
"Model: dolphin-mistral\n",
"Model: phi\n",
"Model: orca-mini\n",
"Model: nous-hermes2\n",
"Model: zephyr\n",
"Model: llama2-chinese\n",
"Model: wizard-vicuna-uncensored\n",
"Model: starcoder2\n",
"Model: vicuna\n",
"Model: tinyllama\n",
"Model: openhermes\n",
"Model: starcoder\n",
"Model: openchat\n",
"Model: dolphin-llama3\n",
"Model: yi\n",
"Model: tinydolphin\n",
"Model: wizardcoder\n",
"Model: stable-code\n",
"Model: mxbai-embed-large\n",
"Model: neural-chat\n",
"Model: phind-codellama\n",
"Model: wizard-math\n",
"Model: starling-lm\n",
"Model: falcon\n",
"Model: dolphincoder\n",
"Model: nous-hermes\n",
"Model: orca2\n",
"Model: sqlcoder\n",
"Model: stablelm2\n",
"Model: dolphin-phi\n",
"Model: solar\n",
"Model: yarn-llama2\n",
"Model: deepseek-llm\n",
"Model: codeqwen\n",
"Model: bakllava\n",
"Model: all-minilm\n",
"Model: samantha-mistral\n",
"Model: llama3-gradient\n",
"Model: medllama2\n",
"Model: wizardlm-uncensored\n",
"Model: xwinlm\n",
"Model: nous-hermes2-mixtral\n",
"Model: stable-beluga\n",
"Model: wizardlm\n",
"Model: codeup\n",
"Model: yarn-mistral\n",
"Model: everythinglm\n",
"Model: meditron\n",
"Model: llama-pro\n",
"Model: magicoder\n",
"Model: stablelm-zephyr\n",
"Model: nexusraven\n",
"Model: codebooga\n",
"Model: mistrallite\n",
"Model: llama3-chatqa\n",
"Model: wizard-vicuna\n",
"Model: snowflake-arctic-embed\n",
"Model: llava-llama3\n",
"Model: goliath\n",
"Model: open-orca-platypus2\n",
"Model: moondream\n",
"Model: duckdb-nsql\n",
"Model: notux\n",
"Model: megadolphin\n",
"Model: notus\n",
"Model: alfred\n",
"Model: llava-phi3\n",
"Model: falcon2\n"
]
}
],
"source": [
"for model in models:\n",
" tagsurl = f\"{model['url']}/tags\"\n",
" tags_page = get(tagsurl).text\n",
" # Parse the HTML content with BeautifulSoup\n",
" soup = BeautifulSoup(tags_page, 'html.parser')\n",
" # select links with the class group\n",
" tags = soup.select('a.group')\n",
" print(f\"Model: {model['name']}\")\n",
" model_tags = []\n",
" for tag in tags:\n",
" # get the parent div of the tag\n",
" parent = tag.parent\n",
" sizes = parent.parent.select('div.items-baseline')[0].text.strip().split(' • ',2)\n",
" # strip each size\n",
" sizes = [size.strip() for size in sizes]\n",
" model_tags.append({\n",
" \"name\": tag.text.strip(),\n",
" \"url\": f\"{base_url}{tag['href']}\",\n",
" \"size\": sizes[1],\n",
" \"hash\": sizes[0],\n",
" \"updated\": sizes[2],\n",
" })\n",
" link = tag['href']\n",
" #print(sizes,\"----\")\n",
" # get the next sibling of the parent div\n",
" sibling = parent.select('span')\n",
" if len(sibling) == 1:\n",
" hash = sibling[0].text.strip()\n",
" if len(sibling) == 3:\n",
" size = sibling[2].strip()\n",
" else:\n",
" pass\n",
" #print(sibling)\n",
" model[\"tags\"] = model_tags\n",
"with open('models.json', 'w', encoding=\"utf-8\") as file:\n",
" file.write(json.dumps(models, indent=4, ensure_ascii=False))"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "base",
"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.11.7"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
|