datastx commited on
Commit
ede7310
1 Parent(s): ee4aa0b
Files changed (5) hide show
  1. .gitignore +4 -0
  2. Makefile.venv +272 -0
  3. app.py +75 -0
  4. makefile +14 -0
  5. requirements.txt +19 -0
.gitignore ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ .venv
2
+ .env
3
+ __pycache__
4
+ models
Makefile.venv ADDED
@@ -0,0 +1,272 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #
2
+ # SEAMLESSLY MANAGE PYTHON VIRTUAL ENVIRONMENT WITH A MAKEFILE
3
+ #
4
+ # https://github.com/sio/Makefile.venv v2023.04.17
5
+ #
6
+ #
7
+ # Insert `include Makefile.venv` at the bottom of your Makefile to enable these
8
+ # rules.
9
+ #
10
+ # When writing your Makefile use '$(VENV)/python' to refer to the Python
11
+ # interpreter within virtual environment and '$(VENV)/executablename' for any
12
+ # other executable in venv.
13
+ #
14
+ # This Makefile provides the following targets:
15
+ # venv
16
+ # Use this as a dependency for any target that requires virtual
17
+ # environment to be created and configured
18
+ # python, ipython
19
+ # Use these to launch interactive Python shell within virtual environment
20
+ # shell, bash, zsh
21
+ # Launch interactive command line shell. "shell" target launches the
22
+ # default shell Makefile executes its rules in (usually /bin/sh).
23
+ # "bash" and "zsh" can be used to refer to the specific desired shell.
24
+ # show-venv
25
+ # Show versions of Python and pip, and the path to the virtual environment
26
+ # clean-venv
27
+ # Remove virtual environment
28
+ # $(VENV)/executable_name
29
+ # Install `executable_name` with pip. Only packages with names matching
30
+ # the name of the corresponding executable are supported.
31
+ # Use this as a lightweight mechanism for development dependencies
32
+ # tracking. E.g. for one-off tools that are not required in every
33
+ # developer's environment, therefore are not included into
34
+ # requirements.txt or setup.py.
35
+ # Note:
36
+ # Rules using such target or dependency MUST be defined below
37
+ # `include` directive to make use of correct $(VENV) value.
38
+ # Example:
39
+ # codestyle: $(VENV)/pyflakes
40
+ # $(VENV)/pyflakes .
41
+ # See `ipython` target below for another example.
42
+ #
43
+ # This Makefile can be configured via following variables:
44
+ # PY
45
+ # Command name for system Python interpreter. It is used only initially to
46
+ # create the virtual environment
47
+ # Default: python3
48
+ # REQUIREMENTS_TXT
49
+ # Space separated list of paths to requirements.txt files.
50
+ # Paths are resolved relative to current working directory.
51
+ # Default: requirements.txt
52
+ #
53
+ # Non-existent files are treated as hard dependencies,
54
+ # recipes for creating such files must be provided by the main Makefile.
55
+ # Providing empty value (REQUIREMENTS_TXT=) turns off processing of
56
+ # requirements.txt even when the file exists.
57
+ # SETUP_PY, SETUP_CFG, PYPROJECT_TOML, VENV_LOCAL_PACKAGE
58
+ # Space separated list of paths to files that contain build instructions
59
+ # for local Python packages. Corresponding packages will be installed
60
+ # into venv in editable mode along with all their dependencies.
61
+ # Default: setup.py setup.cfg pyproject.toml (whichever present)
62
+ #
63
+ # Non-existent and empty values are treated in the same way as for REQUIREMENTS_TXT.
64
+ # WORKDIR
65
+ # Parent directory for the virtual environment.
66
+ # Default: current working directory.
67
+ # VENVDIR
68
+ # Python virtual environment directory.
69
+ # Default: $(WORKDIR)/.venv
70
+ #
71
+ # This Makefile was written for GNU Make and may not work with other make
72
+ # implementations.
73
+ #
74
+ #
75
+ # Copyright (c) 2019-2023 Vitaly Potyarkin
76
+ #
77
+ # Licensed under the Apache License, Version 2.0
78
+ # <http://www.apache.org/licenses/LICENSE-2.0>
79
+ #
80
+
81
+
82
+ #
83
+ # Configuration variables
84
+ #
85
+
86
+ WORKDIR?=.
87
+ VENVDIR?=$(WORKDIR)/.venv
88
+ REQUIREMENTS_TXT?=$(wildcard requirements.txt) # Multiple paths are supported (space separated)
89
+ SETUP_PY?=$(wildcard setup.py) # Multiple paths are supported (space separated)
90
+ SETUP_CFG?=$(foreach s,$(SETUP_PY),$(wildcard $(patsubst %setup.py,%setup.cfg,$(s))))
91
+ PYPROJECT_TOML?=$(wildcard pyproject.toml)
92
+ VENV_LOCAL_PACKAGE?=$(SETUP_PY) $(SETUP_CFG) $(PYPROJECT_TOML)
93
+ MARKER=.initialized-with-Makefile.venv
94
+
95
+
96
+ #
97
+ # Python interpreter detection
98
+ #
99
+
100
+ _PY_AUTODETECT_MSG=Detected Python interpreter: $(PY). Use PY environment variable to override
101
+
102
+ ifeq (ok,$(shell test -e /dev/null 2>&1 && echo ok))
103
+ NULL_STDERR=2>/dev/null
104
+ else
105
+ NULL_STDERR=2>NUL
106
+ endif
107
+
108
+ ifndef PY
109
+ _PY_OPTION:=python3
110
+ ifeq (ok,$(shell $(_PY_OPTION) -c "print('ok')" $(NULL_STDERR)))
111
+ PY=$(_PY_OPTION)
112
+ endif
113
+ endif
114
+
115
+ ifndef PY
116
+ _PY_OPTION:=$(VENVDIR)/bin/python
117
+ ifeq (ok,$(shell $(_PY_OPTION) -c "print('ok')" $(NULL_STDERR)))
118
+ PY=$(_PY_OPTION)
119
+ $(info $(_PY_AUTODETECT_MSG))
120
+ endif
121
+ endif
122
+
123
+ ifndef PY
124
+ _PY_OPTION:=$(subst /,\,$(VENVDIR)/Scripts/python)
125
+ ifeq (ok,$(shell $(_PY_OPTION) -c "print('ok')" $(NULL_STDERR)))
126
+ PY=$(_PY_OPTION)
127
+ $(info $(_PY_AUTODETECT_MSG))
128
+ endif
129
+ endif
130
+
131
+ ifndef PY
132
+ _PY_OPTION:=py -3
133
+ ifeq (ok,$(shell $(_PY_OPTION) -c "print('ok')" $(NULL_STDERR)))
134
+ PY=$(_PY_OPTION)
135
+ $(info $(_PY_AUTODETECT_MSG))
136
+ endif
137
+ endif
138
+
139
+ ifndef PY
140
+ _PY_OPTION:=python
141
+ ifeq (ok,$(shell $(_PY_OPTION) -c "print('ok')" $(NULL_STDERR)))
142
+ PY=$(_PY_OPTION)
143
+ $(info $(_PY_AUTODETECT_MSG))
144
+ endif
145
+ endif
146
+
147
+ ifndef PY
148
+ define _PY_AUTODETECT_ERR
149
+ Could not detect Python interpreter automatically.
150
+ Please specify path to interpreter via PY environment variable.
151
+ endef
152
+ $(error $(_PY_AUTODETECT_ERR))
153
+ endif
154
+
155
+
156
+ #
157
+ # Internal variable resolution
158
+ #
159
+
160
+ VENV=$(VENVDIR)/bin
161
+ EXE=
162
+ # Detect windows
163
+ ifeq (win32,$(shell $(PY) -c "import __future__, sys; print(sys.platform)"))
164
+ VENV=$(VENVDIR)/Scripts
165
+ EXE=.exe
166
+ endif
167
+
168
+ touch=touch $(1)
169
+ ifeq (,$(shell command -v touch $(NULL_STDERR)))
170
+ # https://ss64.com/nt/touch.html
171
+ touch=type nul >> $(subst /,\,$(1)) && copy /y /b $(subst /,\,$(1))+,, $(subst /,\,$(1))
172
+ endif
173
+
174
+ RM?=rm -f
175
+ ifeq (,$(shell command -v $(firstword $(RM)) $(NULL_STDERR)))
176
+ RMDIR:=rd /s /q
177
+ else
178
+ RMDIR:=$(RM) -r
179
+ endif
180
+
181
+
182
+ #
183
+ # Virtual environment
184
+ #
185
+
186
+ .PHONY: venv
187
+ venv: $(VENV)/$(MARKER)
188
+
189
+ .PHONY: clean-venv
190
+ clean-venv:
191
+ -$(RMDIR) "$(VENVDIR)"
192
+
193
+ .PHONY: show-venv
194
+ show-venv: venv
195
+ @$(VENV)/python -c "import sys; print('Python ' + sys.version.replace('\n',''))"
196
+ @$(VENV)/pip --version
197
+ @echo venv: $(VENVDIR)
198
+
199
+ .PHONY: debug-venv
200
+ debug-venv:
201
+ @echo "PATH (Shell)=$$PATH"
202
+ @$(MAKE) --version
203
+ $(info PATH (GNU Make)="$(PATH)")
204
+ $(info SHELL="$(SHELL)")
205
+ $(info PY="$(PY)")
206
+ $(info REQUIREMENTS_TXT="$(REQUIREMENTS_TXT)")
207
+ $(info VENV_LOCAL_PACKAGE="$(VENV_LOCAL_PACKAGE)")
208
+ $(info VENVDIR="$(VENVDIR)")
209
+ $(info VENVDEPENDS="$(VENVDEPENDS)")
210
+ $(info WORKDIR="$(WORKDIR)")
211
+
212
+
213
+ #
214
+ # Dependencies
215
+ #
216
+
217
+ ifneq ($(strip $(REQUIREMENTS_TXT)),)
218
+ VENVDEPENDS+=$(REQUIREMENTS_TXT)
219
+ endif
220
+
221
+ ifneq ($(strip $(VENV_LOCAL_PACKAGE)),)
222
+ VENVDEPENDS+=$(VENV_LOCAL_PACKAGE)
223
+ endif
224
+
225
+ $(VENV):
226
+ $(PY) -m venv $(VENVDIR)
227
+ $(VENV)/python -m pip install --upgrade pip setuptools wheel
228
+
229
+ $(VENV)/$(MARKER): $(VENVDEPENDS) | $(VENV)
230
+ ifneq ($(strip $(REQUIREMENTS_TXT)),)
231
+ $(VENV)/pip install $(foreach path,$(REQUIREMENTS_TXT),-r $(path))
232
+ endif
233
+ ifneq ($(strip $(VENV_LOCAL_PACKAGE)),)
234
+ $(VENV)/pip install $(foreach path,$(sort $(VENV_LOCAL_PACKAGE)),-e $(dir $(path)))
235
+ endif
236
+ $(call touch,$(VENV)/$(MARKER))
237
+
238
+
239
+ #
240
+ # Interactive shells
241
+ #
242
+
243
+ .PHONY: python
244
+ python: venv
245
+ exec $(VENV)/python
246
+
247
+ .PHONY: ipython
248
+ ipython: $(VENV)/ipython
249
+ exec $(VENV)/ipython
250
+
251
+ .PHONY: shell
252
+ shell: venv
253
+ . $(VENV)/activate && exec $(notdir $(SHELL))
254
+
255
+ .PHONY: bash zsh
256
+ bash zsh: venv
257
+ . $(VENV)/activate && exec $@
258
+
259
+
260
+ #
261
+ # Commandline tools (wildcard rule, executable name must match package name)
262
+ #
263
+
264
+ ifneq ($(EXE),)
265
+ $(VENV)/%: $(VENV)/%$(EXE) ;
266
+ .PHONY: $(VENV)/%
267
+ .PRECIOUS: $(VENV)/%$(EXE)
268
+ endif
269
+
270
+ $(VENV)/%$(EXE): $(VENV)/$(MARKER)
271
+ $(VENV)/pip install --upgrade $*
272
+ $(call touch,$@)
app.py ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from langchain.prompts import PromptTemplate
3
+ from langchain.llms import CTransformers
4
+
5
+ # Load model directly
6
+ # Load model directly
7
+ from transformers import AutoModel
8
+
9
+
10
+ #Function to get the response back
11
+ def getLLMResponse(form_input,email_sender,email_recipient,email_style):
12
+ #llm = OpenAI(temperature=.9, model="text-davinci-003")
13
+
14
+ # Wrapper for Llama-2-7B-Chat, Running Llama 2 on CPU
15
+
16
+ #Quantization is reducing model precision by converting weights from 16-bit floats to 8-bit integers,
17
+ #enabling efficient deployment on resource-limited devices, reducing model size, and maintaining performance.
18
+
19
+ #C Transformers offers support for various open-source models,
20
+ #among them popular ones like Llama, GPT4All-J, MPT, and Falcon.
21
+
22
+
23
+ #C Transformers is the Python library that provides bindings for transformer models implemented in C/C++ using the GGML library
24
+
25
+ llm = CTransformers(model='models/llama-2-7b-chat.ggmlv3.q8_0.bin', #https://huggingface.co/TheBloke/Llama-2-7B-Chat-GGML/tree/main
26
+ model_type='llama',
27
+ config={'max_new_tokens': 256,
28
+ 'temperature': 0.01})
29
+
30
+ # llm = AutoModel.from_pretrained("TheBloke/Llama-2-7B-Chat-GGML")
31
+ #Template for building the PROMPT
32
+ template = """
33
+ Write a email with {style} style and includes topic :{email_topic}.\n\nSender: {sender}\nRecipient: {recipient}
34
+ \n\nEmail Text:
35
+
36
+ """
37
+
38
+ #Creating the final PROMPT
39
+ prompt = PromptTemplate(
40
+ input_variables=["style","email_topic","sender","recipient"],
41
+ template=template,)
42
+
43
+
44
+ #Generating the response using LLM
45
+ response=llm(prompt.format(email_topic=form_input,sender=email_sender,recipient=email_recipient,style=email_style))
46
+ print(response)
47
+
48
+ return response
49
+
50
+
51
+ st.set_page_config(page_title="Generate Emails",
52
+ page_icon='📧',
53
+ layout='centered',
54
+ initial_sidebar_state='collapsed')
55
+ st.header("Generate Emails 📧")
56
+
57
+ form_input = st.text_area('Enter the email topic', height=275)
58
+
59
+ #Creating columns for the UI - To receive inputs from user
60
+ col1, col2, col3 = st.columns([10, 10, 5])
61
+ with col1:
62
+ email_sender = st.text_input('Sender Name')
63
+ with col2:
64
+ email_recipient = st.text_input('Recipient Name')
65
+ with col3:
66
+ email_style = st.selectbox('Writing Style',
67
+ ('Formal', 'Appreciating', 'Not Satisfied', 'Neutral'),
68
+ index=0)
69
+
70
+
71
+ submit = st.button("Generate")
72
+
73
+ #When 'Generate' button is clicked, execute the below code
74
+ if submit:
75
+ st.write(getLLMResponse(form_input,email_sender,email_recipient,email_style))
makefile ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+
3
+ PYTHON_BINARY = $(VENV)/python
4
+ STREAMLIT_BINARY = $(VENV)/streamlit
5
+
6
+
7
+ re-venv: clean-venv venv
8
+
9
+ run: venv
10
+ $(PYTHON_BINARY) app.py
11
+ $(STREAMLIT_BINARY) run app.py
12
+
13
+
14
+ include Makefile.venv
requirements.txt ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ langchain
2
+ openai
3
+ Streamlit
4
+ huggingface_hub
5
+ python-dotenv
6
+ watchdog
7
+ tiktoken
8
+ pinecone-client
9
+ pypdf
10
+ joblib
11
+ pandas
12
+ scikit-learn
13
+ sentence_transformers
14
+ uvicorn
15
+ ctransformers
16
+ fastapi
17
+ ipykernel
18
+ python-box
19
+ transformers