Skip to content

Commit

Permalink
Merge pull request #5 from codejoey/joey-mercury-app
Browse files Browse the repository at this point in the history
Joey mercury app return to heroku deployment
  • Loading branch information
codejoey authored Feb 23, 2024
2 parents 6ef1abd + d0b75e3 commit 1f96955
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 119 deletions.
1 change: 1 addition & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web: mercury run 0.0.0.0:$PORT
6 changes: 0 additions & 6 deletions app.py

This file was deleted.

Binary file modified celery.sqlite
Binary file not shown.
Binary file modified celerybeat-schedule.db
Binary file not shown.
167 changes: 57 additions & 110 deletions chunky-web-app.ipynb
Original file line number Diff line number Diff line change
@@ -1,141 +1,88 @@
{
"cells": [
{
"cell_type": "raw",
"metadata": {},
"source": [
"---\n",
"title: Chunky 🍫\n",
"description: Chunk Better \n",
"show-code: False\n",
"\n",
"params:\n",
" input_filename:\n",
" label: Upload a lesson plan, novel, article, wiki page, and more! (.txt <50MB)\n",
" input: file\n",
" maxFileSize: 50MB\n",
" user_query:\n",
" input: text\n",
" label: What's your query?\n",
" value: How do you setup a vector database?\n",
" output_dir:\n",
" output: dir\n",
" ---"
]
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"application/mercury+json": {
"allow_download": true,
"code_uid": "App.0.40.25.4-rand96b990fd",
"continuous_update": true,
"description": "Optimising chunking for RAG",
"full_screen": true,
"model_id": "mercury-app",
"notify": "{}",
"output": "app",
"schedule": "",
"show_code": false,
"show_prompt": false,
"show_sidebar": true,
"static_notebook": false,
"stop_on_error": false,
"title": "Chunky 🍫",
"widget": "App"
},
"text/html": [
"<h3>Mercury Application</h3><small>This output won't appear in the web app.</small>"
],
"text/plain": [
"mercury.App"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"outputs": [],
"source": [
"#name these var to match widget names above^, these var will update in webapp when run from user input\n",
"input_filename = 'lesson_plan.txt'\n",
"\"\"\"\n",
"The uploaded file name will be passed to the notebook as a string. \n",
"The uploaded file will be copied to the same directory as the notebook. \n",
"After notebook execution, the uploaded file will be removed.\n",
"\"\"\"\n",
"user_query = \"How do you setup a vector database?\"\n",
"output_dir = \"\"\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import mercury as mr\n",
" \n",
"# set Application parameters\n",
"app = mr.App(title=\"Chunky 🍫\",\n",
" description=\"Optimising chunking for RAG\",\n",
" show_code=False,\n",
" show_prompt=False,\n",
" continuous_update=True,\n",
" static_notebook=False,\n",
" show_sidebar=True,\n",
" full_screen=True,\n",
" allow_download=True,\n",
" stop_on_error=False\n",
")"
"#ADD DEPENDENCIES HERE and BELOW (not above)\n"
]
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 6,
"metadata": {},
"outputs": [
{
"data": {
"application/mercury+json": {
"code_uid": "File.0.40.18.4-randfb24b47f",
"disabled": false,
"hidden": false,
"label": "File upload (max 100mb)",
"max_file_size": "100MB",
"model_id": "a0f5d7fa224c463f84c8778508646363",
"widget": "File"
},
"application/vnd.jupyter.widget-view+json": {
"model_id": "a0f5d7fa224c463f84c8778508646363",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"mercury.File"
"'\\nThe uploaded file name will be passed to the notebook as a string. \\nThe uploaded file will be copied to the same directory as the notebook. \\nAfter notebook execution, the uploaded file will be removed.\\n'"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Let's read content of None\n"
]
},
{
"ename": "TypeError",
"evalue": "expected str, bytes or os.PathLike object, not NoneType",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m/var/folders/sr/9jd6ghy14vg_nrkkggx10lk80000gq/T/ipykernel_48186/3996636579.py\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[1;32m 6\u001b[0m \u001b[0;31m# get file path in the code and read its content\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 7\u001b[0m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34mf\"Let's read content of {my_file.filepath}\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 8\u001b[0;31m \u001b[0;32mwith\u001b[0m \u001b[0mopen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mmy_file\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mfilepath\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m\"r\"\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0mfin\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 9\u001b[0m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mfin\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mread\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 10\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;31mTypeError\u001b[0m: expected str, bytes or os.PathLike object, not NoneType"
]
"output_type": "execute_result"
}
],
"source": [
"#input widgets\n",
"\n",
"# add file upload widget\n",
"my_file = mr.File(label=\"File upload (max 100mb)\", max_file_size=\"100MB\")\n",
" \n",
"# get file path in the code and read its content\n",
"print(f\"Let's read content of {my_file.filepath}\")\n",
"with open(my_file.filepath, \"r\") as fin:\n",
" print(fin.read())\n",
" \n",
"# get file name\n",
"print(f\"Thanks for uploading {my_file.filename}\")\n",
" \n",
"# get file content in binary format\n",
"binary_content = my_file.value"
"# note there are two user inputs\n",
"#! input_filename\n",
"#! user_query\n",
"\"\"\"\n",
"Both are strings. Access the file locally.\n",
"The uploaded file name will be passed to the notebook as a string. \n",
"The uploaded file will be copied to the same directory as the notebook. \n",
"After notebook execution, the uploaded file will be removed.\n",
"\"\"\""
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# add text widget\n",
"user_query = mr.Text(value=\"Piotr\", label=\"Input user query\", rows=1)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"print(f\"User query is {user_query.value}!\")"
]
"source": []
}
],
"metadata": {
Expand Down
6 changes: 3 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ distro==1.9.0
dnspython==2.6.1
exceptiongroup==1.2.0
frozenlist==1.4.1
greenlet==3.0.3
greenlet==1.1.0
h11==0.14.0
httpcore==1.0.4
httpx==0.27.0
Expand Down Expand Up @@ -45,8 +45,8 @@ typing-inspect==0.9.0
typing_extensions==4.9.0
urllib3==2.2.1
yarl==1.9.4
mercury>=2.2.6
mljar-mercury==1.1.6
pypdf==4.0.2
langchain==0.1.8
langchain-community==0.0.21
nltk==3.8.1
nltk==3.8.1
1 change: 1 addition & 0 deletions runtime.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
python-3.9.18

0 comments on commit 1f96955

Please sign in to comment.