Spaces:
Running
Running
pragneshbarik
commited on
Commit
•
b3f1ffe
1
Parent(s):
5253983
initial commit
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- .gitattributes +0 -35
- .gitignore +160 -0
- app.py +462 -0
- chat_client.py +50 -0
- rag/Scripts/Activate.ps1 +399 -0
- rag/Scripts/activate +66 -0
- rag/Scripts/activate.bat +33 -0
- rag/Scripts/convert-caffe2-to-onnx.exe +0 -0
- rag/Scripts/convert-onnx-to-caffe2.exe +0 -0
- rag/Scripts/deactivate.bat +21 -0
- rag/Scripts/dotenv.exe +0 -0
- rag/Scripts/f2py.exe +0 -0
- rag/Scripts/huggingface-cli.exe +0 -0
- rag/Scripts/ipython.exe +0 -0
- rag/Scripts/ipython3.exe +0 -0
- rag/Scripts/isympy.exe +0 -0
- rag/Scripts/jsonschema.exe +0 -0
- rag/Scripts/jupyter-kernel.exe +0 -0
- rag/Scripts/jupyter-kernelspec.exe +0 -0
- rag/Scripts/jupyter-migrate.exe +0 -0
- rag/Scripts/jupyter-run.exe +0 -0
- rag/Scripts/jupyter-troubleshoot.exe +0 -0
- rag/Scripts/jupyter.exe +0 -0
- rag/Scripts/markdown-it.exe +0 -0
- rag/Scripts/nltk.exe +0 -0
- rag/Scripts/normalizer.exe +0 -0
- rag/Scripts/pinecone.exe +0 -0
- rag/Scripts/pip.exe +0 -0
- rag/Scripts/pip3.9.exe +0 -0
- rag/Scripts/pip3.exe +0 -0
- rag/Scripts/pygmentize.exe +0 -0
- rag/Scripts/python.exe +0 -0
- rag/Scripts/pythonw.exe +0 -0
- rag/Scripts/pywin32_postinstall.py +783 -0
- rag/Scripts/pywin32_testall.py +124 -0
- rag/Scripts/streamlit.cmd +16 -0
- rag/Scripts/streamlit.exe +0 -0
- rag/Scripts/torchrun.exe +0 -0
- rag/Scripts/tqdm.exe +0 -0
- rag/Scripts/transformers-cli.exe +0 -0
- rag/Scripts/watchmedo.exe +0 -0
- rag/etc/jupyter/nbconfig/notebook.d/pydeck.json +5 -0
- rag/pyvenv.cfg +3 -0
- rag/share/jupyter/kernels/python3/kernel.json +14 -0
- rag/share/jupyter/kernels/python3/logo-32x32.png +0 -0
- rag/share/jupyter/kernels/python3/logo-64x64.png +0 -0
- rag/share/jupyter/kernels/python3/logo-svg.svg +265 -0
- rag/share/jupyter/nbextensions/pydeck/extensionRequires.js +15 -0
- rag/share/jupyter/nbextensions/pydeck/index.js +0 -0
- rag/share/jupyter/nbextensions/pydeck/index.js.map +0 -0
.gitattributes
DELETED
@@ -1,35 +0,0 @@
|
|
1 |
-
*.7z filter=lfs diff=lfs merge=lfs -text
|
2 |
-
*.arrow filter=lfs diff=lfs merge=lfs -text
|
3 |
-
*.bin filter=lfs diff=lfs merge=lfs -text
|
4 |
-
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
5 |
-
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
6 |
-
*.ftz filter=lfs diff=lfs merge=lfs -text
|
7 |
-
*.gz filter=lfs diff=lfs merge=lfs -text
|
8 |
-
*.h5 filter=lfs diff=lfs merge=lfs -text
|
9 |
-
*.joblib filter=lfs diff=lfs merge=lfs -text
|
10 |
-
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
11 |
-
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
12 |
-
*.model filter=lfs diff=lfs merge=lfs -text
|
13 |
-
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
14 |
-
*.npy filter=lfs diff=lfs merge=lfs -text
|
15 |
-
*.npz filter=lfs diff=lfs merge=lfs -text
|
16 |
-
*.onnx filter=lfs diff=lfs merge=lfs -text
|
17 |
-
*.ot filter=lfs diff=lfs merge=lfs -text
|
18 |
-
*.parquet filter=lfs diff=lfs merge=lfs -text
|
19 |
-
*.pb filter=lfs diff=lfs merge=lfs -text
|
20 |
-
*.pickle filter=lfs diff=lfs merge=lfs -text
|
21 |
-
*.pkl filter=lfs diff=lfs merge=lfs -text
|
22 |
-
*.pt filter=lfs diff=lfs merge=lfs -text
|
23 |
-
*.pth filter=lfs diff=lfs merge=lfs -text
|
24 |
-
*.rar filter=lfs diff=lfs merge=lfs -text
|
25 |
-
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
26 |
-
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
27 |
-
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
28 |
-
*.tar filter=lfs diff=lfs merge=lfs -text
|
29 |
-
*.tflite filter=lfs diff=lfs merge=lfs -text
|
30 |
-
*.tgz filter=lfs diff=lfs merge=lfs -text
|
31 |
-
*.wasm filter=lfs diff=lfs merge=lfs -text
|
32 |
-
*.xz filter=lfs diff=lfs merge=lfs -text
|
33 |
-
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
-
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
-
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.gitignore
ADDED
@@ -0,0 +1,160 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Byte-compiled / optimized / DLL files
|
2 |
+
__pycache__/
|
3 |
+
*.py[cod]
|
4 |
+
*$py.class
|
5 |
+
|
6 |
+
# C extensions
|
7 |
+
*.so
|
8 |
+
|
9 |
+
# Distribution / packaging
|
10 |
+
.Python
|
11 |
+
build/
|
12 |
+
develop-eggs/
|
13 |
+
dist/
|
14 |
+
downloads/
|
15 |
+
eggs/
|
16 |
+
.eggs/
|
17 |
+
lib/
|
18 |
+
lib64/
|
19 |
+
parts/
|
20 |
+
sdist/
|
21 |
+
var/
|
22 |
+
wheels/
|
23 |
+
share/python-wheels/
|
24 |
+
*.egg-info/
|
25 |
+
.installed.cfg
|
26 |
+
*.egg
|
27 |
+
MANIFEST
|
28 |
+
|
29 |
+
# PyInstaller
|
30 |
+
# Usually these files are written by a python script from a template
|
31 |
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
32 |
+
*.manifest
|
33 |
+
*.spec
|
34 |
+
|
35 |
+
# Installer logs
|
36 |
+
pip-log.txt
|
37 |
+
pip-delete-this-directory.txt
|
38 |
+
|
39 |
+
# Unit test / coverage reports
|
40 |
+
htmlcov/
|
41 |
+
.tox/
|
42 |
+
.nox/
|
43 |
+
.coverage
|
44 |
+
.coverage.*
|
45 |
+
.cache
|
46 |
+
nosetests.xml
|
47 |
+
coverage.xml
|
48 |
+
*.cover
|
49 |
+
*.py,cover
|
50 |
+
.hypothesis/
|
51 |
+
.pytest_cache/
|
52 |
+
cover/
|
53 |
+
|
54 |
+
# Translations
|
55 |
+
*.mo
|
56 |
+
*.pot
|
57 |
+
|
58 |
+
# Django stuff:
|
59 |
+
*.log
|
60 |
+
local_settings.py
|
61 |
+
db.sqlite3
|
62 |
+
db.sqlite3-journal
|
63 |
+
|
64 |
+
# Flask stuff:
|
65 |
+
instance/
|
66 |
+
.webassets-cache
|
67 |
+
|
68 |
+
# Scrapy stuff:
|
69 |
+
.scrapy
|
70 |
+
|
71 |
+
# Sphinx documentation
|
72 |
+
docs/_build/
|
73 |
+
|
74 |
+
# PyBuilder
|
75 |
+
.pybuilder/
|
76 |
+
target/
|
77 |
+
|
78 |
+
# Jupyter Notebook
|
79 |
+
.ipynb_checkpoints
|
80 |
+
|
81 |
+
# IPython
|
82 |
+
profile_default/
|
83 |
+
ipython_config.py
|
84 |
+
|
85 |
+
# pyenv
|
86 |
+
# For a library or package, you might want to ignore these files since the code is
|
87 |
+
# intended to run in multiple environments; otherwise, check them in:
|
88 |
+
# .python-version
|
89 |
+
|
90 |
+
# pipenv
|
91 |
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
92 |
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
93 |
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
94 |
+
# install all needed dependencies.
|
95 |
+
#Pipfile.lock
|
96 |
+
|
97 |
+
# poetry
|
98 |
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
99 |
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
100 |
+
# commonly ignored for libraries.
|
101 |
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
102 |
+
#poetry.lock
|
103 |
+
|
104 |
+
# pdm
|
105 |
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
106 |
+
#pdm.lock
|
107 |
+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
|
108 |
+
# in version control.
|
109 |
+
# https://pdm.fming.dev/#use-with-ide
|
110 |
+
.pdm.toml
|
111 |
+
|
112 |
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
113 |
+
__pypackages__/
|
114 |
+
|
115 |
+
# Celery stuff
|
116 |
+
celerybeat-schedule
|
117 |
+
celerybeat.pid
|
118 |
+
|
119 |
+
# SageMath parsed files
|
120 |
+
*.sage.py
|
121 |
+
|
122 |
+
# Environments
|
123 |
+
.env
|
124 |
+
.venv
|
125 |
+
env/
|
126 |
+
venv/
|
127 |
+
ENV/
|
128 |
+
env.bak/
|
129 |
+
venv.bak/
|
130 |
+
|
131 |
+
# Spyder project settings
|
132 |
+
.spyderproject
|
133 |
+
.spyproject
|
134 |
+
|
135 |
+
# Rope project settings
|
136 |
+
.ropeproject
|
137 |
+
|
138 |
+
# mkdocs documentation
|
139 |
+
/site
|
140 |
+
|
141 |
+
# mypy
|
142 |
+
.mypy_cache/
|
143 |
+
.dmypy.json
|
144 |
+
dmypy.json
|
145 |
+
|
146 |
+
# Pyre type checker
|
147 |
+
.pyre/
|
148 |
+
|
149 |
+
# pytype static type analyzer
|
150 |
+
.pytype/
|
151 |
+
|
152 |
+
# Cython debug symbols
|
153 |
+
cython_debug/
|
154 |
+
|
155 |
+
# PyCharm
|
156 |
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
157 |
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
158 |
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
159 |
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
160 |
+
#.idea/
|
app.py
ADDED
@@ -0,0 +1,462 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from chat_client import chat
|
3 |
+
import time
|
4 |
+
import pandas as pd
|
5 |
+
import os
|
6 |
+
from dotenv import load_dotenv
|
7 |
+
from search_client import SearchClient
|
8 |
+
import math
|
9 |
+
import numpy as np
|
10 |
+
from sentence_transformers import CrossEncoder
|
11 |
+
|
12 |
+
load_dotenv()
|
13 |
+
|
14 |
+
|
15 |
+
GOOGLE_SEARCH_ENGINE_ID = os.getenv("GOOGLE_SEARCH_ENGINE_ID")
|
16 |
+
GOOGLE_SEARCH_API_KEY = os.getenv("GOOGLE_SEARCH_API_KEY")
|
17 |
+
BING_SEARCH_API_KEY = os.getenv("BING_SEARCH_API_KEY")
|
18 |
+
COST_PER_1000_TOKENS_INR = 0.139
|
19 |
+
CHAT_BOTS = {
|
20 |
+
"Mixtral 8x7B v0.1": "mistralai/Mixtral-8x7B-Instruct-v0.1",
|
21 |
+
"Mistral 7B v0.1": "mistralai/Mistral-7B-Instruct-v0.1",
|
22 |
+
}
|
23 |
+
|
24 |
+
INITIAL_PROMPT_ENGINEERING = {
|
25 |
+
"SYSTEM_INSTRUCTION": """ You are a knowledgeable author on medical conditions, with a deep expertise in Huntington's disease.
|
26 |
+
You provide extensive, clear information on complex medical topics, treatments, new research and developments.
|
27 |
+
You avoid giving personal medical advice or diagnoses but offers general advice and underscores the importance of consulting healthcare professionals.
|
28 |
+
Your goal is to inform, engage and enlighten users that enquire about Huntington's disease, offering factual data and real-life perspectives with anempathetic tone.
|
29 |
+
You use every search available including web search together with articles and information from
|
30 |
+
* Journal of Huntington's disease,
|
31 |
+
* Movement Disorders,
|
32 |
+
* Neurology,
|
33 |
+
* Journal of Neurology,
|
34 |
+
* Neurosurgery & Psychiatry,
|
35 |
+
* HDBuzz,
|
36 |
+
* PubMed,
|
37 |
+
* Huntington's disease Society of America (HDSA),
|
38 |
+
* Huntington Study Group (HSG),
|
39 |
+
* Nature Reviews Neurology
|
40 |
+
* ScienceDirect
|
41 |
+
|
42 |
+
The information you provide should be understandable to laypersons, well-organized, and include credible sources, citations, and an empathetic tone.
|
43 |
+
It should educate on the scientific aspects and personal challenges of living with Huntington's Disease.""",
|
44 |
+
"SYSTEM_RESPONSE": """Hello! I'm an assistant trained to provide detailed and accurate information on medical conditions, including Huntington's Disease.
|
45 |
+
I'm here to help answer your questions and provide resources to help you better understand this disease and its impact on individuals and their families.
|
46 |
+
If you have any questions about HD or related topics, feel free to ask!""",
|
47 |
+
"PRE_CONTEXT": """NOW YOU ARE SEARCHING THE WEB, AND HERE ARE THE CHUNKS RETRIEVED FROM THE WEB.""",
|
48 |
+
"POST_CONTEXT": """ """, # EMPTY
|
49 |
+
"PRE_PROMPT": """NOW ACCORDING TO THE CONTEXT RETRIEVED FROM THE GENERATE THE CONTENT FOR THE FOLLOWING SUBJECT""",
|
50 |
+
"POST_PROMPT": """
|
51 |
+
Do not repeat yourself
|
52 |
+
""",
|
53 |
+
}
|
54 |
+
|
55 |
+
googleSearchClient = SearchClient(
|
56 |
+
"google", api_key=GOOGLE_SEARCH_API_KEY, engine_id=GOOGLE_SEARCH_ENGINE_ID
|
57 |
+
)
|
58 |
+
bingSearchClient = SearchClient("bing", api_key=BING_SEARCH_API_KEY, engine_id=None)
|
59 |
+
|
60 |
+
st.set_page_config(
|
61 |
+
page_title="Mixtral Playground",
|
62 |
+
page_icon="📚",
|
63 |
+
)
|
64 |
+
|
65 |
+
reranker = CrossEncoder("cross-encoder/ms-marco-MiniLM-L-6-v2")
|
66 |
+
|
67 |
+
|
68 |
+
def rerank(query, top_k, search_results):
|
69 |
+
chunks = []
|
70 |
+
for result in search_results:
|
71 |
+
text = result["text"]
|
72 |
+
# Chunk the text into segments of 512 words each
|
73 |
+
words = text.split()
|
74 |
+
chunk_size = 512
|
75 |
+
num_chunks = math.ceil(len(words) / chunk_size)
|
76 |
+
for i in range(num_chunks):
|
77 |
+
start = i * chunk_size
|
78 |
+
end = (i + 1) * chunk_size
|
79 |
+
chunk = " ".join(words[start:end])
|
80 |
+
chunks.append((result["link"], chunk))
|
81 |
+
|
82 |
+
# Create sentence combinations with the query
|
83 |
+
sentence_combinations = [[query, chunk[1]] for chunk in chunks]
|
84 |
+
|
85 |
+
# Compute similarity scores for these combinations
|
86 |
+
similarity_scores = reranker.predict(sentence_combinations)
|
87 |
+
|
88 |
+
# Sort scores in decreasing order
|
89 |
+
sim_scores_argsort = reversed(np.argsort(similarity_scores))
|
90 |
+
|
91 |
+
# Rearrange search_results based on the reranked scores
|
92 |
+
reranked_results = []
|
93 |
+
for idx in sim_scores_argsort:
|
94 |
+
link = chunks[idx][0]
|
95 |
+
for result in search_results:
|
96 |
+
if result["link"] == link:
|
97 |
+
reranked_results.append(result)
|
98 |
+
break
|
99 |
+
|
100 |
+
return reranked_results[:top_k]
|
101 |
+
|
102 |
+
|
103 |
+
def gen_augmented_prompt_via_websearch(
|
104 |
+
prompt,
|
105 |
+
vendor,
|
106 |
+
n_crawl,
|
107 |
+
top_k,
|
108 |
+
pre_context,
|
109 |
+
post_context,
|
110 |
+
pre_prompt="",
|
111 |
+
post_prompt="",
|
112 |
+
pass_prev=False,
|
113 |
+
):
|
114 |
+
"""returns a prompt with the context of the query and the top k web search results.
|
115 |
+
|
116 |
+
Args:
|
117 |
+
query (_type_): _description_
|
118 |
+
top_k (_type_): _description_
|
119 |
+
preprompt (str, optional): _description_. Defaults to "".
|
120 |
+
postprompt (str, optional): _description_. Defaults to "".
|
121 |
+
"""
|
122 |
+
search_results = []
|
123 |
+
if vendor == "Google":
|
124 |
+
search_results = googleSearchClient.search(prompt, n_crawl)
|
125 |
+
elif vendor == "Bing":
|
126 |
+
search_results = bingSearchClient.search(prompt, n_crawl)
|
127 |
+
|
128 |
+
reranked_results = rerank(prompt, top_k, search_results)
|
129 |
+
|
130 |
+
links = []
|
131 |
+
context = ""
|
132 |
+
for res in reranked_results:
|
133 |
+
context += res["text"] + "\n\n"
|
134 |
+
link = res["link"]
|
135 |
+
links.append(link)
|
136 |
+
|
137 |
+
print(reranked_results)
|
138 |
+
|
139 |
+
prev_input = st.session_state.history[-1][1] if pass_prev else ""
|
140 |
+
|
141 |
+
generated_prompt = f"""
|
142 |
+
{pre_context}
|
143 |
+
|
144 |
+
{context}
|
145 |
+
|
146 |
+
{post_context}
|
147 |
+
|
148 |
+
{pre_prompt}
|
149 |
+
|
150 |
+
{prompt} \n\n
|
151 |
+
|
152 |
+
{post_prompt}
|
153 |
+
|
154 |
+
{prev_input}
|
155 |
+
"""
|
156 |
+
return generated_prompt, links
|
157 |
+
|
158 |
+
|
159 |
+
def init_state():
|
160 |
+
if "messages" not in st.session_state:
|
161 |
+
st.session_state.messages = []
|
162 |
+
|
163 |
+
if "tokens_used" not in st.session_state:
|
164 |
+
st.session_state.tokens_used = 0
|
165 |
+
|
166 |
+
if "tps" not in st.session_state:
|
167 |
+
st.session_state.tps = 0
|
168 |
+
|
169 |
+
if "temp" not in st.session_state:
|
170 |
+
st.session_state.temp = 0.8
|
171 |
+
|
172 |
+
if "history" not in st.session_state:
|
173 |
+
st.session_state.history = [
|
174 |
+
[
|
175 |
+
INITIAL_PROMPT_ENGINEERING["SYSTEM_INSTRUCTION"],
|
176 |
+
INITIAL_PROMPT_ENGINEERING["SYSTEM_RESPONSE"],
|
177 |
+
]
|
178 |
+
]
|
179 |
+
|
180 |
+
if "n_crawl" not in st.session_state:
|
181 |
+
st.session_state.n_crawl = 5
|
182 |
+
|
183 |
+
if "repetion_penalty" not in st.session_state:
|
184 |
+
st.session_state.repetion_penalty = 1
|
185 |
+
|
186 |
+
if "rag_enabled" not in st.session_state:
|
187 |
+
st.session_state.rag_enabled = True
|
188 |
+
|
189 |
+
if "chat_bot" not in st.session_state:
|
190 |
+
st.session_state.chat_bot = "Mixtral 8x7B v0.1"
|
191 |
+
|
192 |
+
if "search_vendor" not in st.session_state:
|
193 |
+
st.session_state.search_vendor = "Bing"
|
194 |
+
|
195 |
+
if "system_instruction" not in st.session_state:
|
196 |
+
st.session_state.system_instruction = INITIAL_PROMPT_ENGINEERING[
|
197 |
+
"SYSTEM_INSTRUCTION"
|
198 |
+
]
|
199 |
+
|
200 |
+
if "system_response" not in st.session_state:
|
201 |
+
st.session_state.system_instruction = INITIAL_PROMPT_ENGINEERING[
|
202 |
+
"SYSTEM_RESPONSE"
|
203 |
+
]
|
204 |
+
|
205 |
+
if "pre_context" not in st.session_state:
|
206 |
+
st.session_state.pre_context = INITIAL_PROMPT_ENGINEERING["PRE_CONTEXT"]
|
207 |
+
|
208 |
+
if "post_context" not in st.session_state:
|
209 |
+
st.session_state.post_context = INITIAL_PROMPT_ENGINEERING["POST_CONTEXT"]
|
210 |
+
|
211 |
+
if "pre_prompt" not in st.session_state:
|
212 |
+
st.session_state.pre_prompt = INITIAL_PROMPT_ENGINEERING["PRE_PROMPT"]
|
213 |
+
|
214 |
+
if "post_prompt" not in st.session_state:
|
215 |
+
st.session_state.post_prompt = INITIAL_PROMPT_ENGINEERING["POST_PROMPT"]
|
216 |
+
|
217 |
+
if "pass_prev" not in st.session_state:
|
218 |
+
st.session_state.pass_prev = False
|
219 |
+
|
220 |
+
|
221 |
+
def sidebar():
|
222 |
+
def retrieval_settings():
|
223 |
+
st.markdown("# Web Retrieval")
|
224 |
+
st.session_state.rag_enabled = st.toggle("Activate Web Retrieval", value=True)
|
225 |
+
st.session_state.search_vendor = st.radio(
|
226 |
+
"Select Search Vendor",
|
227 |
+
["Bing", "Google"],
|
228 |
+
disabled=not st.session_state.rag_enabled,
|
229 |
+
)
|
230 |
+
st.session_state.n_crawl = st.slider(
|
231 |
+
label="Links to Crawl",
|
232 |
+
key=1,
|
233 |
+
min_value=1,
|
234 |
+
max_value=10,
|
235 |
+
value=4,
|
236 |
+
disabled=not st.session_state.rag_enabled,
|
237 |
+
)
|
238 |
+
st.session_state.top_k = st.slider(
|
239 |
+
label="Rerank Factor",
|
240 |
+
key=2,
|
241 |
+
min_value=1,
|
242 |
+
max_value=20,
|
243 |
+
value=4,
|
244 |
+
disabled=not st.session_state.rag_enabled,
|
245 |
+
)
|
246 |
+
|
247 |
+
st.markdown("---")
|
248 |
+
|
249 |
+
def model_analytics():
|
250 |
+
st.markdown("# Model Analytics")
|
251 |
+
|
252 |
+
st.write("Total tokens used :", st.session_state["tokens_used"])
|
253 |
+
st.write("Speed :", st.session_state["tps"], " tokens/sec")
|
254 |
+
st.write(
|
255 |
+
"Total cost incurred :",
|
256 |
+
round(COST_PER_1000_TOKENS_INR * st.session_state["tokens_used"] / 1000, 3),
|
257 |
+
"INR",
|
258 |
+
)
|
259 |
+
|
260 |
+
st.markdown("---")
|
261 |
+
|
262 |
+
def model_settings():
|
263 |
+
st.markdown("# Model Settings")
|
264 |
+
|
265 |
+
st.session_state.chat_bot = st.sidebar.radio(
|
266 |
+
"Select one:", [key for key, _ in CHAT_BOTS.items()]
|
267 |
+
)
|
268 |
+
st.session_state.temp = st.slider(
|
269 |
+
label="Temperature", min_value=0.0, max_value=1.0, step=0.1, value=0.9
|
270 |
+
)
|
271 |
+
|
272 |
+
st.session_state.max_tokens = st.slider(
|
273 |
+
label="New tokens to generate",
|
274 |
+
min_value=64,
|
275 |
+
max_value=2048,
|
276 |
+
step=32,
|
277 |
+
value=512,
|
278 |
+
)
|
279 |
+
|
280 |
+
st.session_state.repetion_penalty = st.slider(
|
281 |
+
label="Repetion Penalty", min_value=0.0, max_value=1.0, step=0.1, value=1.0
|
282 |
+
)
|
283 |
+
|
284 |
+
with st.sidebar:
|
285 |
+
retrieval_settings()
|
286 |
+
model_analytics()
|
287 |
+
model_settings()
|
288 |
+
|
289 |
+
st.markdown(
|
290 |
+
"""
|
291 |
+
> **Created by [Pragnesh Barik](https://barik.super.site) 🔗**
|
292 |
+
"""
|
293 |
+
)
|
294 |
+
|
295 |
+
|
296 |
+
def prompt_engineering_dashboard():
|
297 |
+
def engineer_prompt():
|
298 |
+
st.session_state.history[0] = [
|
299 |
+
st.session_state.system_instruction,
|
300 |
+
st.session_state.system_response,
|
301 |
+
]
|
302 |
+
|
303 |
+
with st.expander("Prompt Engineering Dashboard"):
|
304 |
+
st.info(
|
305 |
+
"**The input to the model follows this below template**",
|
306 |
+
)
|
307 |
+
st.code(
|
308 |
+
"""
|
309 |
+
[SYSTEM INSTRUCTION]
|
310 |
+
[SYSTEM RESPONSE]
|
311 |
+
|
312 |
+
[... LIST OF PREV INPUTS]
|
313 |
+
|
314 |
+
[PRE CONTEXT]
|
315 |
+
[CONTEXT RETRIEVED FROM THE WEB]
|
316 |
+
[POST CONTEXT]
|
317 |
+
|
318 |
+
[PRE PROMPT]
|
319 |
+
[PROMPT]
|
320 |
+
[POST PROMPT]
|
321 |
+
[PREV GENERATED INPUT] # Only if Pass previous prompt set True
|
322 |
+
|
323 |
+
"""
|
324 |
+
)
|
325 |
+
st.session_state.system_instruction = st.text_area(
|
326 |
+
label="SYSTEM INSTRUCTION",
|
327 |
+
value=INITIAL_PROMPT_ENGINEERING["SYSTEM_INSTRUCTION"],
|
328 |
+
)
|
329 |
+
st.session_state.system_response = st.text_area(
|
330 |
+
"SYSTEM RESPONSE", value=INITIAL_PROMPT_ENGINEERING["SYSTEM_RESPONSE"]
|
331 |
+
)
|
332 |
+
col1, col2 = st.columns(2)
|
333 |
+
with col1:
|
334 |
+
st.text_input(
|
335 |
+
"PRE CONTEXT",
|
336 |
+
value=INITIAL_PROMPT_ENGINEERING["PRE_CONTEXT"],
|
337 |
+
disabled=not st.session_state.rag_enabled,
|
338 |
+
)
|
339 |
+
st.text_input("PRE PROMPT", value=INITIAL_PROMPT_ENGINEERING["PRE_PROMPT"])
|
340 |
+
st.button("Engineer Prompts", on_click=engineer_prompt)
|
341 |
+
|
342 |
+
with col2:
|
343 |
+
st.text_input(
|
344 |
+
"POST CONTEXT",
|
345 |
+
value=INITIAL_PROMPT_ENGINEERING["POST_CONTEXT"],
|
346 |
+
disabled=not st.session_state.rag_enabled,
|
347 |
+
)
|
348 |
+
st.text_input(
|
349 |
+
"POST PROMPT", value=INITIAL_PROMPT_ENGINEERING["POST_PROMPT"]
|
350 |
+
)
|
351 |
+
pass_prev = st.toggle("Pass previous prompt")
|
352 |
+
|
353 |
+
|
354 |
+
def header():
|
355 |
+
st.write("# Mixtral Playground")
|
356 |
+
data = {
|
357 |
+
"Attribute": ["LLM", "Text Vectorizer", "Vector Database", "CPU", "System RAM"],
|
358 |
+
"Information": [
|
359 |
+
"Mixtral-8x7B-Instruct-v0.1",
|
360 |
+
"all-distilroberta-v1",
|
361 |
+
"Hosted Pinecone",
|
362 |
+
"2 vCPU",
|
363 |
+
"16 GB",
|
364 |
+
],
|
365 |
+
}
|
366 |
+
df = pd.DataFrame(data)
|
367 |
+
st.table(df)
|
368 |
+
prompt_engineering_dashboard()
|
369 |
+
|
370 |
+
|
371 |
+
def chat_box():
|
372 |
+
for message in st.session_state.messages:
|
373 |
+
with st.chat_message(message["role"]):
|
374 |
+
st.markdown(message["content"])
|
375 |
+
|
376 |
+
|
377 |
+
def generate_chat_stream(prompt):
|
378 |
+
links = []
|
379 |
+
if st.session_state.rag_enabled:
|
380 |
+
with st.spinner("Fetching relevent documents from Web...."):
|
381 |
+
prompt, links = gen_augmented_prompt_via_websearch(
|
382 |
+
prompt=prompt,
|
383 |
+
pre_context=st.session_state.pre_context,
|
384 |
+
post_context=st.session_state.post_context,
|
385 |
+
pre_prompt=st.session_state.pre_prompt,
|
386 |
+
post_prompt=st.session_state.post_prompt,
|
387 |
+
vendor=st.session_state.search_vendor,
|
388 |
+
top_k=st.session_state.top_k,
|
389 |
+
n_crawl=st.session_state.n_crawl,
|
390 |
+
)
|
391 |
+
|
392 |
+
with st.spinner("Generating response..."):
|
393 |
+
chat_stream = chat(
|
394 |
+
prompt,
|
395 |
+
st.session_state.history,
|
396 |
+
chat_client=CHAT_BOTS[st.session_state.chat_bot],
|
397 |
+
temperature=st.session_state.temp,
|
398 |
+
max_new_tokens=st.session_state.max_tokens,
|
399 |
+
)
|
400 |
+
|
401 |
+
return chat_stream, links
|
402 |
+
|
403 |
+
|
404 |
+
def stream_handler(chat_stream, placeholder):
|
405 |
+
start_time = time.time()
|
406 |
+
full_response = ""
|
407 |
+
|
408 |
+
for chunk in chat_stream:
|
409 |
+
if chunk.token["text"] != "</s>":
|
410 |
+
full_response += chunk.token["text"]
|
411 |
+
placeholder.markdown(full_response + "▌")
|
412 |
+
placeholder.markdown(full_response)
|
413 |
+
|
414 |
+
end_time = time.time()
|
415 |
+
elapsed_time = end_time - start_time
|
416 |
+
total_tokens_processed = len(full_response.split())
|
417 |
+
tokens_per_second = total_tokens_processed // elapsed_time
|
418 |
+
len_response = (len(prompt.split()) + len(full_response.split())) * 1.25
|
419 |
+
col1, col2, col3 = st.columns(3)
|
420 |
+
|
421 |
+
with col1:
|
422 |
+
st.write(f"**{tokens_per_second} tokens/second**")
|
423 |
+
|
424 |
+
with col2:
|
425 |
+
st.write(f"**{int(len_response)} tokens generated**")
|
426 |
+
|
427 |
+
with col3:
|
428 |
+
st.write(
|
429 |
+
f"**₹ {round(len_response * COST_PER_1000_TOKENS_INR / 1000, 5)} cost incurred**"
|
430 |
+
)
|
431 |
+
|
432 |
+
st.session_state["tps"] = tokens_per_second
|
433 |
+
st.session_state["tokens_used"] = len_response + st.session_state["tokens_used"]
|
434 |
+
|
435 |
+
return full_response
|
436 |
+
|
437 |
+
|
438 |
+
def show_source(links):
|
439 |
+
with st.expander("Show source"):
|
440 |
+
for i, link in enumerate(links):
|
441 |
+
st.info(f"{link}")
|
442 |
+
|
443 |
+
|
444 |
+
init_state()
|
445 |
+
sidebar()
|
446 |
+
header()
|
447 |
+
chat_box()
|
448 |
+
|
449 |
+
if prompt := st.chat_input("Generate Ebook"):
|
450 |
+
st.chat_message("user").markdown(prompt)
|
451 |
+
st.session_state.messages.append({"role": "user", "content": prompt})
|
452 |
+
|
453 |
+
chat_stream, links = generate_chat_stream(prompt)
|
454 |
+
|
455 |
+
with st.chat_message("assistant"):
|
456 |
+
placeholder = st.empty()
|
457 |
+
full_response = stream_handler(chat_stream, placeholder)
|
458 |
+
if st.session_state.rag_enabled:
|
459 |
+
show_source(links)
|
460 |
+
|
461 |
+
st.session_state.history.append([prompt, full_response])
|
462 |
+
st.session_state.messages.append({"role": "assistant", "content": full_response})
|
chat_client.py
ADDED
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from huggingface_hub import InferenceClient
|
2 |
+
import os
|
3 |
+
from dotenv import load_dotenv
|
4 |
+
load_dotenv()
|
5 |
+
|
6 |
+
API_TOKEN = os.getenv('HF_TOKEN')
|
7 |
+
|
8 |
+
|
9 |
+
def format_prompt(message, history):
|
10 |
+
prompt = "<s>"
|
11 |
+
for user_prompt, bot_response in history:
|
12 |
+
prompt += f"[INST] {user_prompt} [/INST]"
|
13 |
+
prompt += f" {bot_response}</s> "
|
14 |
+
prompt += f"[INST] {message} [/INST]"
|
15 |
+
return prompt
|
16 |
+
|
17 |
+
def chat(
|
18 |
+
prompt, history, chat_client = "mistralai/Mistral-7B-Instruct-v0.1",temperature=0.9, max_new_tokens=256, top_p=0.95, repetition_penalty=1.0,
|
19 |
+
):
|
20 |
+
client = InferenceClient(
|
21 |
+
chat_client,
|
22 |
+
token=API_TOKEN
|
23 |
+
)
|
24 |
+
temperature = float(temperature)
|
25 |
+
if temperature < 1e-2:
|
26 |
+
temperature = 1e-2
|
27 |
+
top_p = float(top_p)
|
28 |
+
|
29 |
+
generate_kwargs = dict(
|
30 |
+
temperature=temperature,
|
31 |
+
max_new_tokens=max_new_tokens,
|
32 |
+
top_p=top_p,
|
33 |
+
repetition_penalty=repetition_penalty,
|
34 |
+
do_sample=True,
|
35 |
+
seed=42,
|
36 |
+
)
|
37 |
+
|
38 |
+
formatted_prompt = format_prompt(prompt, history)
|
39 |
+
|
40 |
+
stream = client.text_generation(formatted_prompt, **generate_kwargs, stream=True, details=True, return_full_text=False)
|
41 |
+
output = ""
|
42 |
+
|
43 |
+
# for response in stream:
|
44 |
+
# # print(response)
|
45 |
+
# output += response.token["text"]
|
46 |
+
# yield output
|
47 |
+
# return output
|
48 |
+
|
49 |
+
|
50 |
+
return stream
|
rag/Scripts/Activate.ps1
ADDED
@@ -0,0 +1,399 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<#
|
2 |
+
.Synopsis
|
3 |
+
Activate a Python virtual environment for the current PowerShell session.
|
4 |
+
|
5 |
+
.Description
|
6 |
+
Pushes the python executable for a virtual environment to the front of the
|
7 |
+
$Env:PATH environment variable and sets the prompt to signify that you are
|
8 |
+
in a Python virtual environment. Makes use of the command line switches as
|
9 |
+
well as the `pyvenv.cfg` file values present in the virtual environment.
|
10 |
+
|
11 |
+
.Parameter VenvDir
|
12 |
+
Path to the directory that contains the virtual environment to activate. The
|
13 |
+
default value for this is the parent of the directory that the Activate.ps1
|
14 |
+
script is located within.
|
15 |
+
|
16 |
+
.Parameter Prompt
|
17 |
+
The prompt prefix to display when this virtual environment is activated. By
|
18 |
+
default, this prompt is the name of the virtual environment folder (VenvDir)
|
19 |
+
surrounded by parentheses and followed by a single space (ie. '(.venv) ').
|
20 |
+
|
21 |
+
.Example
|
22 |
+
Activate.ps1
|
23 |
+
Activates the Python virtual environment that contains the Activate.ps1 script.
|
24 |
+
|
25 |
+
.Example
|
26 |
+
Activate.ps1 -Verbose
|
27 |
+
Activates the Python virtual environment that contains the Activate.ps1 script,
|
28 |
+
and shows extra information about the activation as it executes.
|
29 |
+
|
30 |
+
.Example
|
31 |
+
Activate.ps1 -VenvDir C:\Users\MyUser\Common\.venv
|
32 |
+
Activates the Python virtual environment located in the specified location.
|
33 |
+
|
34 |
+
.Example
|
35 |
+
Activate.ps1 -Prompt "MyPython"
|
36 |
+
Activates the Python virtual environment that contains the Activate.ps1 script,
|
37 |
+
and prefixes the current prompt with the specified string (surrounded in
|
38 |
+
parentheses) while the virtual environment is active.
|
39 |
+
|
40 |
+
.Notes
|
41 |
+
On Windows, it may be required to enable this Activate.ps1 script by setting the
|
42 |
+
execution policy for the user. You can do this by issuing the following PowerShell
|
43 |
+
command:
|
44 |
+
|
45 |
+
PS C:\> Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
|
46 |
+
|
47 |
+
For more information on Execution Policies:
|
48 |
+
https://go.microsoft.com/fwlink/?LinkID=135170
|
49 |
+
|
50 |
+
#>
|
51 |
+
Param(
|
52 |
+
[Parameter(Mandatory = $false)]
|
53 |
+
[String]
|
54 |
+
$VenvDir,
|
55 |
+
[Parameter(Mandatory = $false)]
|
56 |
+
[String]
|
57 |
+
$Prompt
|
58 |
+
)
|
59 |
+
|
60 |
+
<# Function declarations --------------------------------------------------- #>
|
61 |
+
|
62 |
+
<#
|
63 |
+
.Synopsis
|
64 |
+
Remove all shell session elements added by the Activate script, including the
|
65 |
+
addition of the virtual environment's Python executable from the beginning of
|
66 |
+
the PATH variable.
|
67 |
+
|
68 |
+
.Parameter NonDestructive
|
69 |
+
If present, do not remove this function from the global namespace for the
|
70 |
+
session.
|
71 |
+
|
72 |
+
#>
|
73 |
+
function global:deactivate ([switch]$NonDestructive) {
|
74 |
+
# Revert to original values
|
75 |
+
|
76 |
+
# The prior prompt:
|
77 |
+
if (Test-Path -Path Function:_OLD_VIRTUAL_PROMPT) {
|
78 |
+
Copy-Item -Path Function:_OLD_VIRTUAL_PROMPT -Destination Function:prompt
|
79 |
+
Remove-Item -Path Function:_OLD_VIRTUAL_PROMPT
|
80 |
+
}
|
81 |
+
|
82 |
+
# The prior PYTHONHOME:
|
83 |
+
if (Test-Path -Path Env:_OLD_VIRTUAL_PYTHONHOME) {
|
84 |
+
Copy-Item -Path Env:_OLD_VIRTUAL_PYTHONHOME -Destination Env:PYTHONHOME
|
85 |
+
Remove-Item -Path Env:_OLD_VIRTUAL_PYTHONHOME
|
86 |
+
}
|
87 |
+
|
88 |
+
# The prior PATH:
|
89 |
+
if (Test-Path -Path Env:_OLD_VIRTUAL_PATH) {
|
90 |
+
Copy-Item -Path Env:_OLD_VIRTUAL_PATH -Destination Env:PATH
|
91 |
+
Remove-Item -Path Env:_OLD_VIRTUAL_PATH
|
92 |
+
}
|
93 |
+
|
94 |
+
# Just remove the VIRTUAL_ENV altogether:
|
95 |
+
if (Test-Path -Path Env:VIRTUAL_ENV) {
|
96 |
+
Remove-Item -Path env:VIRTUAL_ENV
|
97 |
+
}
|
98 |
+
|
99 |
+
# Just remove the _PYTHON_VENV_PROMPT_PREFIX altogether:
|
100 |
+
if (Get-Variable -Name "_PYTHON_VENV_PROMPT_PREFIX" -ErrorAction SilentlyContinue) {
|
101 |
+
Remove-Variable -Name _PYTHON_VENV_PROMPT_PREFIX -Scope Global -Force
|
102 |
+
}
|
103 |
+
|
104 |
+
# Leave deactivate function in the global namespace if requested:
|
105 |
+
if (-not $NonDestructive) {
|
106 |
+
Remove-Item -Path function:deactivate
|
107 |
+
}
|
108 |
+
}
|
109 |
+
|
110 |
+
<#
|
111 |
+
.Description
|
112 |
+
Get-PyVenvConfig parses the values from the pyvenv.cfg file located in the
|
113 |
+
given folder, and returns them in a map.
|
114 |
+
|
115 |
+
For each line in the pyvenv.cfg file, if that line can be parsed into exactly
|
116 |
+
two strings separated by `=` (with any amount of whitespace surrounding the =)
|
117 |
+
then it is considered a `key = value` line. The left hand string is the key,
|
118 |
+
the right hand is the value.
|
119 |
+
|
120 |
+
If the value starts with a `'` or a `"` then the first and last character is
|
121 |
+
stripped from the value before being captured.
|
122 |
+
|
123 |
+
.Parameter ConfigDir
|
124 |
+
Path to the directory that contains the `pyvenv.cfg` file.
|
125 |
+
#>
|
126 |
+
function Get-PyVenvConfig(
|
127 |
+
[String]
|
128 |
+
$ConfigDir
|
129 |
+
) {
|
130 |
+
Write-Verbose "Given ConfigDir=$ConfigDir, obtain values in pyvenv.cfg"
|
131 |
+
|
132 |
+
# Ensure the file exists, and issue a warning if it doesn't (but still allow the function to continue).
|
133 |
+
$pyvenvConfigPath = Join-Path -Resolve -Path $ConfigDir -ChildPath 'pyvenv.cfg' -ErrorAction Continue
|
134 |
+
|
135 |
+
# An empty map will be returned if no config file is found.
|
136 |
+
$pyvenvConfig = @{ }
|
137 |
+
|
138 |
+
if ($pyvenvConfigPath) {
|
139 |
+
|
140 |
+
Write-Verbose "File exists, parse `key = value` lines"
|
141 |
+
$pyvenvConfigContent = Get-Content -Path $pyvenvConfigPath
|
142 |
+
|
143 |
+
$pyvenvConfigContent | ForEach-Object {
|
144 |
+
$keyval = $PSItem -split "\s*=\s*", 2
|
145 |
+
if ($keyval[0] -and $keyval[1]) {
|
146 |
+
$val = $keyval[1]
|
147 |
+
|
148 |
+
# Remove extraneous quotations around a string value.
|
149 |
+
if ("'""".Contains($val.Substring(0, 1))) {
|
150 |
+
$val = $val.Substring(1, $val.Length - 2)
|
151 |
+
}
|
152 |
+
|
153 |
+
$pyvenvConfig[$keyval[0]] = $val
|
154 |
+
Write-Verbose "Adding Key: '$($keyval[0])'='$val'"
|
155 |
+
}
|
156 |
+
}
|
157 |
+
}
|
158 |
+
return $pyvenvConfig
|
159 |
+
}
|
160 |
+
|
161 |
+
|
162 |
+
<# Begin Activate script --------------------------------------------------- #>
|
163 |
+
|
164 |
+
# Determine the containing directory of this script
|
165 |
+
$VenvExecPath = Split-Path -Parent $MyInvocation.MyCommand.Definition
|
166 |
+
$VenvExecDir = Get-Item -Path $VenvExecPath
|
167 |
+
|
168 |
+
Write-Verbose "Activation script is located in path: '$VenvExecPath'"
|
169 |
+
Write-Verbose "VenvExecDir Fullname: '$($VenvExecDir.FullName)"
|
170 |
+
Write-Verbose "VenvExecDir Name: '$($VenvExecDir.Name)"
|
171 |
+
|
172 |
+
# Set values required in priority: CmdLine, ConfigFile, Default
|
173 |
+
# First, get the location of the virtual environment, it might not be
|
174 |
+
# VenvExecDir if specified on the command line.
|
175 |
+
if ($VenvDir) {
|
176 |
+
Write-Verbose "VenvDir given as parameter, using '$VenvDir' to determine values"
|
177 |
+
}
|
178 |
+
else {
|
179 |
+
Write-Verbose "VenvDir not given as a parameter, using parent directory name as VenvDir."
|
180 |
+
$VenvDir = $VenvExecDir.Parent.FullName.TrimEnd("\\/")
|
181 |
+
Write-Verbose "VenvDir=$VenvDir"
|
182 |
+
}
|
183 |
+
|
184 |
+
# Next, read the `pyvenv.cfg` file to determine any required value such
|
185 |
+
# as `prompt`.
|
186 |
+
$pyvenvCfg = Get-PyVenvConfig -ConfigDir $VenvDir
|
187 |
+
|
188 |
+
# Next, set the prompt from the command line, or the config file, or
|
189 |
+
# just use the name of the virtual environment folder.
|
190 |
+
if ($Prompt) {
|
191 |
+
Write-Verbose "Prompt specified as argument, using '$Prompt'"
|
192 |
+
}
|
193 |
+
else {
|
194 |
+
Write-Verbose "Prompt not specified as argument to script, checking pyvenv.cfg value"
|
195 |
+
if ($pyvenvCfg -and $pyvenvCfg['prompt']) {
|
196 |
+
Write-Verbose " Setting based on value in pyvenv.cfg='$($pyvenvCfg['prompt'])'"
|
197 |
+
$Prompt = $pyvenvCfg['prompt'];
|
198 |
+
}
|
199 |
+
else {
|
200 |
+
Write-Verbose " Setting prompt based on parent's directory's name. (Is the directory name passed to venv module when creating the virtual environment)"
|
201 |
+
Write-Verbose " Got leaf-name of $VenvDir='$(Split-Path -Path $venvDir -Leaf)'"
|
202 |
+
$Prompt = Split-Path -Path $venvDir -Leaf
|
203 |
+
}
|
204 |
+
}
|
205 |
+
|
206 |
+
Write-Verbose "Prompt = '$Prompt'"
|
207 |
+
Write-Verbose "VenvDir='$VenvDir'"
|
208 |
+
|
209 |
+
# Deactivate any currently active virtual environment, but leave the
|
210 |
+
# deactivate function in place.
|
211 |
+
deactivate -nondestructive
|
212 |
+
|
213 |
+
# Now set the environment variable VIRTUAL_ENV, used by many tools to determine
|
214 |
+
# that there is an activated venv.
|
215 |
+
$env:VIRTUAL_ENV = $VenvDir
|
216 |
+
|
217 |
+
if (-not $Env:VIRTUAL_ENV_DISABLE_PROMPT) {
|
218 |
+
|
219 |
+
Write-Verbose "Setting prompt to '$Prompt'"
|
220 |
+
|
221 |
+
# Set the prompt to include the env name
|
222 |
+
# Make sure _OLD_VIRTUAL_PROMPT is global
|
223 |
+
function global:_OLD_VIRTUAL_PROMPT { "" }
|
224 |
+
Copy-Item -Path function:prompt -Destination function:_OLD_VIRTUAL_PROMPT
|
225 |
+
New-Variable -Name _PYTHON_VENV_PROMPT_PREFIX -Description "Python virtual environment prompt prefix" -Scope Global -Option ReadOnly -Visibility Public -Value $Prompt
|
226 |
+
|
227 |
+
function global:prompt {
|
228 |
+
Write-Host -NoNewline -ForegroundColor Green "($_PYTHON_VENV_PROMPT_PREFIX) "
|
229 |
+
_OLD_VIRTUAL_PROMPT
|
230 |
+
}
|
231 |
+
}
|
232 |
+
|
233 |
+
# Clear PYTHONHOME
|
234 |
+
if (Test-Path -Path Env:PYTHONHOME) {
|
235 |
+
Copy-Item -Path Env:PYTHONHOME -Destination Env:_OLD_VIRTUAL_PYTHONHOME
|
236 |
+
Remove-Item -Path Env:PYTHONHOME
|
237 |
+
}
|
238 |
+
|
239 |
+
# Add the venv to the PATH
|
240 |
+
Copy-Item -Path Env:PATH -Destination Env:_OLD_VIRTUAL_PATH
|
241 |
+
$Env:PATH = "$VenvExecDir$([System.IO.Path]::PathSeparator)$Env:PATH"
|
242 |
+
|
243 |
+
# SIG # Begin signature block
|
244 |
+
# MIIc9wYJKoZIhvcNAQcCoIIc6DCCHOQCAQExDzANBglghkgBZQMEAgEFADB5Bgor
|
245 |
+
# BgEEAYI3AgEEoGswaTA0BgorBg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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# This file must be used with "source bin/activate" *from bash*
|
2 |
+
# you cannot run it directly
|
3 |
+
|
4 |
+
deactivate () {
|
5 |
+
# reset old environment variables
|
6 |
+
if [ -n "${_OLD_VIRTUAL_PATH:-}" ] ; then
|
7 |
+
PATH="${_OLD_VIRTUAL_PATH:-}"
|
8 |
+
export PATH
|
9 |
+
unset _OLD_VIRTUAL_PATH
|
10 |
+
fi
|
11 |
+
if [ -n "${_OLD_VIRTUAL_PYTHONHOME:-}" ] ; then
|
12 |
+
PYTHONHOME="${_OLD_VIRTUAL_PYTHONHOME:-}"
|
13 |
+
export PYTHONHOME
|
14 |
+
unset _OLD_VIRTUAL_PYTHONHOME
|
15 |
+
fi
|
16 |
+
|
17 |
+
# This should detect bash and zsh, which have a hash command that must
|
18 |
+
# be called to get it to forget past commands. Without forgetting
|
19 |
+
# past commands the $PATH changes we made may not be respected
|
20 |
+
if [ -n "${BASH:-}" -o -n "${ZSH_VERSION:-}" ] ; then
|
21 |
+
hash -r 2> /dev/null
|
22 |
+
fi
|
23 |
+
|
24 |
+
if [ -n "${_OLD_VIRTUAL_PS1:-}" ] ; then
|
25 |
+
PS1="${_OLD_VIRTUAL_PS1:-}"
|
26 |
+
export PS1
|
27 |
+
unset _OLD_VIRTUAL_PS1
|
28 |
+
fi
|
29 |
+
|
30 |
+
unset VIRTUAL_ENV
|
31 |
+
if [ ! "${1:-}" = "nondestructive" ] ; then
|
32 |
+
# Self destruct!
|
33 |
+
unset -f deactivate
|
34 |
+
fi
|
35 |
+
}
|
36 |
+
|
37 |
+
# unset irrelevant variables
|
38 |
+
deactivate nondestructive
|
39 |
+
|
40 |
+
VIRTUAL_ENV="E:\Projects\ebook-gen\ebook-gen\rag"
|
41 |
+
export VIRTUAL_ENV
|
42 |
+
|
43 |
+
_OLD_VIRTUAL_PATH="$PATH"
|
44 |
+
PATH="$VIRTUAL_ENV/Scripts:$PATH"
|
45 |
+
export PATH
|
46 |
+
|
47 |
+
# unset PYTHONHOME if set
|
48 |
+
# this will fail if PYTHONHOME is set to the empty string (which is bad anyway)
|
49 |
+
# could use `if (set -u; : $PYTHONHOME) ;` in bash
|
50 |
+
if [ -n "${PYTHONHOME:-}" ] ; then
|
51 |
+
_OLD_VIRTUAL_PYTHONHOME="${PYTHONHOME:-}"
|
52 |
+
unset PYTHONHOME
|
53 |
+
fi
|
54 |
+
|
55 |
+
if [ -z "${VIRTUAL_ENV_DISABLE_PROMPT:-}" ] ; then
|
56 |
+
_OLD_VIRTUAL_PS1="${PS1:-}"
|
57 |
+
PS1="(rag) ${PS1:-}"
|
58 |
+
export PS1
|
59 |
+
fi
|
60 |
+
|
61 |
+
# This should detect bash and zsh, which have a hash command that must
|
62 |
+
# be called to get it to forget past commands. Without forgetting
|
63 |
+
# past commands the $PATH changes we made may not be respected
|
64 |
+
if [ -n "${BASH:-}" -o -n "${ZSH_VERSION:-}" ] ; then
|
65 |
+
hash -r 2> /dev/null
|
66 |
+
fi
|
rag/Scripts/activate.bat
ADDED
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
@echo off
|
2 |
+
|
3 |
+
rem This file is UTF-8 encoded, so we need to update the current code page while executing it
|
4 |
+
for /f "tokens=2 delims=:." %%a in ('"%SystemRoot%\System32\chcp.com"') do (
|
5 |
+
set _OLD_CODEPAGE=%%a
|
6 |
+
)
|
7 |
+
if defined _OLD_CODEPAGE (
|
8 |
+
"%SystemRoot%\System32\chcp.com" 65001 > nul
|
9 |
+
)
|
10 |
+
|
11 |
+
set VIRTUAL_ENV=E:\Projects\ebook-gen\ebook-gen\rag
|
12 |
+
|
13 |
+
if not defined PROMPT set PROMPT=$P$G
|
14 |
+
|
15 |
+
if defined _OLD_VIRTUAL_PROMPT set PROMPT=%_OLD_VIRTUAL_PROMPT%
|
16 |
+
if defined _OLD_VIRTUAL_PYTHONHOME set PYTHONHOME=%_OLD_VIRTUAL_PYTHONHOME%
|
17 |
+
|
18 |
+
set _OLD_VIRTUAL_PROMPT=%PROMPT%
|
19 |
+
set PROMPT=(rag) %PROMPT%
|
20 |
+
|
21 |
+
if defined PYTHONHOME set _OLD_VIRTUAL_PYTHONHOME=%PYTHONHOME%
|
22 |
+
set PYTHONHOME=
|
23 |
+
|
24 |
+
if defined _OLD_VIRTUAL_PATH set PATH=%_OLD_VIRTUAL_PATH%
|
25 |
+
if not defined _OLD_VIRTUAL_PATH set _OLD_VIRTUAL_PATH=%PATH%
|
26 |
+
|
27 |
+
set PATH=%VIRTUAL_ENV%\Scripts;%PATH%
|
28 |
+
|
29 |
+
:END
|
30 |
+
if defined _OLD_CODEPAGE (
|
31 |
+
"%SystemRoot%\System32\chcp.com" %_OLD_CODEPAGE% > nul
|
32 |
+
set _OLD_CODEPAGE=
|
33 |
+
)
|
rag/Scripts/convert-caffe2-to-onnx.exe
ADDED
Binary file (106 kB). View file
|
|
rag/Scripts/convert-onnx-to-caffe2.exe
ADDED
Binary file (106 kB). View file
|
|
rag/Scripts/deactivate.bat
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
@echo off
|
2 |
+
|
3 |
+
if defined _OLD_VIRTUAL_PROMPT (
|
4 |
+
set "PROMPT=%_OLD_VIRTUAL_PROMPT%"
|
5 |
+
)
|
6 |
+
set _OLD_VIRTUAL_PROMPT=
|
7 |
+
|
8 |
+
if defined _OLD_VIRTUAL_PYTHONHOME (
|
9 |
+
set "PYTHONHOME=%_OLD_VIRTUAL_PYTHONHOME%"
|
10 |
+
set _OLD_VIRTUAL_PYTHONHOME=
|
11 |
+
)
|
12 |
+
|
13 |
+
if defined _OLD_VIRTUAL_PATH (
|
14 |
+
set "PATH=%_OLD_VIRTUAL_PATH%"
|
15 |
+
)
|
16 |
+
|
17 |
+
set _OLD_VIRTUAL_PATH=
|
18 |
+
|
19 |
+
set VIRTUAL_ENV=
|
20 |
+
|
21 |
+
:END
|
rag/Scripts/dotenv.exe
ADDED
Binary file (106 kB). View file
|
|
rag/Scripts/f2py.exe
ADDED
Binary file (106 kB). View file
|
|
rag/Scripts/huggingface-cli.exe
ADDED
Binary file (106 kB). View file
|
|
rag/Scripts/ipython.exe
ADDED
Binary file (106 kB). View file
|
|
rag/Scripts/ipython3.exe
ADDED
Binary file (106 kB). View file
|
|
rag/Scripts/isympy.exe
ADDED
Binary file (106 kB). View file
|
|
rag/Scripts/jsonschema.exe
ADDED
Binary file (106 kB). View file
|
|
rag/Scripts/jupyter-kernel.exe
ADDED
Binary file (106 kB). View file
|
|
rag/Scripts/jupyter-kernelspec.exe
ADDED
Binary file (106 kB). View file
|
|
rag/Scripts/jupyter-migrate.exe
ADDED
Binary file (106 kB). View file
|
|
rag/Scripts/jupyter-run.exe
ADDED
Binary file (106 kB). View file
|
|
rag/Scripts/jupyter-troubleshoot.exe
ADDED
Binary file (106 kB). View file
|
|
rag/Scripts/jupyter.exe
ADDED
Binary file (106 kB). View file
|
|
rag/Scripts/markdown-it.exe
ADDED
Binary file (106 kB). View file
|
|
rag/Scripts/nltk.exe
ADDED
Binary file (106 kB). View file
|
|
rag/Scripts/normalizer.exe
ADDED
Binary file (106 kB). View file
|
|
rag/Scripts/pinecone.exe
ADDED
Binary file (106 kB). View file
|
|
rag/Scripts/pip.exe
ADDED
Binary file (106 kB). View file
|
|
rag/Scripts/pip3.9.exe
ADDED
Binary file (106 kB). View file
|
|
rag/Scripts/pip3.exe
ADDED
Binary file (106 kB). View file
|
|
rag/Scripts/pygmentize.exe
ADDED
Binary file (106 kB). View file
|
|
rag/Scripts/python.exe
ADDED
Binary file (543 kB). View file
|
|
rag/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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# postinstall script for pywin32
|
2 |
+
#
|
3 |
+
# copies PyWinTypesxx.dll and PythonCOMxx.dll into the system directory,
|
4 |
+
# and creates a pth file
|
5 |
+
import glob
|
6 |
+
import os
|
7 |
+
import shutil
|
8 |
+
import sys
|
9 |
+
import sysconfig
|
10 |
+
|
11 |
+
try:
|
12 |
+
import winreg as winreg
|
13 |
+
except:
|
14 |
+
import winreg
|
15 |
+
|
16 |
+
# Send output somewhere so it can be found if necessary...
|
17 |
+
import tempfile
|
18 |
+
|
19 |
+
tee_f = open(os.path.join(tempfile.gettempdir(), "pywin32_postinstall.log"), "w")
|
20 |
+
|
21 |
+
|
22 |
+
class Tee:
|
23 |
+
def __init__(self, file):
|
24 |
+
self.f = file
|
25 |
+
|
26 |
+
def write(self, what):
|
27 |
+
if self.f is not None:
|
28 |
+
try:
|
29 |
+
self.f.write(what.replace("\n", "\r\n"))
|
30 |
+
except IOError:
|
31 |
+
pass
|
32 |
+
tee_f.write(what)
|
33 |
+
|
34 |
+
def flush(self):
|
35 |
+
if self.f is not None:
|
36 |
+
try:
|
37 |
+
self.f.flush()
|
38 |
+
except IOError:
|
39 |
+
pass
|
40 |
+
tee_f.flush()
|
41 |
+
|
42 |
+
|
43 |
+
# For some unknown reason, when running under bdist_wininst we will start up
|
44 |
+
# with sys.stdout as None but stderr is hooked up. This work-around allows
|
45 |
+
# bdist_wininst to see the output we write and display it at the end of
|
46 |
+
# the install.
|
47 |
+
if sys.stdout is None:
|
48 |
+
sys.stdout = sys.stderr
|
49 |
+
|
50 |
+
sys.stderr = Tee(sys.stderr)
|
51 |
+
sys.stdout = Tee(sys.stdout)
|
52 |
+
|
53 |
+
com_modules = [
|
54 |
+
# module_name, class_names
|
55 |
+
("win32com.servers.interp", "Interpreter"),
|
56 |
+
("win32com.servers.dictionary", "DictionaryPolicy"),
|
57 |
+
("win32com.axscript.client.pyscript", "PyScript"),
|
58 |
+
]
|
59 |
+
|
60 |
+
# Is this a 'silent' install - ie, avoid all dialogs.
|
61 |
+
# Different than 'verbose'
|
62 |
+
silent = 0
|
63 |
+
|
64 |
+
# Verbosity of output messages.
|
65 |
+
verbose = 1
|
66 |
+
|
67 |
+
root_key_name = "Software\\Python\\PythonCore\\" + sys.winver
|
68 |
+
|
69 |
+
try:
|
70 |
+
# When this script is run from inside the bdist_wininst installer,
|
71 |
+
# file_created() and directory_created() are additional builtin
|
72 |
+
# functions which write lines to Python23\pywin32-install.log. This is
|
73 |
+
# a list of actions for the uninstaller, the format is inspired by what
|
74 |
+
# the Wise installer also creates.
|
75 |
+
file_created
|
76 |
+
is_bdist_wininst = True
|
77 |
+
except NameError:
|
78 |
+
is_bdist_wininst = False # we know what it is not - but not what it is :)
|
79 |
+
|
80 |
+
def file_created(file):
|
81 |
+
pass
|
82 |
+
|
83 |
+
def directory_created(directory):
|
84 |
+
pass
|
85 |
+
|
86 |
+
def get_root_hkey():
|
87 |
+
try:
|
88 |
+
winreg.OpenKey(
|
89 |
+
winreg.HKEY_LOCAL_MACHINE, root_key_name, 0, winreg.KEY_CREATE_SUB_KEY
|
90 |
+
)
|
91 |
+
return winreg.HKEY_LOCAL_MACHINE
|
92 |
+
except OSError:
|
93 |
+
# Either not exist, or no permissions to create subkey means
|
94 |
+
# must be HKCU
|
95 |
+
return winreg.HKEY_CURRENT_USER
|
96 |
+
|
97 |
+
|
98 |
+
try:
|
99 |
+
create_shortcut
|
100 |
+
except NameError:
|
101 |
+
# Create a function with the same signature as create_shortcut provided
|
102 |
+
# by bdist_wininst
|
103 |
+
def create_shortcut(
|
104 |
+
path, description, filename, arguments="", workdir="", iconpath="", iconindex=0
|
105 |
+
):
|
106 |
+
import pythoncom
|
107 |
+
from win32com.shell import shell
|
108 |
+
|
109 |
+
ilink = pythoncom.CoCreateInstance(
|
110 |
+
shell.CLSID_ShellLink,
|
111 |
+
None,
|
112 |
+
pythoncom.CLSCTX_INPROC_SERVER,
|
113 |
+
shell.IID_IShellLink,
|
114 |
+
)
|
115 |
+
ilink.SetPath(path)
|
116 |
+
ilink.SetDescription(description)
|
117 |
+
if arguments:
|
118 |
+
ilink.SetArguments(arguments)
|
119 |
+
if workdir:
|
120 |
+
ilink.SetWorkingDirectory(workdir)
|
121 |
+
if iconpath or iconindex:
|
122 |
+
ilink.SetIconLocation(iconpath, iconindex)
|
123 |
+
# now save it.
|
124 |
+
ipf = ilink.QueryInterface(pythoncom.IID_IPersistFile)
|
125 |
+
ipf.Save(filename, 0)
|
126 |
+
|
127 |
+
# Support the same list of "path names" as bdist_wininst.
|
128 |
+
def get_special_folder_path(path_name):
|
129 |
+
from win32com.shell import shell, shellcon
|
130 |
+
|
131 |
+
for maybe in """
|
132 |
+
CSIDL_COMMON_STARTMENU CSIDL_STARTMENU CSIDL_COMMON_APPDATA
|
133 |
+
CSIDL_LOCAL_APPDATA CSIDL_APPDATA CSIDL_COMMON_DESKTOPDIRECTORY
|
134 |
+
CSIDL_DESKTOPDIRECTORY CSIDL_COMMON_STARTUP CSIDL_STARTUP
|
135 |
+
CSIDL_COMMON_PROGRAMS CSIDL_PROGRAMS CSIDL_PROGRAM_FILES_COMMON
|
136 |
+
CSIDL_PROGRAM_FILES CSIDL_FONTS""".split():
|
137 |
+
if maybe == path_name:
|
138 |
+
csidl = getattr(shellcon, maybe)
|
139 |
+
return shell.SHGetSpecialFolderPath(0, csidl, False)
|
140 |
+
raise ValueError("%s is an unknown path ID" % (path_name,))
|
141 |
+
|
142 |
+
|
143 |
+
def CopyTo(desc, src, dest):
|
144 |
+
import win32api
|
145 |
+
import win32con
|
146 |
+
|
147 |
+
while 1:
|
148 |
+
try:
|
149 |
+
win32api.CopyFile(src, dest, 0)
|
150 |
+
return
|
151 |
+
except win32api.error as details:
|
152 |
+
if details.winerror == 5: # access denied - user not admin.
|
153 |
+
raise
|
154 |
+
if silent:
|
155 |
+
# Running silent mode - just re-raise the error.
|
156 |
+
raise
|
157 |
+
full_desc = (
|
158 |
+
"Error %s\n\n"
|
159 |
+
"If you have any Python applications running, "
|
160 |
+
"please close them now\nand select 'Retry'\n\n%s"
|
161 |
+
% (desc, details.strerror)
|
162 |
+
)
|
163 |
+
rc = win32api.MessageBox(
|
164 |
+
0, full_desc, "Installation Error", win32con.MB_ABORTRETRYIGNORE
|
165 |
+
)
|
166 |
+
if rc == win32con.IDABORT:
|
167 |
+
raise
|
168 |
+
elif rc == win32con.IDIGNORE:
|
169 |
+
return
|
170 |
+
# else retry - around we go again.
|
171 |
+
|
172 |
+
|
173 |
+
# We need to import win32api to determine the Windows system directory,
|
174 |
+
# so we can copy our system files there - but importing win32api will
|
175 |
+
# load the pywintypes.dll already in the system directory preventing us
|
176 |
+
# from updating them!
|
177 |
+
# So, we pull the same trick pywintypes.py does, but it loads from
|
178 |
+
# our pywintypes_system32 directory.
|
179 |
+
def LoadSystemModule(lib_dir, modname):
|
180 |
+
# See if this is a debug build.
|
181 |
+
import importlib.machinery
|
182 |
+
import importlib.util
|
183 |
+
|
184 |
+
suffix = "_d" if "_d.pyd" in importlib.machinery.EXTENSION_SUFFIXES else ""
|
185 |
+
filename = "%s%d%d%s.dll" % (
|
186 |
+
modname,
|
187 |
+
sys.version_info[0],
|
188 |
+
sys.version_info[1],
|
189 |
+
suffix,
|
190 |
+
)
|
191 |
+
filename = os.path.join(lib_dir, "pywin32_system32", filename)
|
192 |
+
loader = importlib.machinery.ExtensionFileLoader(modname, filename)
|
193 |
+
spec = importlib.machinery.ModuleSpec(name=modname, loader=loader, origin=filename)
|
194 |
+
mod = importlib.util.module_from_spec(spec)
|
195 |
+
spec.loader.exec_module(mod)
|
196 |
+
|
197 |
+
|
198 |
+
def SetPyKeyVal(key_name, value_name, value):
|
199 |
+
root_hkey = get_root_hkey()
|
200 |
+
root_key = winreg.OpenKey(root_hkey, root_key_name)
|
201 |
+
try:
|
202 |
+
my_key = winreg.CreateKey(root_key, key_name)
|
203 |
+
try:
|
204 |
+
winreg.SetValueEx(my_key, value_name, 0, winreg.REG_SZ, value)
|
205 |
+
if verbose:
|
206 |
+
print("-> %s\\%s[%s]=%r" % (root_key_name, key_name, value_name, value))
|
207 |
+
finally:
|
208 |
+
my_key.Close()
|
209 |
+
finally:
|
210 |
+
root_key.Close()
|
211 |
+
|
212 |
+
|
213 |
+
def UnsetPyKeyVal(key_name, value_name, delete_key=False):
|
214 |
+
root_hkey = get_root_hkey()
|
215 |
+
root_key = winreg.OpenKey(root_hkey, root_key_name)
|
216 |
+
try:
|
217 |
+
my_key = winreg.OpenKey(root_key, key_name, 0, winreg.KEY_SET_VALUE)
|
218 |
+
try:
|
219 |
+
winreg.DeleteValue(my_key, value_name)
|
220 |
+
if verbose:
|
221 |
+
print("-> DELETE %s\\%s[%s]" % (root_key_name, key_name, value_name))
|
222 |
+
finally:
|
223 |
+
my_key.Close()
|
224 |
+
if delete_key:
|
225 |
+
winreg.DeleteKey(root_key, key_name)
|
226 |
+
if verbose:
|
227 |
+
print("-> DELETE %s\\%s" % (root_key_name, key_name))
|
228 |
+
except OSError as why:
|
229 |
+
winerror = getattr(why, "winerror", why.errno)
|
230 |
+
if winerror != 2: # file not found
|
231 |
+
raise
|
232 |
+
finally:
|
233 |
+
root_key.Close()
|
234 |
+
|
235 |
+
|
236 |
+
def RegisterCOMObjects(register=True):
|
237 |
+
import win32com.server.register
|
238 |
+
|
239 |
+
if register:
|
240 |
+
func = win32com.server.register.RegisterClasses
|
241 |
+
else:
|
242 |
+
func = win32com.server.register.UnregisterClasses
|
243 |
+
flags = {}
|
244 |
+
if not verbose:
|
245 |
+
flags["quiet"] = 1
|
246 |
+
for module, klass_name in com_modules:
|
247 |
+
__import__(module)
|
248 |
+
mod = sys.modules[module]
|
249 |
+
flags["finalize_register"] = getattr(mod, "DllRegisterServer", None)
|
250 |
+
flags["finalize_unregister"] = getattr(mod, "DllUnregisterServer", None)
|
251 |
+
klass = getattr(mod, klass_name)
|
252 |
+
func(klass, **flags)
|
253 |
+
|
254 |
+
|
255 |
+
def RegisterHelpFile(register=True, lib_dir=None):
|
256 |
+
if lib_dir is None:
|
257 |
+
lib_dir = sysconfig.get_paths()["platlib"]
|
258 |
+
if register:
|
259 |
+
# Register the .chm help file.
|
260 |
+
chm_file = os.path.join(lib_dir, "PyWin32.chm")
|
261 |
+
if os.path.isfile(chm_file):
|
262 |
+
# This isn't recursive, so if 'Help' doesn't exist, we croak
|
263 |
+
SetPyKeyVal("Help", None, None)
|
264 |
+
SetPyKeyVal("Help\\Pythonwin Reference", None, chm_file)
|
265 |
+
return chm_file
|
266 |
+
else:
|
267 |
+
print("NOTE: PyWin32.chm can not be located, so has not " "been registered")
|
268 |
+
else:
|
269 |
+
UnsetPyKeyVal("Help\\Pythonwin Reference", None, delete_key=True)
|
270 |
+
return None
|
271 |
+
|
272 |
+
|
273 |
+
def RegisterPythonwin(register=True, lib_dir=None):
|
274 |
+
"""Add (or remove) Pythonwin to context menu for python scripts.
|
275 |
+
??? Should probably also add Edit command for pys files also.
|
276 |
+
Also need to remove these keys on uninstall, but there's no function
|
277 |
+
like file_created to add registry entries to uninstall log ???
|
278 |
+
"""
|
279 |
+
import os
|
280 |
+
|
281 |
+
if lib_dir is None:
|
282 |
+
lib_dir = sysconfig.get_paths()["platlib"]
|
283 |
+
classes_root = get_root_hkey()
|
284 |
+
## Installer executable doesn't seem to pass anything to postinstall script indicating if it's a debug build,
|
285 |
+
pythonwin_exe = os.path.join(lib_dir, "Pythonwin", "Pythonwin.exe")
|
286 |
+
pythonwin_edit_command = pythonwin_exe + ' -edit "%1"'
|
287 |
+
|
288 |
+
keys_vals = [
|
289 |
+
(
|
290 |
+
"Software\\Microsoft\\Windows\\CurrentVersion\\App Paths\\Pythonwin.exe",
|
291 |
+
"",
|
292 |
+
pythonwin_exe,
|
293 |
+
),
|
294 |
+
(
|
295 |
+
"Software\\Classes\\Python.File\\shell\\Edit with Pythonwin",
|
296 |
+
"command",
|
297 |
+
pythonwin_edit_command,
|
298 |
+
),
|
299 |
+
(
|
300 |
+
"Software\\Classes\\Python.NoConFile\\shell\\Edit with Pythonwin",
|
301 |
+
"command",
|
302 |
+
pythonwin_edit_command,
|
303 |
+
),
|
304 |
+
]
|
305 |
+
|
306 |
+
try:
|
307 |
+
if register:
|
308 |
+
for key, sub_key, val in keys_vals:
|
309 |
+
## Since winreg only uses the character Api functions, this can fail if Python
|
310 |
+
## is installed to a path containing non-ascii characters
|
311 |
+
hkey = winreg.CreateKey(classes_root, key)
|
312 |
+
if sub_key:
|
313 |
+
hkey = winreg.CreateKey(hkey, sub_key)
|
314 |
+
winreg.SetValueEx(hkey, None, 0, winreg.REG_SZ, val)
|
315 |
+
hkey.Close()
|
316 |
+
else:
|
317 |
+
for key, sub_key, val in keys_vals:
|
318 |
+
try:
|
319 |
+
if sub_key:
|
320 |
+
hkey = winreg.OpenKey(classes_root, key)
|
321 |
+
winreg.DeleteKey(hkey, sub_key)
|
322 |
+
hkey.Close()
|
323 |
+
winreg.DeleteKey(classes_root, key)
|
324 |
+
except OSError as why:
|
325 |
+
winerror = getattr(why, "winerror", why.errno)
|
326 |
+
if winerror != 2: # file not found
|
327 |
+
raise
|
328 |
+
finally:
|
329 |
+
# tell windows about the change
|
330 |
+
from win32com.shell import shell, shellcon
|
331 |
+
|
332 |
+
shell.SHChangeNotify(
|
333 |
+
shellcon.SHCNE_ASSOCCHANGED, shellcon.SHCNF_IDLIST, None, None
|
334 |
+
)
|
335 |
+
|
336 |
+
|
337 |
+
def get_shortcuts_folder():
|
338 |
+
if get_root_hkey() == winreg.HKEY_LOCAL_MACHINE:
|
339 |
+
try:
|
340 |
+
fldr = get_special_folder_path("CSIDL_COMMON_PROGRAMS")
|
341 |
+
except OSError:
|
342 |
+
# No CSIDL_COMMON_PROGRAMS on this platform
|
343 |
+
fldr = get_special_folder_path("CSIDL_PROGRAMS")
|
344 |
+
else:
|
345 |
+
# non-admin install - always goes in this user's start menu.
|
346 |
+
fldr = get_special_folder_path("CSIDL_PROGRAMS")
|
347 |
+
|
348 |
+
try:
|
349 |
+
install_group = winreg.QueryValue(
|
350 |
+
get_root_hkey(), root_key_name + "\\InstallPath\\InstallGroup"
|
351 |
+
)
|
352 |
+
except OSError:
|
353 |
+
vi = sys.version_info
|
354 |
+
install_group = "Python %d.%d" % (vi[0], vi[1])
|
355 |
+
return os.path.join(fldr, install_group)
|
356 |
+
|
357 |
+
|
358 |
+
# Get the system directory, which may be the Wow64 directory if we are a 32bit
|
359 |
+
# python on a 64bit OS.
|
360 |
+
def get_system_dir():
|
361 |
+
import win32api # we assume this exists.
|
362 |
+
|
363 |
+
try:
|
364 |
+
import pythoncom
|
365 |
+
import win32process
|
366 |
+
from win32com.shell import shell, shellcon
|
367 |
+
|
368 |
+
try:
|
369 |
+
if win32process.IsWow64Process():
|
370 |
+
return shell.SHGetSpecialFolderPath(0, shellcon.CSIDL_SYSTEMX86)
|
371 |
+
return shell.SHGetSpecialFolderPath(0, shellcon.CSIDL_SYSTEM)
|
372 |
+
except (pythoncom.com_error, win32process.error):
|
373 |
+
return win32api.GetSystemDirectory()
|
374 |
+
except ImportError:
|
375 |
+
return win32api.GetSystemDirectory()
|
376 |
+
|
377 |
+
|
378 |
+
def fixup_dbi():
|
379 |
+
# We used to have a dbi.pyd with our .pyd files, but now have a .py file.
|
380 |
+
# If the user didn't uninstall, they will find the .pyd which will cause
|
381 |
+
# problems - so handle that.
|
382 |
+
import win32api
|
383 |
+
import win32con
|
384 |
+
|
385 |
+
pyd_name = os.path.join(os.path.dirname(win32api.__file__), "dbi.pyd")
|
386 |
+
pyd_d_name = os.path.join(os.path.dirname(win32api.__file__), "dbi_d.pyd")
|
387 |
+
py_name = os.path.join(os.path.dirname(win32con.__file__), "dbi.py")
|
388 |
+
for this_pyd in (pyd_name, pyd_d_name):
|
389 |
+
this_dest = this_pyd + ".old"
|
390 |
+
if os.path.isfile(this_pyd) and os.path.isfile(py_name):
|
391 |
+
try:
|
392 |
+
if os.path.isfile(this_dest):
|
393 |
+
print(
|
394 |
+
"Old dbi '%s' already exists - deleting '%s'"
|
395 |
+
% (this_dest, this_pyd)
|
396 |
+
)
|
397 |
+
os.remove(this_pyd)
|
398 |
+
else:
|
399 |
+
os.rename(this_pyd, this_dest)
|
400 |
+
print("renamed '%s'->'%s.old'" % (this_pyd, this_pyd))
|
401 |
+
file_created(this_pyd + ".old")
|
402 |
+
except os.error as exc:
|
403 |
+
print("FAILED to rename '%s': %s" % (this_pyd, exc))
|
404 |
+
|
405 |
+
|
406 |
+
def install(lib_dir):
|
407 |
+
import traceback
|
408 |
+
|
409 |
+
# The .pth file is now installed as a regular file.
|
410 |
+
# Create the .pth file in the site-packages dir, and use only relative paths
|
411 |
+
# We used to write a .pth directly to sys.prefix - clobber it.
|
412 |
+
if os.path.isfile(os.path.join(sys.prefix, "pywin32.pth")):
|
413 |
+
os.unlink(os.path.join(sys.prefix, "pywin32.pth"))
|
414 |
+
# The .pth may be new and therefore not loaded in this session.
|
415 |
+
# Setup the paths just in case.
|
416 |
+
for name in "win32 win32\\lib Pythonwin".split():
|
417 |
+
sys.path.append(os.path.join(lib_dir, name))
|
418 |
+
# It is possible people with old versions installed with still have
|
419 |
+
# pywintypes and pythoncom registered. We no longer need this, and stale
|
420 |
+
# entries hurt us.
|
421 |
+
for name in "pythoncom pywintypes".split():
|
422 |
+
keyname = "Software\\Python\\PythonCore\\" + sys.winver + "\\Modules\\" + name
|
423 |
+
for root in winreg.HKEY_LOCAL_MACHINE, winreg.HKEY_CURRENT_USER:
|
424 |
+
try:
|
425 |
+
winreg.DeleteKey(root, keyname + "\\Debug")
|
426 |
+
except WindowsError:
|
427 |
+
pass
|
428 |
+
try:
|
429 |
+
winreg.DeleteKey(root, keyname)
|
430 |
+
except WindowsError:
|
431 |
+
pass
|
432 |
+
LoadSystemModule(lib_dir, "pywintypes")
|
433 |
+
LoadSystemModule(lib_dir, "pythoncom")
|
434 |
+
import win32api
|
435 |
+
|
436 |
+
# and now we can get the system directory:
|
437 |
+
files = glob.glob(os.path.join(lib_dir, "pywin32_system32\\*.*"))
|
438 |
+
if not files:
|
439 |
+
raise RuntimeError("No system files to copy!!")
|
440 |
+
# Try the system32 directory first - if that fails due to "access denied",
|
441 |
+
# it implies a non-admin user, and we use sys.prefix
|
442 |
+
for dest_dir in [get_system_dir(), sys.prefix]:
|
443 |
+
# and copy some files over there
|
444 |
+
worked = 0
|
445 |
+
try:
|
446 |
+
for fname in files:
|
447 |
+
base = os.path.basename(fname)
|
448 |
+
dst = os.path.join(dest_dir, base)
|
449 |
+
CopyTo("installing %s" % base, fname, dst)
|
450 |
+
if verbose:
|
451 |
+
print("Copied %s to %s" % (base, dst))
|
452 |
+
# Register the files with the uninstaller
|
453 |
+
file_created(dst)
|
454 |
+
worked = 1
|
455 |
+
# Nuke any other versions that may exist - having
|
456 |
+
# duplicates causes major headaches.
|
457 |
+
bad_dest_dirs = [
|
458 |
+
os.path.join(sys.prefix, "Library\\bin"),
|
459 |
+
os.path.join(sys.prefix, "Lib\\site-packages\\win32"),
|
460 |
+
]
|
461 |
+
if dest_dir != sys.prefix:
|
462 |
+
bad_dest_dirs.append(sys.prefix)
|
463 |
+
for bad_dest_dir in bad_dest_dirs:
|
464 |
+
bad_fname = os.path.join(bad_dest_dir, base)
|
465 |
+
if os.path.exists(bad_fname):
|
466 |
+
# let exceptions go here - delete must succeed
|
467 |
+
os.unlink(bad_fname)
|
468 |
+
if worked:
|
469 |
+
break
|
470 |
+
except win32api.error as details:
|
471 |
+
if details.winerror == 5:
|
472 |
+
# access denied - user not admin - try sys.prefix dir,
|
473 |
+
# but first check that a version doesn't already exist
|
474 |
+
# in that place - otherwise that one will still get used!
|
475 |
+
if os.path.exists(dst):
|
476 |
+
msg = (
|
477 |
+
"The file '%s' exists, but can not be replaced "
|
478 |
+
"due to insufficient permissions. You must "
|
479 |
+
"reinstall this software as an Administrator" % dst
|
480 |
+
)
|
481 |
+
print(msg)
|
482 |
+
raise RuntimeError(msg)
|
483 |
+
continue
|
484 |
+
raise
|
485 |
+
else:
|
486 |
+
raise RuntimeError(
|
487 |
+
"You don't have enough permissions to install the system files"
|
488 |
+
)
|
489 |
+
|
490 |
+
# Pythonwin 'compiles' config files - record them for uninstall.
|
491 |
+
pywin_dir = os.path.join(lib_dir, "Pythonwin", "pywin")
|
492 |
+
for fname in glob.glob(os.path.join(pywin_dir, "*.cfg")):
|
493 |
+
file_created(fname[:-1] + "c") # .cfg->.cfc
|
494 |
+
|
495 |
+
# Register our demo COM objects.
|
496 |
+
try:
|
497 |
+
try:
|
498 |
+
RegisterCOMObjects()
|
499 |
+
except win32api.error as details:
|
500 |
+
if details.winerror != 5: # ERROR_ACCESS_DENIED
|
501 |
+
raise
|
502 |
+
print("You do not have the permissions to install COM objects.")
|
503 |
+
print("The sample COM objects were not registered.")
|
504 |
+
except Exception:
|
505 |
+
print("FAILED to register the Python COM objects")
|
506 |
+
traceback.print_exc()
|
507 |
+
|
508 |
+
# There may be no main Python key in HKCU if, eg, an admin installed
|
509 |
+
# python itself.
|
510 |
+
winreg.CreateKey(get_root_hkey(), root_key_name)
|
511 |
+
|
512 |
+
chm_file = None
|
513 |
+
try:
|
514 |
+
chm_file = RegisterHelpFile(True, lib_dir)
|
515 |
+
except Exception:
|
516 |
+
print("Failed to register help file")
|
517 |
+
traceback.print_exc()
|
518 |
+
else:
|
519 |
+
if verbose:
|
520 |
+
print("Registered help file")
|
521 |
+
|
522 |
+
# misc other fixups.
|
523 |
+
fixup_dbi()
|
524 |
+
|
525 |
+
# Register Pythonwin in context menu
|
526 |
+
try:
|
527 |
+
RegisterPythonwin(True, lib_dir)
|
528 |
+
except Exception:
|
529 |
+
print("Failed to register pythonwin as editor")
|
530 |
+
traceback.print_exc()
|
531 |
+
else:
|
532 |
+
if verbose:
|
533 |
+
print("Pythonwin has been registered in context menu")
|
534 |
+
|
535 |
+
# Create the win32com\gen_py directory.
|
536 |
+
make_dir = os.path.join(lib_dir, "win32com", "gen_py")
|
537 |
+
if not os.path.isdir(make_dir):
|
538 |
+
if verbose:
|
539 |
+
print("Creating directory %s" % (make_dir,))
|
540 |
+
directory_created(make_dir)
|
541 |
+
os.mkdir(make_dir)
|
542 |
+
|
543 |
+
try:
|
544 |
+
# create shortcuts
|
545 |
+
# CSIDL_COMMON_PROGRAMS only available works on NT/2000/XP, and
|
546 |
+
# will fail there if the user has no admin rights.
|
547 |
+
fldr = get_shortcuts_folder()
|
548 |
+
# If the group doesn't exist, then we don't make shortcuts - its
|
549 |
+
# possible that this isn't a "normal" install.
|
550 |
+
if os.path.isdir(fldr):
|
551 |
+
dst = os.path.join(fldr, "PythonWin.lnk")
|
552 |
+
create_shortcut(
|
553 |
+
os.path.join(lib_dir, "Pythonwin\\Pythonwin.exe"),
|
554 |
+
"The Pythonwin IDE",
|
555 |
+
dst,
|
556 |
+
"",
|
557 |
+
sys.prefix,
|
558 |
+
)
|
559 |
+
file_created(dst)
|
560 |
+
if verbose:
|
561 |
+
print("Shortcut for Pythonwin created")
|
562 |
+
# And the docs.
|
563 |
+
if chm_file:
|
564 |
+
dst = os.path.join(fldr, "Python for Windows Documentation.lnk")
|
565 |
+
doc = "Documentation for the PyWin32 extensions"
|
566 |
+
create_shortcut(chm_file, doc, dst)
|
567 |
+
file_created(dst)
|
568 |
+
if verbose:
|
569 |
+
print("Shortcut to documentation created")
|
570 |
+
else:
|
571 |
+
if verbose:
|
572 |
+
print("Can't install shortcuts - %r is not a folder" % (fldr,))
|
573 |
+
except Exception as details:
|
574 |
+
print(details)
|
575 |
+
|
576 |
+
# importing win32com.client ensures the gen_py dir created - not strictly
|
577 |
+
# necessary to do now, but this makes the installation "complete"
|
578 |
+
try:
|
579 |
+
import win32com.client # noqa
|
580 |
+
except ImportError:
|
581 |
+
# Don't let this error sound fatal
|
582 |
+
pass
|
583 |
+
print("The pywin32 extensions were successfully installed.")
|
584 |
+
|
585 |
+
if is_bdist_wininst:
|
586 |
+
# Open a web page with info about the .exe installers being deprecated.
|
587 |
+
import webbrowser
|
588 |
+
|
589 |
+
try:
|
590 |
+
webbrowser.open("https://mhammond.github.io/pywin32_installers.html")
|
591 |
+
except webbrowser.Error:
|
592 |
+
print("Please visit https://mhammond.github.io/pywin32_installers.html")
|
593 |
+
|
594 |
+
|
595 |
+
def uninstall(lib_dir):
|
596 |
+
# First ensure our system modules are loaded from pywin32_system, so
|
597 |
+
# we can remove the ones we copied...
|
598 |
+
LoadSystemModule(lib_dir, "pywintypes")
|
599 |
+
LoadSystemModule(lib_dir, "pythoncom")
|
600 |
+
|
601 |
+
try:
|
602 |
+
RegisterCOMObjects(False)
|
603 |
+
except Exception as why:
|
604 |
+
print("Failed to unregister COM objects: %s" % (why,))
|
605 |
+
|
606 |
+
try:
|
607 |
+
RegisterHelpFile(False, lib_dir)
|
608 |
+
except Exception as why:
|
609 |
+
print("Failed to unregister help file: %s" % (why,))
|
610 |
+
else:
|
611 |
+
if verbose:
|
612 |
+
print("Unregistered help file")
|
613 |
+
|
614 |
+
try:
|
615 |
+
RegisterPythonwin(False, lib_dir)
|
616 |
+
except Exception as why:
|
617 |
+
print("Failed to unregister Pythonwin: %s" % (why,))
|
618 |
+
else:
|
619 |
+
if verbose:
|
620 |
+
print("Unregistered Pythonwin")
|
621 |
+
|
622 |
+
try:
|
623 |
+
# remove gen_py directory.
|
624 |
+
gen_dir = os.path.join(lib_dir, "win32com", "gen_py")
|
625 |
+
if os.path.isdir(gen_dir):
|
626 |
+
shutil.rmtree(gen_dir)
|
627 |
+
if verbose:
|
628 |
+
print("Removed directory %s" % (gen_dir,))
|
629 |
+
|
630 |
+
# Remove pythonwin compiled "config" files.
|
631 |
+
pywin_dir = os.path.join(lib_dir, "Pythonwin", "pywin")
|
632 |
+
for fname in glob.glob(os.path.join(pywin_dir, "*.cfc")):
|
633 |
+
os.remove(fname)
|
634 |
+
|
635 |
+
# The dbi.pyd.old files we may have created.
|
636 |
+
try:
|
637 |
+
os.remove(os.path.join(lib_dir, "win32", "dbi.pyd.old"))
|
638 |
+
except os.error:
|
639 |
+
pass
|
640 |
+
try:
|
641 |
+
os.remove(os.path.join(lib_dir, "win32", "dbi_d.pyd.old"))
|
642 |
+
except os.error:
|
643 |
+
pass
|
644 |
+
|
645 |
+
except Exception as why:
|
646 |
+
print("Failed to remove misc files: %s" % (why,))
|
647 |
+
|
648 |
+
try:
|
649 |
+
fldr = get_shortcuts_folder()
|
650 |
+
for link in ("PythonWin.lnk", "Python for Windows Documentation.lnk"):
|
651 |
+
fqlink = os.path.join(fldr, link)
|
652 |
+
if os.path.isfile(fqlink):
|
653 |
+
os.remove(fqlink)
|
654 |
+
if verbose:
|
655 |
+
print("Removed %s" % (link,))
|
656 |
+
except Exception as why:
|
657 |
+
print("Failed to remove shortcuts: %s" % (why,))
|
658 |
+
# Now remove the system32 files.
|
659 |
+
files = glob.glob(os.path.join(lib_dir, "pywin32_system32\\*.*"))
|
660 |
+
# Try the system32 directory first - if that fails due to "access denied",
|
661 |
+
# it implies a non-admin user, and we use sys.prefix
|
662 |
+
try:
|
663 |
+
for dest_dir in [get_system_dir(), sys.prefix]:
|
664 |
+
# and copy some files over there
|
665 |
+
worked = 0
|
666 |
+
for fname in files:
|
667 |
+
base = os.path.basename(fname)
|
668 |
+
dst = os.path.join(dest_dir, base)
|
669 |
+
if os.path.isfile(dst):
|
670 |
+
try:
|
671 |
+
os.remove(dst)
|
672 |
+
worked = 1
|
673 |
+
if verbose:
|
674 |
+
print("Removed file %s" % (dst))
|
675 |
+
except Exception:
|
676 |
+
print("FAILED to remove %s" % (dst,))
|
677 |
+
if worked:
|
678 |
+
break
|
679 |
+
except Exception as why:
|
680 |
+
print("FAILED to remove system files: %s" % (why,))
|
681 |
+
|
682 |
+
|
683 |
+
# NOTE: If this script is run from inside the bdist_wininst created
|
684 |
+
# binary installer or uninstaller, the command line args are either
|
685 |
+
# '-install' or '-remove'.
|
686 |
+
|
687 |
+
# Important: From inside the binary installer this script MUST NOT
|
688 |
+
# call sys.exit() or raise SystemExit, otherwise not only this script
|
689 |
+
# but also the installer will terminate! (Is there a way to prevent
|
690 |
+
# this from the bdist_wininst C code?)
|
691 |
+
|
692 |
+
|
693 |
+
def verify_destination(location):
|
694 |
+
if not os.path.isdir(location):
|
695 |
+
raise argparse.ArgumentTypeError('Path "{}" does not exist!'.format(location))
|
696 |
+
return location
|
697 |
+
|
698 |
+
|
699 |
+
def main():
|
700 |
+
import argparse
|
701 |
+
|
702 |
+
parser = argparse.ArgumentParser(
|
703 |
+
formatter_class=argparse.RawDescriptionHelpFormatter,
|
704 |
+
description="""A post-install script for the pywin32 extensions.
|
705 |
+
|
706 |
+
* Typical usage:
|
707 |
+
|
708 |
+
> python pywin32_postinstall.py -install
|
709 |
+
|
710 |
+
If you installed pywin32 via a .exe installer, this should be run
|
711 |
+
automatically after installation, but if it fails you can run it again.
|
712 |
+
|
713 |
+
If you installed pywin32 via PIP, you almost certainly need to run this to
|
714 |
+
setup the environment correctly.
|
715 |
+
|
716 |
+
Execute with script with a '-install' parameter, to ensure the environment
|
717 |
+
is setup correctly.
|
718 |
+
""",
|
719 |
+
)
|
720 |
+
parser.add_argument(
|
721 |
+
"-install",
|
722 |
+
default=False,
|
723 |
+
action="store_true",
|
724 |
+
help="Configure the Python environment correctly for pywin32.",
|
725 |
+
)
|
726 |
+
parser.add_argument(
|
727 |
+
"-remove",
|
728 |
+
default=False,
|
729 |
+
action="store_true",
|
730 |
+
help="Try and remove everything that was installed or copied.",
|
731 |
+
)
|
732 |
+
parser.add_argument(
|
733 |
+
"-wait",
|
734 |
+
type=int,
|
735 |
+
help="Wait for the specified process to terminate before starting.",
|
736 |
+
)
|
737 |
+
parser.add_argument(
|
738 |
+
"-silent",
|
739 |
+
default=False,
|
740 |
+
action="store_true",
|
741 |
+
help='Don\'t display the "Abort/Retry/Ignore" dialog for files in use.',
|
742 |
+
)
|
743 |
+
parser.add_argument(
|
744 |
+
"-quiet",
|
745 |
+
default=False,
|
746 |
+
action="store_true",
|
747 |
+
help="Don't display progress messages.",
|
748 |
+
)
|
749 |
+
parser.add_argument(
|
750 |
+
"-destination",
|
751 |
+
default=sysconfig.get_paths()["platlib"],
|
752 |
+
type=verify_destination,
|
753 |
+
help="Location of the PyWin32 installation",
|
754 |
+
)
|
755 |
+
|
756 |
+
args = parser.parse_args()
|
757 |
+
|
758 |
+
if not args.quiet:
|
759 |
+
print("Parsed arguments are: {}".format(args))
|
760 |
+
|
761 |
+
if not args.install ^ args.remove:
|
762 |
+
parser.error("You need to either choose to -install or -remove!")
|
763 |
+
|
764 |
+
if args.wait is not None:
|
765 |
+
try:
|
766 |
+
os.waitpid(args.wait, 0)
|
767 |
+
except os.error:
|
768 |
+
# child already dead
|
769 |
+
pass
|
770 |
+
|
771 |
+
silent = args.silent
|
772 |
+
verbose = not args.quiet
|
773 |
+
|
774 |
+
if args.install:
|
775 |
+
install(args.destination)
|
776 |
+
|
777 |
+
if args.remove:
|
778 |
+
if not is_bdist_wininst:
|
779 |
+
uninstall(args.destination)
|
780 |
+
|
781 |
+
|
782 |
+
if __name__ == "__main__":
|
783 |
+
main()
|
rag/Scripts/pywin32_testall.py
ADDED
@@ -0,0 +1,124 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""A test runner for pywin32"""
|
2 |
+
import os
|
3 |
+
import site
|
4 |
+
import subprocess
|
5 |
+
import sys
|
6 |
+
|
7 |
+
# locate the dirs based on where this script is - it may be either in the
|
8 |
+
# source tree, or in an installed Python 'Scripts' tree.
|
9 |
+
this_dir = os.path.dirname(__file__)
|
10 |
+
site_packages = [
|
11 |
+
site.getusersitepackages(),
|
12 |
+
] + site.getsitepackages()
|
13 |
+
|
14 |
+
failures = []
|
15 |
+
|
16 |
+
|
17 |
+
# Run a test using subprocess and wait for the result.
|
18 |
+
# If we get an returncode != 0, we know that there was an error, but we don't
|
19 |
+
# abort immediately - we run as many tests as we can.
|
20 |
+
def run_test(script, cmdline_extras):
|
21 |
+
dirname, scriptname = os.path.split(script)
|
22 |
+
# some tests prefer to be run from their directory.
|
23 |
+
cmd = [sys.executable, "-u", scriptname] + cmdline_extras
|
24 |
+
print("--- Running '%s' ---" % script)
|
25 |
+
sys.stdout.flush()
|
26 |
+
result = subprocess.run(cmd, check=False, cwd=dirname)
|
27 |
+
print("*** Test script '%s' exited with %s" % (script, result.returncode))
|
28 |
+
sys.stdout.flush()
|
29 |
+
if result.returncode:
|
30 |
+
failures.append(script)
|
31 |
+
|
32 |
+
|
33 |
+
def find_and_run(possible_locations, extras):
|
34 |
+
for maybe in possible_locations:
|
35 |
+
if os.path.isfile(maybe):
|
36 |
+
run_test(maybe, extras)
|
37 |
+
break
|
38 |
+
else:
|
39 |
+
raise RuntimeError(
|
40 |
+
"Failed to locate a test script in one of %s" % possible_locations
|
41 |
+
)
|
42 |
+
|
43 |
+
|
44 |
+
def main():
|
45 |
+
import argparse
|
46 |
+
|
47 |
+
code_directories = [this_dir] + site_packages
|
48 |
+
|
49 |
+
parser = argparse.ArgumentParser(
|
50 |
+
description="A script to trigger tests in all subprojects of PyWin32."
|
51 |
+
)
|
52 |
+
parser.add_argument(
|
53 |
+
"-no-user-interaction",
|
54 |
+
default=False,
|
55 |
+
action="store_true",
|
56 |
+
help="(This is now the default - use `-user-interaction` to include them)",
|
57 |
+
)
|
58 |
+
|
59 |
+
parser.add_argument(
|
60 |
+
"-user-interaction",
|
61 |
+
action="store_true",
|
62 |
+
help="Include tests which require user interaction",
|
63 |
+
)
|
64 |
+
|
65 |
+
parser.add_argument(
|
66 |
+
"-skip-adodbapi",
|
67 |
+
default=False,
|
68 |
+
action="store_true",
|
69 |
+
help="Skip the adodbapi tests; useful for CI where there's no provider",
|
70 |
+
)
|
71 |
+
|
72 |
+
args, remains = parser.parse_known_args()
|
73 |
+
|
74 |
+
# win32, win32ui / Pythonwin
|
75 |
+
|
76 |
+
extras = []
|
77 |
+
if args.user_interaction:
|
78 |
+
extras += ["-user-interaction"]
|
79 |
+
extras.extend(remains)
|
80 |
+
scripts = [
|
81 |
+
"win32/test/testall.py",
|
82 |
+
"Pythonwin/pywin/test/all.py",
|
83 |
+
]
|
84 |
+
for script in scripts:
|
85 |
+
maybes = [os.path.join(directory, script) for directory in code_directories]
|
86 |
+
find_and_run(maybes, extras)
|
87 |
+
|
88 |
+
# win32com
|
89 |
+
maybes = [
|
90 |
+
os.path.join(directory, "win32com", "test", "testall.py")
|
91 |
+
for directory in [
|
92 |
+
os.path.join(this_dir, "com"),
|
93 |
+
]
|
94 |
+
+ site_packages
|
95 |
+
]
|
96 |
+
extras = remains + ["1"] # only run "level 1" tests in CI
|
97 |
+
find_and_run(maybes, extras)
|
98 |
+
|
99 |
+
# adodbapi
|
100 |
+
if not args.skip_adodbapi:
|
101 |
+
maybes = [
|
102 |
+
os.path.join(directory, "adodbapi", "test", "adodbapitest.py")
|
103 |
+
for directory in code_directories
|
104 |
+
]
|
105 |
+
find_and_run(maybes, remains)
|
106 |
+
# This script has a hard-coded sql server name in it, (and markh typically
|
107 |
+
# doesn't have a different server to test on) but there is now supposed to be a server out there on the Internet
|
108 |
+
# just to run these tests, so try it...
|
109 |
+
maybes = [
|
110 |
+
os.path.join(directory, "adodbapi", "test", "test_adodbapi_dbapi20.py")
|
111 |
+
for directory in code_directories
|
112 |
+
]
|
113 |
+
find_and_run(maybes, remains)
|
114 |
+
|
115 |
+
if failures:
|
116 |
+
print("The following scripts failed")
|
117 |
+
for failure in failures:
|
118 |
+
print(">", failure)
|
119 |
+
sys.exit(1)
|
120 |
+
print("All tests passed \\o/")
|
121 |
+
|
122 |
+
|
123 |
+
if __name__ == "__main__":
|
124 |
+
main()
|
rag/Scripts/streamlit.cmd
ADDED
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
rem Copyright (c) Streamlit Inc. (2018-2022) Snowflake Inc. (2022)
|
2 |
+
rem
|
3 |
+
rem Licensed under the Apache License, Version 2.0 (the "License");
|
4 |
+
rem you may not use this file except in compliance with the License.
|
5 |
+
rem You may obtain a copy of the License at
|
6 |
+
rem
|
7 |
+
rem http://www.apache.org/licenses/LICENSE-2.0
|
8 |
+
rem
|
9 |
+
rem Unless required by applicable law or agreed to in writing, software
|
10 |
+
rem distributed under the License is distributed on an "AS IS" BASIS,
|
11 |
+
rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12 |
+
rem See the License for the specific language governing permissions and
|
13 |
+
rem limitations under the License.
|
14 |
+
|
15 |
+
@echo OFF
|
16 |
+
python -m streamlit %*
|
rag/Scripts/streamlit.exe
ADDED
Binary file (106 kB). View file
|
|
rag/Scripts/torchrun.exe
ADDED
Binary file (106 kB). View file
|
|
rag/Scripts/tqdm.exe
ADDED
Binary file (106 kB). View file
|
|
rag/Scripts/transformers-cli.exe
ADDED
Binary file (106 kB). View file
|
|
rag/Scripts/watchmedo.exe
ADDED
Binary file (106 kB). View file
|
|
rag/etc/jupyter/nbconfig/notebook.d/pydeck.json
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"load_extensions": {
|
3 |
+
"pydeck/extension": true
|
4 |
+
}
|
5 |
+
}
|
rag/pyvenv.cfg
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
home = C:\Python39
|
2 |
+
include-system-site-packages = false
|
3 |
+
version = 3.9.8
|
rag/share/jupyter/kernels/python3/kernel.json
ADDED
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"argv": [
|
3 |
+
"python",
|
4 |
+
"-m",
|
5 |
+
"ipykernel_launcher",
|
6 |
+
"-f",
|
7 |
+
"{connection_file}"
|
8 |
+
],
|
9 |
+
"display_name": "Python 3 (ipykernel)",
|
10 |
+
"language": "python",
|
11 |
+
"metadata": {
|
12 |
+
"debugger": true
|
13 |
+
}
|
14 |
+
}
|
rag/share/jupyter/kernels/python3/logo-32x32.png
ADDED
rag/share/jupyter/kernels/python3/logo-64x64.png
ADDED
rag/share/jupyter/kernels/python3/logo-svg.svg
ADDED
rag/share/jupyter/nbextensions/pydeck/extensionRequires.js
ADDED
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/* eslint-disable */
|
2 |
+
define(function() {
|
3 |
+
'use strict';
|
4 |
+
requirejs.config({
|
5 |
+
map: {
|
6 |
+
'*': {
|
7 |
+
'@deck.gl/jupyter-widget': 'nbextensions/pydeck/index'
|
8 |
+
}
|
9 |
+
}
|
10 |
+
});
|
11 |
+
// Export the required load_ipython_extension function
|
12 |
+
return {
|
13 |
+
load_ipython_extension: function() {}
|
14 |
+
};
|
15 |
+
});
|
rag/share/jupyter/nbextensions/pydeck/index.js
ADDED
The diff for this file is too large to render.
See raw diff
|
|
rag/share/jupyter/nbextensions/pydeck/index.js.map
ADDED
The diff for this file is too large to render.
See raw diff
|
|