thivav commited on
Commit
6a6018a
β€’
1 Parent(s): bbafa2c

init llama2 blogger app

Browse files
Files changed (4) hide show
  1. .gitignore +2 -0
  2. README.md +15 -1
  3. app.py +95 -0
  4. requirements.txt +6 -0
.gitignore CHANGED
@@ -158,3 +158,5 @@ cython_debug/
158
  # and can be added to the global gitignore or merged into this file. For a more nuclear
159
  # option (not recommended) you can uncomment the following to ignore the entire idea folder.
160
  #.idea/
 
 
 
158
  # and can be added to the global gitignore or merged into this file. For a more nuclear
159
  # option (not recommended) you can uncomment the following to ignore the entire idea folder.
160
  #.idea/
161
+
162
+ models/
README.md CHANGED
@@ -1,2 +1,16 @@
1
- # llama2_blogger
 
 
 
 
 
 
 
 
 
 
 
 
2
  LLAMA2 - Article Generation
 
 
 
1
+ ---
2
+ title: Llama2 Blogger App
3
+ emoji: πŸ“
4
+ colorFrom: blue
5
+ colorTo: purple
6
+ sdk: streamlit
7
+ sdk_version: 1.29.0
8
+ app_file: app.py
9
+ pinned: false
10
+ ---
11
+
12
+ # Blogger
13
+
14
  LLAMA2 - Article Generation
15
+
16
+ [The TheBloke/Llama-2-7B-Chat-GGML llama2 model used](https://huggingface.co/TheBloke/Llama-2-7B-Chat-GGML)
app.py ADDED
@@ -0,0 +1,95 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """streamlit providing the UI functionality."""
2
+ import streamlit as st
3
+ from langchain.llms import CTransformers
4
+ from langchain.prompts import PromptTemplate
5
+
6
+
7
+ # load llama2 model
8
+ @st.cache_resource
9
+ def load_model():
10
+ """load the llama2 model"""
11
+
12
+ # llama2_model_path = "models/llama-2-7b-chat.ggmlv3.q8_0.bin"
13
+ # model = CTransformers(
14
+ # model=llama2_model_path,
15
+ # model_type="llama",
16
+ # config={"max_new_tokens": 256, "temperature": 0},
17
+ # )
18
+ # return model
19
+
20
+ llama2_model = "TheBloke/Llama-2-7B-Chat-GGML"
21
+ model_variant = "llama-2-7b-chat.ggmlv3.q8_0.bin"
22
+ model = CTransformers(
23
+ model=llama2_model,
24
+ model_file=model_variant,
25
+ config={"max_new_tokens": 256, "temperature": 0},
26
+ )
27
+ return model
28
+
29
+
30
+ # request for blog content
31
+ @st.cache_data
32
+ def generate_blog(query, word_count, genre):
33
+ """generate blog"""
34
+
35
+ template = """
36
+ As a you a blogger, please write a blog for the topic {query} and under gener {genre}.
37
+ Please write the blog in {no_of_words} words.
38
+ Your blog strictly should be in markdown language.
39
+ Also, come with an appropriate title for the blog and set it at the top in bold letters.
40
+
41
+ Example:
42
+ # **YOUR TITLE**
43
+ YOUR BLOG
44
+ """
45
+
46
+ prompt = PromptTemplate(
47
+ input_variables=["query", "word_count", "genre"], template=template
48
+ )
49
+
50
+ llama2_model = load_model()
51
+ response = llama2_model(
52
+ prompt.format(query=query, word_count=word_count, genre=genre)
53
+ )
54
+ return response
55
+
56
+
57
+ st.set_page_config(
58
+ page_title="The Blogger",
59
+ page_icon="πŸ“",
60
+ layout="centered",
61
+ initial_sidebar_state="collapsed",
62
+ )
63
+
64
+ st.header("The Blogger πŸ“")
65
+
66
+ user_input = st.text_input("Enter the topic you wanted the blog")
67
+
68
+ col_1, col_2 = st.columns([5, 5])
69
+ with col_1:
70
+ no_of_words = st.selectbox(
71
+ "Number of words", ("200", "250", "300", "350", "400", "500")
72
+ )
73
+ with col_2:
74
+ blog_genres = st.selectbox(
75
+ "Genre of the blog",
76
+ (
77
+ "Business",
78
+ "Food",
79
+ "Music",
80
+ "Fitness",
81
+ "Travel",
82
+ "Gaming",
83
+ "Finance",
84
+ "Sports",
85
+ "Movie",
86
+ "Science & Technology",
87
+ "Lifestyle",
88
+ ),
89
+ index=0,
90
+ )
91
+
92
+ submit = st.button("Blog")
93
+ if submit:
94
+ blog = generate_blog(user_input, no_of_words, blog_genres)
95
+ st.write(blog)
requirements.txt ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ sentence-transformers
2
+ unicorn
3
+ ctransformers
4
+ langchain
5
+ python-box
6
+ streamlit