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