├── .env.example ├── .gitignore ├── LICENSE.md ├── README.md ├── app.py ├── gen.py └── requirements.txt /.env.example: -------------------------------------------------------------------------------- 1 | # rename this file to .env 2 | OPENAI_API_KEY=sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Project specific ignores 2 | site/ 3 | nohup.out 4 | 5 | # Byte-compiled / optimized / DLL files 6 | __pycache__/ 7 | *.py[cod] 8 | *$py.class 9 | 10 | # C extensions 11 | *.so 12 | 13 | # Distribution / packaging 14 | .Python 15 | build/ 16 | develop-eggs/ 17 | dist/ 18 | downloads/ 19 | eggs/ 20 | .eggs/ 21 | lib/ 22 | lib64/ 23 | parts/ 24 | sdist/ 25 | var/ 26 | wheels/ 27 | share/python-wheels/ 28 | *.egg-info/ 29 | .installed.cfg 30 | *.egg 31 | MANIFEST 32 | 33 | # PyInstaller 34 | # Usually these files are written by a python script from a template 35 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 36 | *.manifest 37 | *.spec 38 | 39 | # Installer logs 40 | pip-log.txt 41 | pip-delete-this-directory.txt 42 | 43 | # Unit test / coverage reports 44 | htmlcov/ 45 | .tox/ 46 | .nox/ 47 | .coverage 48 | .coverage.* 49 | .cache 50 | nosetests.xml 51 | coverage.xml 52 | *.cover 53 | *.py,cover 54 | .hypothesis/ 55 | .pytest_cache/ 56 | cover/ 57 | 58 | # Translations 59 | *.mo 60 | *.pot 61 | 62 | # Django stuff: 63 | *.log 64 | local_settings.py 65 | db.sqlite3 66 | db.sqlite3-journal 67 | 68 | # Flask stuff: 69 | instance/ 70 | .webassets-cache 71 | 72 | # Scrapy stuff: 73 | .scrapy 74 | 75 | # Sphinx documentation 76 | docs/_build/ 77 | 78 | # PyBuilder 79 | .pybuilder/ 80 | target/ 81 | 82 | # Jupyter Notebook 83 | .ipynb_checkpoints 84 | 85 | # IPython 86 | profile_default/ 87 | ipython_config.py 88 | 89 | # pyenv 90 | # For a library or package, you might want to ignore these files since the code is 91 | # intended to run in multiple environments; otherwise, check them in: 92 | # .python-version 93 | 94 | # pipenv 95 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 96 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 97 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 98 | # install all needed dependencies. 99 | #Pipfile.lock 100 | 101 | # poetry 102 | # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. 103 | # This is especially recommended for binary packages to ensure reproducibility, and is more 104 | # commonly ignored for libraries. 105 | # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control 106 | #poetry.lock 107 | 108 | # pdm 109 | # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. 110 | #pdm.lock 111 | # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it 112 | # in version control. 113 | # https://pdm.fming.dev/#use-with-ide 114 | .pdm.toml 115 | 116 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm 117 | __pypackages__/ 118 | 119 | # Celery stuff 120 | celerybeat-schedule 121 | celerybeat.pid 122 | 123 | # SageMath parsed files 124 | *.sage.py 125 | 126 | # Environments 127 | .env 128 | .venv 129 | env/ 130 | venv/ 131 | ENV/ 132 | env.bak/ 133 | venv.bak/ 134 | 135 | # Spyder project settings 136 | .spyderproject 137 | .spyproject 138 | 139 | # Rope project settings 140 | .ropeproject 141 | 142 | # mkdocs documentation 143 | /site 144 | 145 | # mypy 146 | .mypy_cache/ 147 | .dmypy.json 148 | dmypy.json 149 | 150 | # Pyre type checker 151 | .pyre/ 152 | 153 | # pytype static type analyzer 154 | .pytype/ 155 | 156 | # Cython debug symbols 157 | cython_debug/ 158 | 159 | # PyCharm 160 | # JetBrains specific template is maintained in a separate JetBrains.gitignore that can 161 | # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore 162 | # and can be added to the global gitignore or merged into this file. For a more nuclear 163 | # option (not recommended) you can uncomment the following to ignore the entire idea folder. 164 | #.idea/ 165 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright © 2023 Max Dekel 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 6 | 7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 8 | 9 | THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 10 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Auto Wiki 2 | - An experiment to have an auto generated website for everything. 3 | 4 | # Running on localhost (Linux) 5 | - Clone the repository 6 | - Add you OpenAI API key to the .env.example file, and rename it to .env 7 | - Run ```pip install -r requirements.txt``` 8 | - Run ```gunicorn app:app --timeout 600``` 9 | 10 | # License 11 | - [MIT License](LICENSE.md) 12 | -------------------------------------------------------------------------------- /app.py: -------------------------------------------------------------------------------- 1 | from flask import Flask, redirect, render_template_string 2 | import os 3 | 4 | import gen 5 | 6 | 7 | app = Flask(__name__) 8 | app_dir = os.path.abspath(os.path.dirname(__file__)) 9 | 10 | 11 | @app.route("/") 12 | def index(): 13 | return redirect("/index.html") 14 | 15 | @app.route("/", methods=["GET"]) 16 | def catch_all(path): 17 | # if the path exists, return the path 18 | # if the path doesn't exist, return the generated path 19 | site_path = os.path.join(app_dir, "site", path.split('.')[0] + ".html") 20 | if os.path.exists(site_path): 21 | with open(site_path, "r") as file: 22 | content = file.read() 23 | else: 24 | content = gen.genDoc(path) 25 | os.makedirs(os.path.dirname(site_path), exist_ok=True) 26 | with open(site_path, "w") as file: 27 | file.write(content) 28 | 29 | return render_template_string(content) -------------------------------------------------------------------------------- /gen.py: -------------------------------------------------------------------------------- 1 | import os 2 | from dotenv import load_dotenv 3 | from openai import OpenAI 4 | 5 | load_dotenv() 6 | OpenAI.api_key = os.getenv("OPENAI_API_KEY") 7 | 8 | client = OpenAI() 9 | 10 | 11 | def genDoc(path): 12 | prompt = """ 13 | You are wikiGPT. You will provide a wikipedia style info page for any topic. 14 | Given a website path, you will generate an html file containing info related to the path. 15 | Crucial: At every opportunity you will link to other relative paths of this website. 16 | Sitemap of the website so you can infer what to do: 17 | /index.html # A list of some popular topics 18 | //.html # Info main page for the topic 19 | ///.html # Info subpage for the subtopic 20 | etc. 21 | 22 | Use a dark Nord theme for the website. Make nice buttons and other interavtive elements. 23 | 24 | Do not ever append or prepend any explanation to the generated file. DO NOT USE CODE BLOCKS. 25 | 26 | You will now be given a path. You will generate info for the path. 27 | The path you are given is: {path} 28 | """.format(path=path) 29 | 30 | response = client.chat.completions.create( 31 | model="gpt-4-1106-preview", 32 | messages=[{"role": "user", "content": prompt}], 33 | temperature=0.0 34 | ) 35 | site = response.choices[0].message.content 36 | return site 37 | 38 | if __name__ == "__main__": 39 | # testing 40 | genDoc("/python/panadas") 41 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | Flask 2 | openai 3 | python-dotenv 4 | gunicorn --------------------------------------------------------------------------------