thesven commited on
Commit
673a948
1 Parent(s): d7b1e99

Rough concept

Browse files

Needs to be refined, answers are not always correct for each Keyword, Outline, and Article.

Files changed (4) hide show
  1. .gitignore +3 -1
  2. app.py +72 -0
  3. blog-content-writer.code-workspace +11 -0
  4. requirements.txt +3 -0
.gitignore CHANGED
@@ -1 +1,3 @@
1
- .env
 
 
 
1
+ .env
2
+ data
3
+ .chroma
app.py ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import streamlit as st
3
+
4
+ from dotenv import dotenv_values
5
+
6
+ from langchain.prompts import PromptTemplate
7
+ from langchain.chains import RetrievalQA, LLMChain
8
+ from langchain.document_loaders import TextLoader
9
+ from langchain.embeddings import HuggingFaceEmbeddings
10
+ from langchain.llms import HuggingFaceEndpoint
11
+ from langchain.text_splitter import CharacterTextSplitter
12
+ from langchain.vectorstores import Chroma
13
+
14
+ env_vars = dotenv_values(".env")
15
+
16
+ # prepare Falcon Huggingface API
17
+ llm = HuggingFaceEndpoint(
18
+ endpoint_url= f"https://api-inference.huggingface.co/models/{env_vars['HUGGINGFACE_MODEL']}",
19
+ huggingfacehub_api_token=env_vars["HUGGINGFACE_API_TOKEN"],
20
+ task="text-generation",
21
+ model_kwargs = {
22
+ "min_length": 8192,
23
+ "max_length":8192,
24
+ "temperature":0.9,
25
+ "max_new_tokens":4000,
26
+ "num_return_sequences":1
27
+ }
28
+ )
29
+
30
+
31
+ keyword_prompt_template = "What are 10 important keywords related too: {word}? Only return a list of words and do not include any duplicates."
32
+ keyword_chain = LLMChain(
33
+ llm=llm,
34
+ prompt=PromptTemplate.from_template(keyword_prompt_template),
35
+ )
36
+
37
+ outline_prompt_template = "Create an outline for an article about: {word}."
38
+ outline_chain = LLMChain(
39
+ llm=llm,
40
+ prompt=PromptTemplate.from_template(outline_prompt_template),
41
+ )
42
+
43
+ article_prompt_template = """
44
+ Act as an expert SEO Writer.
45
+ Write a well crafted article using the given outline as a guide.
46
+ Use the relavant keywords you are provided.
47
+ Apply EEAT principles and SEO best practices.
48
+ It is important that the content is at least 1500 words.
49
+ Be sure to include section headers.
50
+ OUTLINE: {outline}
51
+ KEYWORDS: {keywords}
52
+ """
53
+ article_chain = LLMChain(
54
+ llm=llm,
55
+ prompt=PromptTemplate.from_template(article_prompt_template),
56
+ )
57
+
58
+ st.title("Blog Writer")
59
+ keyword = st.text_input("Input the keyword you wish to write about")
60
+
61
+ if keyword:
62
+ with st.spinner("Writing..."):
63
+ st.write(f"Writing about: {keyword}")
64
+ with st.expander("Keywords"):
65
+ keywords = keyword_chain.run(keyword)
66
+ st.write(keywords)
67
+ with st.expander("Outline"):
68
+ outline = outline_chain.run(keyword)
69
+ st.write(outline)
70
+ with st.expander("Article"):
71
+ article = article_chain.run(outline=outline, keywords=keywords)
72
+ st.write(article)
blog-content-writer.code-workspace ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "folders": [
3
+ {
4
+ "path": "."
5
+ }
6
+ ],
7
+ "settings": {
8
+ "files.autoSave": "onFocusChange",
9
+ "editor.cursorStyle": "block"
10
+ }
11
+ }
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ langchain
2
+ python-dotenv
3
+ transformers