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