udayr commited on
Commit
5c0f618
·
verified ·
1 Parent(s): 573bb9d

Upload app.py

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