Mo-alaa commited on
Commit
ccf3917
·
1 Parent(s): 1cfd7a8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -31
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
- if topic:
 
 
 
 
30
  if button_clicked:
31
 
32
- hub_llm = HuggingFaceHub(repo_id ="HuggingFaceH4/zephyr-7b-beta")
33
- prompt = PromptTemplate(
34
- input_variables = ['keyword'],
35
- template = """
36
- Write a comprehensive article about {keyword} covering the following aspects:
37
- Introduction, History and Background, Key Concepts and Terminology, Use Cases and Applications, Benefits and Drawbacks, Future Outlook, Conclusion
38
- Ensure that the article is well-structured, informative, and at least 1500 words long. Use SEO best practices for content optimization.
39
- """)
40
- hub_chain = LLMChain(prompt=prompt,llm = hub_llm,verbose=True)
41
 
42
- content = hub_chain.run(topic)
43
 
44
 
45
- subheadings = [
46
- "Introduction:",
47
- "History and Background:",
48
- "Key Concepts and Terminology:",
49
- "Use Cases and Applications:",
50
- "Benefits and Drawbacks:",
51
- "Future Outlook:",
52
- "Conclusion:",
53
- ]
54
- organized_content = ""
55
 
56
- for subheading in subheadings:
57
- if subheading in content:
58
- content = content.replace(subheading,"## "+subheading+"\n")
 
 
 
 
 
 
 
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