Mo-alaa commited on
Commit
35bafe7
·
1 Parent(s): 6cf25d0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +42 -19
app.py CHANGED
@@ -1,3 +1,5 @@
 
 
1
  from langchain.chains import LLMChain
2
  from langchain.llms import HuggingFaceHub
3
  from langchain.prompts import PromptTemplate
@@ -50,36 +52,57 @@ def generate_content(topic):
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])
 
1
+ from diffusers import StableDiffusionXLPipeline
2
+ import torch
3
  from langchain.chains import LLMChain
4
  from langchain.llms import HuggingFaceHub
5
  from langchain.prompts import PromptTemplate
 
52
 
53
  return content
54
 
55
+ def make_pipe():
56
+ pipe = StableDiffusionXLPipeline.from_pretrained("segmind/SSD-1B", torch_dtype=torch.float16, use_safetensors=True, variant="fp16")
57
+ pipe.to("cuda")
58
+ return pipe
59
 
60
+ # generate image
61
+ def generate_image(pipe,topic):
62
+ prompt = f"A banner for a blog about{topic}" # Your prompt here
63
+ neg_prompt = "ugly, blurry, poor quality" # Negative prompt here
64
+ image = pipe(prompt=prompt, negative_prompt=neg_prompt).images[0]
65
+ return image
66
 
 
 
 
67
 
 
 
 
68
 
69
+ pipe = make_pipe()
70
+ with st.spinner('Please Wait for the models to train...'):
71
+ if pipe:
72
+ # Streamlit app
73
+ st.title("Blog Generator")
74
+
75
+ # Input and button
76
+ topic = st.text_input("Enter Title for the blog")
77
+ button_clicked = st.button("Create blog!")
78
+ st.subheader(topic)
79
+ # Load existing ideas
80
+ existing_ideas = load_ideas()
81
+ st.sidebar.header("Previous Ideas:")
82
+
83
+ # Display existing ideas in the sidebar
84
+ keys = list(set([key for idea in existing_ideas for key in idea.keys()]))
85
+ if topic in keys:
86
+ index = keys.index(topic)
87
+ selected_idea = st.sidebar.selectbox("Select Idea", keys, key="selectbox", index=index)
88
+ # Display content for the selected idea
89
+ selected_idea_from_list = next((idea for idea in existing_ideas if selected_idea in idea), None)
90
+ st.markdown(selected_idea_from_list[selected_idea])
91
+ else:
92
+ index = 0
93
+ st.success('')
94
+
95
 
96
  # Handle button click
97
  if button_clicked:
98
  # Generate content and update existing ideas
99
+ image = generate_image(pipe,topic)
100
+ st.image(image)
101
  content = generate_content(topic)
102
  existing_ideas.append({topic: content})
103
  save_ideas(existing_ideas)
104
+ st.experimental_rerun()
105
  # Update keys and selected idea in the sidebar
106
  keys = list(set([key for idea in existing_ideas for key in idea.keys()]))
107
  selected_idea = st.sidebar.selectbox("Select Idea", keys, key="selectbox", index=keys.index(topic))
108
+ st.markdown(content)