Spaces:
Build error
Build error
Commit
·
9cfbf37
1
Parent(s):
580693b
update source code
Browse files- app.py +66 -0
- requirements.txt +7 -0
app.py
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from langchain.prompts import PromptTemplate
|
| 3 |
+
from langchain.llms import CTransformers
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
# Function to get the response back
|
| 7 |
+
def getLLMResponse(form_input, email_sender, email_recipient, email_style):
|
| 8 |
+
# Wrapper for LLAMA2-7B- Chat, Running LLAM2 on CPU
|
| 9 |
+
|
| 10 |
+
# Quantization is reducing model precision by converting weights from 16 bit floats to 8 bit integers,
|
| 11 |
+
# enabling efficient deployment on resource-limited devices, reducing model size, and maintaining
|
| 12 |
+
# performance.
|
| 13 |
+
|
| 14 |
+
# C Transformer offers support for various open-source models.
|
| 15 |
+
# among them popular ones like LLAMA, GPT4All-J, MPT, and Falcon,
|
| 16 |
+
|
| 17 |
+
# C Transformers are Python library that provides bindings for transformer models implemented
|
| 18 |
+
# in C/ C++ using GGML library.
|
| 19 |
+
|
| 20 |
+
# https://huggingface.co/TheBloke/Llama-2-7B-Chat-GGML/tree/main
|
| 21 |
+
llm = CTransformers(model='models/llama-2-7b-chat.ggmlv3.q8_0.bin',
|
| 22 |
+
model_type='llama', config={'max_new_tokens': 256,
|
| 23 |
+
'temperature': 0.01})
|
| 24 |
+
|
| 25 |
+
# Template for building the PROMPT
|
| 26 |
+
template = """
|
| 27 |
+
Write an email with {style} style and includes topic: {email_topic}.\n\nSender: {sender}\nRecipient:
|
| 28 |
+
{recipient}
|
| 29 |
+
\n\nEmail Text:
|
| 30 |
+
"""
|
| 31 |
+
|
| 32 |
+
# Creating the final PROMPT
|
| 33 |
+
prompt = PromptTemplate(
|
| 34 |
+
input_variables=["style", "email_topic", "sender", "recipient"],
|
| 35 |
+
template=template,
|
| 36 |
+
)
|
| 37 |
+
|
| 38 |
+
# Generating the response using LLM
|
| 39 |
+
response = llm(prompt.format(email_topic=form_input, sender=email_sender, recipient=email_recipient
|
| 40 |
+
, style=email_style))
|
| 41 |
+
print(response)
|
| 42 |
+
|
| 43 |
+
return response
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
st.set_page_config(page_title="Generate Emails", page_icon='📧', layout='centered',
|
| 47 |
+
initial_sidebar_state='collapsed')
|
| 48 |
+
st.header("Generate Emails 📧")
|
| 49 |
+
|
| 50 |
+
form_input = st.text_area('Enter the email topic', height=275)
|
| 51 |
+
|
| 52 |
+
# Creating columns for the UI- To receive inputs from user.
|
| 53 |
+
col1, col2, col3 = st.columns([10, 10, 5])
|
| 54 |
+
with col1:
|
| 55 |
+
email_sender = st.text_input('Sender Name')
|
| 56 |
+
with col2:
|
| 57 |
+
email_recipient = st.text_input('Recipient Name')
|
| 58 |
+
with col3:
|
| 59 |
+
email_style = st.selectbox('Writing Style', ('Format', 'Appreciating', 'Not Satisfied', 'Neutral'),
|
| 60 |
+
index=0)
|
| 61 |
+
|
| 62 |
+
submit = st.button("Generate")
|
| 63 |
+
|
| 64 |
+
# When 'Generate' button is clicked, execute the below code
|
| 65 |
+
if submit:
|
| 66 |
+
st.write(getLLMResponse(form_input, email_sender, email_recipient, email_style))
|
requirements.txt
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
sentence-transformers==2.2.2
|
| 2 |
+
uvicorn==0.24.0.post1
|
| 3 |
+
ctransformers==0.2.27
|
| 4 |
+
fastapi==0.105.0
|
| 5 |
+
ipykernel==6.27.1
|
| 6 |
+
langchain==0.1.0
|
| 7 |
+
python-box==7.1.1
|