Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,3 +1,4 @@
|
|
|
|
1 |
from langchain.chains import LLMChain
|
2 |
from langchain.llms import HuggingFaceHub
|
3 |
from langchain.prompts import PromptTemplate
|
@@ -26,42 +27,46 @@ existing_ideas = load_ideas()
|
|
26 |
st.sidebar.header("Previous Ideas:")
|
27 |
|
28 |
while(True):
|
29 |
-
|
|
|
|
|
|
|
|
|
30 |
if button_clicked:
|
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 |
-
existing_ideas.append({topic:content})
|
61 |
-
keys = [key for idea in existing_ideas for key in idea.keys()]
|
62 |
-
save_ideas(existing_ideas)
|
63 |
-
keys = [key for idea in existing_ideas for key in idea.keys()]
|
64 |
-
selected_idea = st.sidebar.selectbox("Select Idea", keys, key="selectbox")
|
65 |
-
selected_idea_from_list = next((idea for idea in existing_ideas if selected_idea in idea), None)
|
66 |
-
st.markdown(selected_idea_from_list[selected_idea])
|
67 |
|
|
|
1 |
+
%%writefile app.py
|
2 |
from langchain.chains import LLMChain
|
3 |
from langchain.llms import HuggingFaceHub
|
4 |
from langchain.prompts import PromptTemplate
|
|
|
27 |
st.sidebar.header("Previous Ideas:")
|
28 |
|
29 |
while(True):
|
30 |
+
keys = list(set([key for idea in existing_ideas for key in idea.keys()]))
|
31 |
+
if keys:
|
32 |
+
selected_idea = st.sidebar.selectbox("Select Idea", keys, key="selectbox")
|
33 |
+
selected_idea_from_list = next((idea for idea in existing_ideas if selected_idea in idea), None)
|
34 |
+
st.markdown(selected_idea_from_list[selected_idea])
|
35 |
if button_clicked:
|
36 |
|
37 |
+
hub_llm = HuggingFaceHub(repo_id ="HuggingFaceH4/zephyr-7b-beta")
|
38 |
+
prompt = PromptTemplate(
|
39 |
+
input_variables = ['keyword'],
|
40 |
+
template = """
|
41 |
+
Write a comprehensive article about {keyword} covering the following aspects:
|
42 |
+
Introduction, History and Background, Key Concepts and Terminology, Use Cases and Applications, Benefits and Drawbacks, Future Outlook, Conclusion
|
43 |
+
Ensure that the article is well-structured, informative, and at least 1500 words long. Use SEO best practices for content optimization.
|
44 |
+
""")
|
45 |
+
hub_chain = LLMChain(prompt=prompt,llm = hub_llm,verbose=True)
|
46 |
|
47 |
+
content = hub_chain.run(topic)
|
48 |
|
49 |
|
50 |
+
subheadings = [
|
51 |
+
"Introduction:",
|
52 |
+
"History and Background:",
|
53 |
+
"Key Concepts and Terminology:",
|
54 |
+
"Use Cases and Applications:",
|
55 |
+
"Benefits and Drawbacks:",
|
56 |
+
"Future Outlook:",
|
57 |
+
"Conclusion:",
|
58 |
+
]
|
59 |
+
organized_content = ""
|
60 |
|
61 |
+
for subheading in subheadings:
|
62 |
+
if subheading in content:
|
63 |
+
content = content.replace(subheading,"## "+subheading+"\n")
|
64 |
+
|
65 |
+
existing_ideas.append({topic:content})
|
66 |
+
keys = list(set([key for idea in existing_ideas for key in idea.keys()]))
|
67 |
+
save_ideas(existing_ideas)
|
68 |
+
selected_idea = st.sidebar.selectbox("Select Idea", keys, key="selectbox",index=keys.index(topic))
|
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 |
|