ubermenchh commited on
Commit
ef5a9f2
β€’
1 Parent(s): b72daeb

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +58 -0
app.py ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from langchain.prompts import PromptTemplate
3
+ from langchain.llms import CTransformers
4
+
5
+ ## Function To get response from LLAma 2 model
6
+
7
+ def getLLamaresponse(input_text,no_words,blog_style):
8
+
9
+ ### LLama2 model
10
+ llm=CTransformers(model='models/llama-2-7b-chat.ggmlv3.q8_0.bin',
11
+ model_type='llama',
12
+ config={'max_new_tokens':256,
13
+ 'temperature':0.01})
14
+
15
+ ## Prompt Template
16
+
17
+ template="""
18
+ Write a blog for {blog_style} job profile for a topic {input_text}
19
+ within {no_words} words.
20
+ """
21
+
22
+ prompt=PromptTemplate(input_variables=["blog_style","input_text",'no_words'],
23
+ template=template)
24
+
25
+ ## Generate the ressponse from the LLama 2 model
26
+ response=llm(prompt.format(blog_style=blog_style,input_text=input_text,no_words=no_words))
27
+ print(response)
28
+ return response
29
+
30
+
31
+
32
+
33
+
34
+
35
+ st.set_page_config(page_title="Generate Blogs",
36
+ page_icon='πŸ€–',
37
+ layout='centered',
38
+ initial_sidebar_state='collapsed')
39
+
40
+ st.header("Generate Blogs πŸ€–")
41
+
42
+ input_text=st.text_input("Enter the Blog Topic")
43
+
44
+ ## creating to more columns for additonal 2 fields
45
+
46
+ col1,col2=st.columns([5,5])
47
+
48
+ with col1:
49
+ no_words=st.text_input('No of Words')
50
+ with col2:
51
+ blog_style=st.selectbox('Writing the blog for',
52
+ ('Researchers','Data Scientist','Common People'),index=0)
53
+
54
+ submit=st.button("Generate")
55
+
56
+ ## Final response
57
+ if submit:
58
+ st.write(getLLamaresponse(input_text,no_words,blog_style))