Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a notebook test script. #187

Open
wants to merge 23 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix opossum search
  • Loading branch information
MarkDaoust committed May 30, 2024
commit ff1862d55d8ac8f542348c82734e45268c02018f
192 changes: 146 additions & 46 deletions examples/Opossum_search.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 1,
"metadata": {
"cellView": "form",
"id": "tuOe1ymfHZPu"
Expand Down Expand Up @@ -68,18 +68,27 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": 2,
"metadata": {
"id": "UyZKDjRs-FN5"
},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[33mWARNING: There was an error checking the latest version of pip.\u001b[0m\u001b[33m\n",
"\u001b[0m"
]
}
],
"source": [
"!pip install -q -U google-generativeai"
]
},
{
"cell_type": "code",
"execution_count": 12,
"execution_count": 3,
"metadata": {
"id": "F0DZNupF-Lfj"
},
Expand All @@ -101,11 +110,23 @@
},
{
"cell_type": "code",
"execution_count": 13,
"execution_count": 4,
"metadata": {
"id": "IciW45ex-Lo9"
},
"outputs": [],
"outputs": [
{
"ename": "ModuleNotFoundError",
"evalue": "No module named 'google.colab'",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mModuleNotFoundError\u001b[0m Traceback (most recent call last)",
"Cell \u001b[0;32mIn[4], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mgoogle\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mcolab\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m userdata\n\u001b[1;32m 2\u001b[0m GOOGLE_API_KEY\u001b[38;5;241m=\u001b[39muserdata\u001b[38;5;241m.\u001b[39mget(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mGOOGLE_API_KEY\u001b[39m\u001b[38;5;124m'\u001b[39m)\n\u001b[1;32m 3\u001b[0m genai\u001b[38;5;241m.\u001b[39mconfigure(api_key\u001b[38;5;241m=\u001b[39mGOOGLE_API_KEY)\n",
"\u001b[0;31mModuleNotFoundError\u001b[0m: No module named 'google.colab'"
]
}
],
"source": [
"from google.colab import userdata\n",
"GOOGLE_API_KEY=userdata.get('GOOGLE_API_KEY')\n",
Expand All @@ -123,7 +144,7 @@
},
{
"cell_type": "code",
"execution_count": 14,
"execution_count": 5,
"metadata": {
"id": "mxYn5lUAfsUC"
},
Expand All @@ -137,7 +158,7 @@
},
{
"cell_type": "code",
"execution_count": 15,
"execution_count": 6,
"metadata": {
"id": "igrg_SxPfwQ6"
},
Expand All @@ -156,7 +177,7 @@
},
{
"cell_type": "code",
"execution_count": 16,
"execution_count": 7,
"metadata": {
"id": "-qpqkgTurqYI"
},
Expand All @@ -165,7 +186,6 @@
"name": "stdout",
"output_type": "stream",
"text": [
"```html\n",
"<!DOCTYPE html>\n",
"<html lang=\"en\">\n",
"<head>\n",
Expand All @@ -174,69 +194,67 @@
" <title>Opossum Search</title>\n",
" <style>\n",
" body {\n",
" font-family: Arial, sans-serif;\n",
" margin: 0;\n",
" padding: 0;\n",
" font-family: Arial, sans-serif;\n",
" }\n",
" header {\n",
"\n",
" .container {\n",
" display: flex;\n",
" justify-content: center;\n",
" flex-direction: column;\n",
" align-items: center;\n",
" padding: 20px;\n",
" justify-content: center;\n",
" height: 100vh;\n",
" }\n",
" header img {\n",
"\n",
" img {\n",
" width: 272px;\n",
" height: auto;\n",
" }\n",
"\n",
" form {\n",
" display: flex;\n",
" justify-content: center;\n",
" margin-top: 30px;\n",
" margin-top: 20px;\n",
" }\n",
"\n",
" input[type=\"text\"] {\n",
" padding: 10px;\n",
" font-size: 16px;\n",
" border: 1px solid #ccc;\n",
" width: 500px;\n",
" border-radius: 5px 0 0 5px;\n",
" width: 400px;\n",
" }\n",
" input[type=\"submit\"] {\n",
" padding: 10px 20px;\n",
"\n",
" button[type=\"submit\"] {\n",
" padding: 10px 15px;\n",
" font-size: 16px;\n",
" background-color: #f8f9fa;\n",
" border: 1px solid #ccc;\n",
" border-radius: 0 5px 5px 0;\n",
" cursor: pointer;\n",
" }\n",
"\n",
" footer {\n",
" position: fixed;\n",
" bottom: 0;\n",
" width: 100%;\n",
" position: absolute;\n",
" bottom: 10px;\n",
" left: 0;\n",
" right: 0;\n",
" text-align: center;\n",
" padding: 10px;\n",
" background-color: #f8f9fa;\n",
" font-size: 12px;\n",
" color: #6c757d;\n",
" }\n",
" </style>\n",
"</head>\n",
"<body>\n",
" <header>\n",
" <img src=\"https://upload.wikimedia.org/wikipedia/commons/thumb/2/27/Opossum_2.jpg/292px-Opossum_2.jpg\" alt=\"Opossum Logo\">\n",
" </header>\n",
" <form action=\"https://www.google.com/search\" method=\"get\">\n",
" <input type=\"text\" name=\"q\" placeholder=\"Search with Opossum...\">\n",
" <input type=\"submit\" value=\"Search\">\n",
" </form>\n",
" <div class=\"container\">\n",
" <img src=\"https://upload.wikimedia.org/wikipedia/commons/thumb/2/27/Opossum_2.jpg/292px-Opossum_2.jpg\" alt=\"Opossum\">\n",
" <form method=\"GET\" action=\"https://www.google.com/search\">\n",
" <input type=\"text\" name=\"q\" placeholder=\"Search the web with Opossum\">\n",
" <button type=\"submit\">Search</button>\n",
" </form>\n",
" </div>\n",
" <footer>Powered by opossum search</footer>\n",
" <script>\n",
" const form = document.querySelector('form');\n",
" form.addEventListener('submit', function(event) {\n",
" event.preventDefault();\n",
" const query = document.querySelector('input[name=\"q\"]').value;\n",
" const newURL = `https://www.google.com/search?q=opossum ${query}`;\n",
" window.location.href = newURL;\n",
" });\n",
" </script>\n",
"</body>\n",
"</html>\n",
"``` \n",
"\n"
]
}
Expand Down Expand Up @@ -275,14 +293,96 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 11,
"metadata": {
"id": "M6FS75_bi5kP"
},
"outputs": [],
"outputs": [
{
"data": {
"text/html": [
"<!DOCTYPE html>\n",
"<html lang=\"en\">\n",
"<head>\n",
" <meta charset=\"UTF-8\">\n",
" <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n",
" <title>Opossum Search</title>\n",
" <style>\n",
" body {\n",
" margin: 0;\n",
" padding: 0;\n",
" font-family: Arial, sans-serif;\n",
" }\n",
"\n",
" .container {\n",
" display: flex;\n",
" flex-direction: column;\n",
" align-items: center;\n",
" justify-content: center;\n",
" height: 100vh;\n",
" }\n",
"\n",
" img {\n",
" width: 272px;\n",
" }\n",
"\n",
" form {\n",
" display: flex;\n",
" margin-top: 20px;\n",
" }\n",
"\n",
" input[type=\"text\"] {\n",
" padding: 10px;\n",
" font-size: 16px;\n",
" border: 1px solid #ccc;\n",
" border-radius: 5px 0 0 5px;\n",
" width: 400px;\n",
" }\n",
"\n",
" button[type=\"submit\"] {\n",
" padding: 10px 15px;\n",
" font-size: 16px;\n",
" background-color: #f8f9fa;\n",
" border: 1px solid #ccc;\n",
" border-radius: 0 5px 5px 0;\n",
" cursor: pointer;\n",
" }\n",
"\n",
" footer {\n",
" position: absolute;\n",
" bottom: 10px;\n",
" left: 0;\n",
" right: 0;\n",
" text-align: center;\n",
" font-size: 12px;\n",
" color: #6c757d;\n",
" }\n",
" </style>\n",
"</head>\n",
"<body>\n",
" <div class=\"container\">\n",
" <img src=\"https://upload.wikimedia.org/wikipedia/commons/thumb/2/27/Opossum_2.jpg/292px-Opossum_2.jpg\" alt=\"Opossum\">\n",
" <form method=\"GET\" action=\"https://www.google.com/search\">\n",
" <input type=\"text\" name=\"q\" placeholder=\"Search the web with Opossum\">\n",
" <button type=\"submit\">Search</button>\n",
" </form>\n",
" </div>\n",
" <footer>Powered by opossum search</footer>\n",
"</body>\n",
"</html>\n"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import IPython\n",
"code = response.text.split('```')[1][len('html'):]\n",
"code = response.text.removeprefix('```html').strip('`')\n",
"IPython.display.HTML(code)"
]
}
Expand Down