File size: 2,582 Bytes
f5a396a
 
 
ac462f6
717fa5f
2bd2884
717fa5f
 
 
 
 
 
 
 
 
 
 
 
 
2bd2884
717fa5f
 
2bd2884
717fa5f
 
 
 
be64c97
 
27c445c
be64c97
 
8e52054
be64c97
 
27c445c
717fa5f
ccf3917
 
 
 
 
 
 
 
 
2bd2884
ccf3917
2bd2884
 
ccf3917
 
 
 
 
 
 
 
 
 
2bd2884
ccf3917
 
 
 
 
 
8e52054
 
be64c97
2bd2884
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
from langchain.chains import LLMChain
from langchain.llms import HuggingFaceHub
from langchain.prompts import PromptTemplate
import streamlit as st
import json

# Load existing ideas from a file
def load_ideas():
    try:
        with open("ideas.json", "r") as file:
            ideas = json.load(file)
    except FileNotFoundError:
        ideas = []
    return ideas

# Save ideas to a file
def save_ideas(ideas):
    with open("ideas.json", "w") as file:
        json.dump(ideas, file)


topic = st.text_input("Enter Topic for the bog")
button_clicked = st.button("Create blog!")

existing_ideas = load_ideas()
st.sidebar.header("Previous Ideas:")

markdown_placeholder = st.empty()

while(True):
  keys = list(set([key for idea in existing_ideas for key in idea.keys()]))
  if keys:  
    selected_idea = st.sidebar.selectbox("Select Idea", keys, key=f"selectbox_{len(keys)}")
    selected_idea_from_list = next((idea for idea in existing_ideas if selected_idea in idea), None)
    markdown_placeholder.markdown(selected_idea_from_list[selected_idea])
    if button_clicked:

        hub_llm = HuggingFaceHub(repo_id ="HuggingFaceH4/zephyr-7b-beta")
        prompt = PromptTemplate(
            input_variables = ['keyword'],
            template = """
            Write a comprehensive article about {keyword} covering the following aspects:
            Introduction, History and Background, Key Concepts and Terminology, Use Cases and Applications, Benefits and Drawbacks, Future Outlook, Conclusion
            Ensure that the article is well-structured, informative, and at least 1500 words long. Use SEO best practices for content optimization.
            """)
        hub_chain = LLMChain(prompt=prompt,llm = hub_llm,verbose=True)

        content = hub_chain.run(topic)


        subheadings = [
                "Introduction:",
                "History and Background:",
                "Key Concepts and Terminology:",
                "Use Cases and Applications:",
                "Benefits and Drawbacks:",
                "Future Outlook:",
                "Conclusion:",
            ]
        organized_content = ""

        for subheading in subheadings:
            if subheading in content:
                content = content.replace(subheading,"## "+subheading+"\n")

        existing_ideas.append({topic:content})
        save_ideas(existing_ideas)
        keys = list(set([key for idea in existing_ideas for key in idea.keys()]))
        st.sidebar.selectbox("Select Idea", keys, key=f"selectbox_{len(keys)}")
        markdown_placeholder.markdown(content)