Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -18,54 +18,68 @@ def save_ideas(ideas):
|
|
18 |
with open("ideas.json", "w") as file:
|
19 |
json.dump(ideas, file)
|
20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
|
22 |
-
|
23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
|
25 |
-
|
26 |
-
|
|
|
|
|
|
|
27 |
|
28 |
-
|
29 |
|
30 |
-
|
31 |
-
|
32 |
-
if keys:
|
33 |
-
selected_idea = st.sidebar.selectbox("Select Idea", keys, key=f"selectbox_{len(keys)}")
|
34 |
-
selected_idea_from_list = next((idea for idea in existing_ideas if selected_idea in idea), None)
|
35 |
-
markdown_placeholder.markdown(selected_idea_from_list[selected_idea])
|
36 |
-
if button_clicked:
|
37 |
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
template = """
|
42 |
-
Write a comprehensive article about {keyword} covering the following aspects:
|
43 |
-
Introduction, History and Background, Key Concepts and Terminology, Use Cases and Applications, Benefits and Drawbacks, Future Outlook, Conclusion
|
44 |
-
Ensure that the article is well-structured, informative, and at least 1500 words long. Use SEO best practices for content optimization.
|
45 |
-
""")
|
46 |
-
hub_chain = LLMChain(prompt=prompt,llm = hub_llm,verbose=True)
|
47 |
|
48 |
-
|
|
|
|
|
49 |
|
|
|
|
|
|
|
50 |
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
"Key Concepts and Terminology:",
|
55 |
-
"Use Cases and Applications:",
|
56 |
-
"Benefits and Drawbacks:",
|
57 |
-
"Future Outlook:",
|
58 |
-
"Conclusion:",
|
59 |
-
]
|
60 |
-
organized_content = ""
|
61 |
|
62 |
-
|
63 |
-
|
64 |
-
|
|
|
|
|
|
|
65 |
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
st.sidebar.selectbox("Select Idea", keys, key=f"selectbox_{len(keys)}")
|
70 |
-
markdown_placeholder.markdown(content)
|
71 |
|
|
|
|
|
|
|
|
18 |
with open("ideas.json", "w") as file:
|
19 |
json.dump(ideas, file)
|
20 |
|
21 |
+
# Function to generate content
|
22 |
+
def generate_content(topic):
|
23 |
+
hub_llm = HuggingFaceHub(repo_id="HuggingFaceH4/zephyr-7b-beta")
|
24 |
+
prompt = PromptTemplate(
|
25 |
+
input_variables=['keyword'],
|
26 |
+
template="""
|
27 |
+
Write a comprehensive article about {keyword} covering the following aspects:
|
28 |
+
Introduction, History and Background, Key Concepts and Terminology, Use Cases and Applications, Benefits and Drawbacks, Future Outlook, Conclusion
|
29 |
+
Ensure that the article is well-structured, informative, and at least 1500 words long. Use SEO best practices for content optimization.
|
30 |
+
"""
|
31 |
+
)
|
32 |
+
hub_chain = LLMChain(prompt=prompt, llm=hub_llm, verbose=True)
|
33 |
+
content = hub_chain.run(topic)
|
34 |
|
35 |
+
subheadings = [
|
36 |
+
"Introduction",
|
37 |
+
"History and Background",
|
38 |
+
"Key Concepts and Terminology",
|
39 |
+
"Use Cases and Applications",
|
40 |
+
"Benefits and Drawbacks",
|
41 |
+
"Future Outlook",
|
42 |
+
"Conclusion",
|
43 |
+
]
|
44 |
|
45 |
+
for subheading in subheadings:
|
46 |
+
if (subheading + ":") in content:
|
47 |
+
content = content.replace(subheading + ":", "## " + subheading + "\n")
|
48 |
+
elif subheading in content:
|
49 |
+
content = content.replace(subheading, "## " + subheading + "\n")
|
50 |
|
51 |
+
return content
|
52 |
|
53 |
+
# Streamlit app
|
54 |
+
st.title("Blog Generator")
|
|
|
|
|
|
|
|
|
|
|
55 |
|
56 |
+
# Input and button
|
57 |
+
topic = st.text_input("Enter Title for the blog")
|
58 |
+
button_clicked = st.button("Create blog!")
|
|
|
|
|
|
|
|
|
|
|
|
|
59 |
|
60 |
+
# Load existing ideas
|
61 |
+
existing_ideas = load_ideas()
|
62 |
+
st.sidebar.header("Previous Ideas:")
|
63 |
|
64 |
+
# Display existing ideas in the sidebar
|
65 |
+
keys = list(set([key for idea in existing_ideas for key in idea.keys()]))
|
66 |
+
selected_idea = st.sidebar.selectbox("Select Idea", keys, key="selectbox", index=0)
|
67 |
|
68 |
+
# Display content for the selected idea
|
69 |
+
selected_idea_from_list = next((idea for idea in existing_ideas if selected_idea in idea), None)
|
70 |
+
st.markdown(selected_idea_from_list[selected_idea])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
71 |
|
72 |
+
# Handle button click
|
73 |
+
if button_clicked:
|
74 |
+
# Generate content and update existing ideas
|
75 |
+
content = generate_content(topic)
|
76 |
+
existing_ideas.append({topic: content})
|
77 |
+
save_ideas(existing_ideas)
|
78 |
|
79 |
+
# Update keys and selected idea in the sidebar
|
80 |
+
keys = list(set([key for idea in existing_ideas for key in idea.keys()]))
|
81 |
+
selected_idea = st.sidebar.selectbox("Select Idea", keys, key="selectbox", index=keys.index(topic))
|
|
|
|
|
82 |
|
83 |
+
# Update selected idea content
|
84 |
+
selected_idea_from_list = next((idea for idea in existing_ideas if selected_idea in idea), None)
|
85 |
+
st.markdown(selected_idea_from_list[selected_idea])
|