Mo-alaa commited on
Commit
717fa5f
·
1 Parent(s): b51632f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -12
app.py CHANGED
@@ -1,20 +1,43 @@
 
1
  from langchain.chains import LLMChain
2
  from langchain.llms import HuggingFaceHub
3
  from langchain.prompts import PromptTemplate
4
  import streamlit as st
 
5
 
6
- topic = st.text_input("Enter Topic for the bog")
7
- hub_llm = HuggingFaceHub(repo_id ="HuggingFaceH4/zephyr-7b-beta")
8
- prompt = PromptTemplate(
9
- input_variables = ['keyword'],
10
- template = """
11
- Write a comprehensive article about {keyword} covering the following aspects:
12
- Introduction, History and Background, Key Concepts and Terminology, Use Cases and Applications, Benefits and Drawbacks, Future Outlook, Conclusion
13
- Ensure that the article is well-structured, informative, and at least 1500 words long. Use SEO best practices for content optimization.
14
- """)
 
 
 
 
15
 
 
 
16
  button_clicked = st.button("Create blog!")
 
 
 
 
 
 
17
  if button_clicked:
 
 
 
 
 
 
 
 
 
18
  hub_chain = LLMChain(prompt=prompt,llm = hub_llm,verbose=True)
19
 
20
  content = hub_chain.run(topic)
@@ -27,7 +50,7 @@ if button_clicked:
27
  "Use Cases and Applications:",
28
  "Benefits and Drawbacks:",
29
  "Future Outlook:",
30
- "Conclusion:"
31
  ]
32
  organized_content = ""
33
 
@@ -35,5 +58,7 @@ if button_clicked:
35
  if subheading in content:
36
  content = content.replace(subheading,"## "+subheading+"\n")
37
 
38
-
39
- st.markdown(content)
 
 
 
1
+ %%writefile app.py
2
  from langchain.chains import LLMChain
3
  from langchain.llms import HuggingFaceHub
4
  from langchain.prompts import PromptTemplate
5
  import streamlit as st
6
+ import json
7
 
8
+ # Load existing ideas from a file
9
+ def load_ideas():
10
+ try:
11
+ with open("ideas.json", "r") as file:
12
+ ideas = json.load(file)
13
+ except FileNotFoundError:
14
+ ideas = []
15
+ return ideas
16
+
17
+ # Save ideas to a file
18
+ def save_ideas(ideas):
19
+ with open("ideas.json", "w") as file:
20
+ json.dump(ideas, file)
21
 
22
+
23
+ topic = st.text_input("Enter Topic for the bog")
24
  button_clicked = st.button("Create blog!")
25
+
26
+ existing_ideas = load_ideas()
27
+ st.sidebar.header("Previous Ideas:")
28
+ selected_idea = st.sidebar.selectbox("Select Idea", existing_ideas, key="selectbox")
29
+ st.markdown(selected_idea)
30
+
31
  if button_clicked:
32
+
33
+ hub_llm = HuggingFaceHub(repo_id ="HuggingFaceH4/zephyr-7b-beta")
34
+ prompt = PromptTemplate(
35
+ input_variables = ['keyword'],
36
+ template = """
37
+ Write a comprehensive article about {keyword} covering the following aspects:
38
+ Introduction, History and Background, Key Concepts and Terminology, Use Cases and Applications, Benefits and Drawbacks, Future Outlook, Conclusion
39
+ Ensure that the article is well-structured, informative, and at least 1500 words long. Use SEO best practices for content optimization.
40
+ """)
41
  hub_chain = LLMChain(prompt=prompt,llm = hub_llm,verbose=True)
42
 
43
  content = hub_chain.run(topic)
 
50
  "Use Cases and Applications:",
51
  "Benefits and Drawbacks:",
52
  "Future Outlook:",
53
+ "Conclusion:",
54
  ]
55
  organized_content = ""
56
 
 
58
  if subheading in content:
59
  content = content.replace(subheading,"## "+subheading+"\n")
60
 
61
+ existing_ideas.append({keyword:content})
62
+ save_ideas(existing_ideas)
63
+ selected_idea = st.sidebar.selectbox("Select Idea", existing_ideas, key="selectbox")
64
+ st.markdown(selected_idea)