Spaces:
Sleeping
Sleeping
Commit
·
1c89c80
1
Parent(s):
19442e1
add files
Browse files- Dockerfile +16 -0
- app.ipynb +111 -0
- requirements.txt +1 -0
Dockerfile
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM python:3.9
|
| 2 |
+
|
| 3 |
+
WORKDIR /code
|
| 4 |
+
|
| 5 |
+
COPY ./requirements.txt /code/requirements.txt
|
| 6 |
+
RUN python3 -m pip install --no-cache-dir --upgrade pip
|
| 7 |
+
RUN python3 -m pip install --no-cache-dir --upgrade -r /code/requirements.txt
|
| 8 |
+
|
| 9 |
+
COPY . .
|
| 10 |
+
|
| 11 |
+
CMD ["panel", "serve", "/code/app.ipynb", "--address", "0.0.0.0", "--port", "7860", "--allow-websocket-origin", "0.0.0.0:7860"]
|
| 12 |
+
|
| 13 |
+
RUN mkdir /.cache
|
| 14 |
+
RUN chmod 777 /.cache
|
| 15 |
+
RUN mkdir .chroma
|
| 16 |
+
RUN chmod 777 .chroma
|
app.ipynb
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"cells": [
|
| 3 |
+
{
|
| 4 |
+
"cell_type": "code",
|
| 5 |
+
"execution_count": null,
|
| 6 |
+
"id": "8cd1e865-53d5-460b-8bae-5658e3aa3d16",
|
| 7 |
+
"metadata": {},
|
| 8 |
+
"outputs": [],
|
| 9 |
+
"source": [
|
| 10 |
+
"import panel as pn\n",
|
| 11 |
+
"pn.extension()\n",
|
| 12 |
+
"import requests\n",
|
| 13 |
+
"import random\n",
|
| 14 |
+
"from PIL import Image"
|
| 15 |
+
]
|
| 16 |
+
},
|
| 17 |
+
{
|
| 18 |
+
"cell_type": "code",
|
| 19 |
+
"execution_count": null,
|
| 20 |
+
"id": "ca65cc07-8181-4259-8770-9c780621eb78",
|
| 21 |
+
"metadata": {},
|
| 22 |
+
"outputs": [],
|
| 23 |
+
"source": [
|
| 24 |
+
"# Button widget\n",
|
| 25 |
+
"run_button = pn.widgets.Button(name=\"Click to get a new image\")"
|
| 26 |
+
]
|
| 27 |
+
},
|
| 28 |
+
{
|
| 29 |
+
"cell_type": "code",
|
| 30 |
+
"execution_count": null,
|
| 31 |
+
"id": "8480d2c2-06c0-441e-9cf9-f858f2db1ec9",
|
| 32 |
+
"metadata": {},
|
| 33 |
+
"outputs": [],
|
| 34 |
+
"source": [
|
| 35 |
+
"def get_image(_):\n",
|
| 36 |
+
" \"\"\"\n",
|
| 37 |
+
" a function to generate random cat images\n",
|
| 38 |
+
" \"\"\"\n",
|
| 39 |
+
" api_url = 'https://api.thecatapi.com/v1/images/search'\n",
|
| 40 |
+
" img_url = requests.get(api_url, stream=True).json()[0]['url']\n",
|
| 41 |
+
" image = Image.open(requests.get(img_url, stream=True).raw)\n",
|
| 42 |
+
" return pn.pane.Image(image, sizing_mode='scale_width')"
|
| 43 |
+
]
|
| 44 |
+
},
|
| 45 |
+
{
|
| 46 |
+
"cell_type": "code",
|
| 47 |
+
"execution_count": null,
|
| 48 |
+
"id": "6fd5a63f-012a-419c-8386-22b5b8ff243f",
|
| 49 |
+
"metadata": {},
|
| 50 |
+
"outputs": [],
|
| 51 |
+
"source": [
|
| 52 |
+
"# Bind the get_image function with the button widget\n",
|
| 53 |
+
"interactive = pn.bind(get_image, run_button)"
|
| 54 |
+
]
|
| 55 |
+
},
|
| 56 |
+
{
|
| 57 |
+
"cell_type": "code",
|
| 58 |
+
"execution_count": null,
|
| 59 |
+
"id": "6e829400-320f-437c-8465-ed392afe3aa9",
|
| 60 |
+
"metadata": {},
|
| 61 |
+
"outputs": [],
|
| 62 |
+
"source": [
|
| 63 |
+
"desc = pn.pane.Markdown(\"\"\"\n",
|
| 64 |
+
"# Hi there!\n",
|
| 65 |
+
"Thanks for trying out the Panel template. This is a super simple demo that combines a function with a widget. \n",
|
| 66 |
+
"Click the button below to generate a new cat image and check out https://panel.holoviz.org/\n",
|
| 67 |
+
"to learn more.\n",
|
| 68 |
+
"\"\"\")\n"
|
| 69 |
+
]
|
| 70 |
+
},
|
| 71 |
+
{
|
| 72 |
+
"cell_type": "code",
|
| 73 |
+
"execution_count": null,
|
| 74 |
+
"id": "84bfdf52-b6e0-400d-baaf-d16303a72b65",
|
| 75 |
+
"metadata": {},
|
| 76 |
+
"outputs": [],
|
| 77 |
+
"source": [
|
| 78 |
+
"# Layout using Template\n",
|
| 79 |
+
"template = pn.template.FastListTemplate(\n",
|
| 80 |
+
" title='Generate random cat images', \n",
|
| 81 |
+
" sidebar=[desc, run_button],\n",
|
| 82 |
+
" main=[interactive],\n",
|
| 83 |
+
" accent_base_color=\"#88d8b0\",\n",
|
| 84 |
+
" header_background=\"#88d8b0\",\n",
|
| 85 |
+
")\n",
|
| 86 |
+
"template.servable()"
|
| 87 |
+
]
|
| 88 |
+
}
|
| 89 |
+
],
|
| 90 |
+
"metadata": {
|
| 91 |
+
"kernelspec": {
|
| 92 |
+
"display_name": "Python 3 (ipykernel)",
|
| 93 |
+
"language": "python",
|
| 94 |
+
"name": "python3"
|
| 95 |
+
},
|
| 96 |
+
"language_info": {
|
| 97 |
+
"codemirror_mode": {
|
| 98 |
+
"name": "ipython",
|
| 99 |
+
"version": 3
|
| 100 |
+
},
|
| 101 |
+
"file_extension": ".py",
|
| 102 |
+
"mimetype": "text/x-python",
|
| 103 |
+
"name": "python",
|
| 104 |
+
"nbconvert_exporter": "python",
|
| 105 |
+
"pygments_lexer": "ipython3",
|
| 106 |
+
"version": "3.10.11"
|
| 107 |
+
}
|
| 108 |
+
},
|
| 109 |
+
"nbformat": 4,
|
| 110 |
+
"nbformat_minor": 5
|
| 111 |
+
}
|
requirements.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
panel
|