diff --git a/README.md b/README.md index c9e8c22..49b32ad 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ Install with `pip install obj2html` and use with `obj2html('model.obj', 'index.h ![](imgs/colab_sample.png) -* run into jupyter notebook +* run into [jupyter notebook](https://jupyter.org/) ([jupyter_example.ipynb](examples/jupyter_example.ipynb)): ``` ! pip install obj2html ! wget https://gitlab.com/nicolalandro/obj2html/-/raw/main/test/assets/model.obj @@ -24,6 +24,22 @@ obj2html('model.obj', 'index.html') display(HTML('index.html')) ``` +* run into [streamlit](https://streamlit.io/) app ([streamlit_example.py](examples/streamlit_example.py)): +``` +# pip install obj2html streamlit +# have a model.obj (wget https://gitlab.com/nicolalandro/obj2html/-/raw/main/test/assets/model.obj) + +import streamlit as st +import streamlit.components.v1 as components +from obj2html import obj2html + +html_string = obj2html("model.obj", html_elements_only=True) +components.html(html_string) +with open("model.obj") as f: + st.download_button('Download model.obj', f, file_name="download_name.obj") +``` +![](imgs/streamlit_example.png) + ## Features @@ -33,7 +49,7 @@ display(HTML('index.html')) - [x] pypi doc add image - [x] edit html positions and other 3D params - [x] add param for streamlit -- [ ] document param for streamlit +- [x] document param for streamlit - [ ] dist wheel - [ ] load three.js as static file - [ ] .mat files support diff --git a/examples/jupyter_example.ipynb b/examples/jupyter_example.ipynb new file mode 100644 index 0000000..e11c535 --- /dev/null +++ b/examples/jupyter_example.ipynb @@ -0,0 +1,189 @@ +{ + "nbformat": 4, + "nbformat_minor": 0, + "metadata": { + "colab": { + "name": "Demo_obj2html.ipynb", + "provenance": [], + "collapsed_sections": [] + }, + "kernelspec": { + "display_name": "Python 3", + "name": "python3" + }, + "language_info": { + "name": "python" + } + }, + "cells": [ + { + "cell_type": "code", + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "yhAY5KFy1gi2", + "outputId": "248d496f-421e-4b92-dc90-8e91cee03c01" + }, + "source": [ + "! pip install obj2html\n", + "! wget https://gitlab.com/nicolalandro/obj2html/-/raw/main/test/assets/model.obj" + ], + "execution_count": null, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Collecting obj2html==0.12\n", + " Downloading obj2html-0.12.tar.gz (3.4 kB)\n", + "Building wheels for collected packages: obj2html\n", + " Building wheel for obj2html (setup.py) ... \u001b[?25l\u001b[?25hdone\n", + " Created wheel for obj2html: filename=obj2html-0.12-py3-none-any.whl size=3801 sha256=b5b7db9f171c91da798ee6ddc805451863ecd34f39221935bdb68d7cab6ae352\n", + " Stored in directory: /root/.cache/pip/wheels/8d/2e/a7/c7a4aa0a197f80a9cabb39e4da48905cf09b0f26244afb2841\n", + "Successfully built obj2html\n", + "Installing collected packages: obj2html\n", + " Attempting uninstall: obj2html\n", + " Found existing installation: obj2html 0.11\n", + " Uninstalling obj2html-0.11:\n", + " Successfully uninstalled obj2html-0.11\n", + "Successfully installed obj2html-0.12\n", + "--2021-11-14 16:05:58-- https://gitlab.com/nicolalandro/obj2html/-/raw/main/test/assets/model.obj\n", + "Resolving gitlab.com (gitlab.com)... 172.65.251.78, 2606:4700:90:0:f22e:fbec:5bed:a9b9\n", + "Connecting to gitlab.com (gitlab.com)|172.65.251.78|:443... connected.\n", + "HTTP request sent, awaiting response... 200 OK\n", + "Length: 9887179 (9.4M) [text/plain]\n", + "Saving to: ‘model.obj.4’\n", + "\n", + "model.obj.4 100%[===================>] 9.43M --.-KB/s in 0.06s \n", + "\n", + "2021-11-14 16:05:58 (157 MB/s) - ‘model.obj.4’ saved [9887179/9887179]\n", + "\n" + ] + } + ] + }, + { + "cell_type": "code", + "metadata": { + "colab": { + "background_save": true, + "base_uri": "https://localhost:8080/", + "height": 171 + }, + "id": "jeTD6bmh2MX6", + "outputId": "945bcf90-70e3-407b-ad54-79aae1246120" + }, + "source": [ + "from obj2html import obj2html\n", + "from IPython.display import display, HTML\n", + "obj2html('model.obj', 'index.html')\n", + "display(HTML('index.html'))" + ], + "execution_count": null, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + "\n", + " \n", + " \n", + " \n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + "" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ] + } + ] +} \ No newline at end of file diff --git a/examples/stramlit_example.py b/examples/stramlit_example.py new file mode 100644 index 0000000..514bac8 --- /dev/null +++ b/examples/stramlit_example.py @@ -0,0 +1,10 @@ +import streamlit as st +import streamlit.components.v1 as components +from obj2html import obj2html + +# run in the root folder, not inside exaples, to have the relative path working +obj_path = "test/assets/model.obj" +html_string = obj2html(obj_path, html_elements_only=True) +components.html(html_string) +with open(obj_path) as f: + st.download_button('Download model.obj', f, file_name="model.obj") diff --git a/imgs/streamlit_example.png b/imgs/streamlit_example.png new file mode 100644 index 0000000..591ef40 Binary files /dev/null and b/imgs/streamlit_example.png differ