Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,3 +1,4 @@
|
|
|
|
1 |
import streamlit as st
|
2 |
from langchain.prompts import PromptTemplate
|
3 |
import requests
|
@@ -6,13 +7,9 @@ from langchain.chains import LLMChain
|
|
6 |
import io
|
7 |
from PIL import Image
|
8 |
import json
|
9 |
-
from model import
|
10 |
-
import torch
|
11 |
-
api_key = st.secrets["API"]
|
12 |
-
|
13 |
-
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
14 |
|
15 |
-
|
16 |
# Load existing ideas from a file
|
17 |
def load_ideas():
|
18 |
try:
|
@@ -83,7 +80,7 @@ def divide_content(text):
|
|
83 |
|
84 |
# Image Generation
|
85 |
API_URL = "https://api-inference.huggingface.co/models/goofyai/3d_render_style_xl"
|
86 |
-
headers = {"Authorization":
|
87 |
|
88 |
def query(payload):
|
89 |
response = requests.post(API_URL, headers=headers, json=payload)
|
@@ -97,37 +94,33 @@ def generat_image(image_prompt,name):
|
|
97 |
image.save(f"{name}.png")
|
98 |
return image
|
99 |
|
100 |
-
# st.title('AI Blog Content Generator')
|
101 |
-
|
102 |
-
# st.header('What is the topic of your blog post?')
|
103 |
-
# topic_text = st.text_input('Topic:', placeholder='Example: Generative AI')
|
104 |
-
# submitted = st.button('Submit')
|
105 |
-
|
106 |
def display_content_with_images(blog):
|
|
|
107 |
# Streamlit Display
|
108 |
st.header(blog['title'])
|
109 |
-
|
110 |
# Introduction
|
111 |
col1, col2 = st.columns(2, gap='medium')
|
112 |
with col1:
|
113 |
st.header('Introduction')
|
114 |
st.write(blog['Introduction'])
|
115 |
with col2:
|
116 |
-
st.image(blog[
|
|
|
117 |
|
118 |
# History
|
119 |
st.header('History and Background')
|
120 |
st.write(blog['History and Background'])
|
121 |
-
st.image(blog[
|
122 |
-
|
123 |
# Content
|
124 |
col1, col2 = st.columns(2, gap='medium')
|
125 |
with col1:
|
126 |
st.header('Key Concepts and Terminology')
|
127 |
st.write(blog['Key Concepts and Terminology'])
|
128 |
with col2:
|
129 |
-
st.image(blog[
|
130 |
-
|
131 |
# Use Cases and Applications
|
132 |
st.header('Use Cases and Applications')
|
133 |
st.write(blog['Use Cases and Applications'])
|
@@ -146,8 +139,8 @@ def display_content_with_images(blog):
|
|
146 |
st.header('Conclusion')
|
147 |
st.write(blog['Conclusion'])
|
148 |
with col2:
|
149 |
-
st.image(blog[
|
150 |
-
|
151 |
|
152 |
|
153 |
# Streamlit App
|
@@ -190,75 +183,33 @@ if button_clicked and topic not in keys:
|
|
190 |
blog = divide_content(content)
|
191 |
st.write(blog)
|
192 |
st.header(topic)
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
st.divider()
|
204 |
-
|
205 |
-
# History
|
206 |
-
st.subheader('History and Background')
|
207 |
-
st.write(blog[' History and Background'])
|
208 |
-
image_prompt = blog[' History and Background'].splitlines()[0]
|
209 |
-
history_image =generat_image(image_prompt,f" History and Background{topic}")
|
210 |
-
st.image(history_image, use_column_width=True)
|
211 |
-
st.divider()
|
212 |
-
|
213 |
-
# Key Concepts and Terminology
|
214 |
-
col1, col2 = st.columns(2, gap='medium')
|
215 |
-
with col1:
|
216 |
-
st.subheader('Key Concepts and Terminology')
|
217 |
-
st.write(blog[' Key Concepts and Terminology'])
|
218 |
-
with col2:
|
219 |
-
image_prompt = blog[' Key Concepts and Terminology'].splitlines()[0]
|
220 |
-
key_concepts_image = generat_image(image_prompt,f" Key Concepts and Terminology{topic}")
|
221 |
-
st.image(key_concepts_image, use_column_width=True)
|
222 |
-
st.divider()
|
223 |
-
|
224 |
-
# Use Cases and Applications
|
225 |
-
st.subheader('Use Cases and Applications')
|
226 |
-
st.write(blog[' Use Cases and Applications'])
|
227 |
-
|
228 |
-
# Benefits and Drawbacks
|
229 |
-
st.subheader('Benefits and Drawbacks')
|
230 |
-
st.write(blog[' Benefits and Drawbacks'])
|
231 |
-
|
232 |
-
# Future Outlook
|
233 |
-
st.subheader('Future Outlook')
|
234 |
-
st.write(blog[' Future Outlook'])
|
235 |
-
|
236 |
-
# Conclusion
|
237 |
-
col1, col2 = st.columns(2, gap='medium')
|
238 |
-
with col1:
|
239 |
-
st.subheader('Conclusion')
|
240 |
-
st.write(blog[' Conclusion'])
|
241 |
-
with col2:
|
242 |
-
image_prompt = blog[' Conclusion'].splitlines()[0]
|
243 |
-
conclusion_image = generat_image(image_prompt,f" Conclusion{topic}")
|
244 |
-
st.image(conclusion_image, use_column_width=True)
|
245 |
-
|
246 |
|
247 |
# Blog Data
|
248 |
blog_data = {
|
249 |
'title': topic,
|
250 |
'Introduction': blog[' Introduction'],
|
251 |
-
'introduction_image': f" Introduction{topic}.png",
|
252 |
'History and Background': blog[' History and Background'],
|
253 |
-
'History and Background_image': f" History and Background{topic}.png",
|
254 |
'Key Concepts and Terminology': blog[' Key Concepts and Terminology'],
|
255 |
-
'Key Concepts and Terminology_image': f" Key Concepts and Terminology{topic}.png",
|
256 |
'Use Cases and Applications': blog[' Use Cases and Applications'],
|
257 |
'Benefits and Drawbacks': blog[' Benefits and Drawbacks'],
|
258 |
'Future Outlook': blog[' Future Outlook'],
|
259 |
'Conclusion': blog[' Conclusion'],
|
260 |
-
'Conclusion_image': f" Conclusion{topic}.png"
|
261 |
}
|
|
|
|
|
|
|
|
|
|
|
262 |
|
263 |
# Save blog with images
|
264 |
existing_ideas.append({topic: blog_data})
|
|
|
1 |
+
|
2 |
import streamlit as st
|
3 |
from langchain.prompts import PromptTemplate
|
4 |
import requests
|
|
|
7 |
import io
|
8 |
from PIL import Image
|
9 |
import json
|
10 |
+
from model import model,tokenizer
|
|
|
|
|
|
|
|
|
11 |
|
12 |
+
API = st.secrets("API")
|
13 |
# Load existing ideas from a file
|
14 |
def load_ideas():
|
15 |
try:
|
|
|
80 |
|
81 |
# Image Generation
|
82 |
API_URL = "https://api-inference.huggingface.co/models/goofyai/3d_render_style_xl"
|
83 |
+
headers = {"Authorization": "Bearer API"}
|
84 |
|
85 |
def query(payload):
|
86 |
response = requests.post(API_URL, headers=headers, json=payload)
|
|
|
94 |
image.save(f"{name}.png")
|
95 |
return image
|
96 |
|
|
|
|
|
|
|
|
|
|
|
|
|
97 |
def display_content_with_images(blog):
|
98 |
+
blog_images = [key for key in list(blog.keys()) if "_image" in key]
|
99 |
# Streamlit Display
|
100 |
st.header(blog['title'])
|
101 |
+
i = 0
|
102 |
# Introduction
|
103 |
col1, col2 = st.columns(2, gap='medium')
|
104 |
with col1:
|
105 |
st.header('Introduction')
|
106 |
st.write(blog['Introduction'])
|
107 |
with col2:
|
108 |
+
st.image(blog[blog_images[i]], use_column_width=True)
|
109 |
+
i+=1
|
110 |
|
111 |
# History
|
112 |
st.header('History and Background')
|
113 |
st.write(blog['History and Background'])
|
114 |
+
st.image(blog[blog_images[i]], use_column_width=True)
|
115 |
+
i+=1
|
116 |
# Content
|
117 |
col1, col2 = st.columns(2, gap='medium')
|
118 |
with col1:
|
119 |
st.header('Key Concepts and Terminology')
|
120 |
st.write(blog['Key Concepts and Terminology'])
|
121 |
with col2:
|
122 |
+
st.image(blog[blog_images[i]], use_column_width=True)
|
123 |
+
i+=1
|
124 |
# Use Cases and Applications
|
125 |
st.header('Use Cases and Applications')
|
126 |
st.write(blog['Use Cases and Applications'])
|
|
|
139 |
st.header('Conclusion')
|
140 |
st.write(blog['Conclusion'])
|
141 |
with col2:
|
142 |
+
st.image(blog[blog_images[i]], use_column_width=True)
|
143 |
+
i+=1
|
144 |
|
145 |
|
146 |
# Streamlit App
|
|
|
183 |
blog = divide_content(content)
|
184 |
st.write(blog)
|
185 |
st.header(topic)
|
186 |
+
keyss = list(blog.keys())
|
187 |
+
image_prompts = []
|
188 |
+
i=0
|
189 |
+
while len(image_prompts)<4:
|
190 |
+
try:
|
191 |
+
image_prompts.append((keyss[i],blog[keyss[i]].splitlines()[0]))
|
192 |
+
i+=1
|
193 |
+
except Exception as e:
|
194 |
+
print(e)
|
195 |
+
i+=1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
196 |
|
197 |
# Blog Data
|
198 |
blog_data = {
|
199 |
'title': topic,
|
200 |
'Introduction': blog[' Introduction'],
|
|
|
201 |
'History and Background': blog[' History and Background'],
|
|
|
202 |
'Key Concepts and Terminology': blog[' Key Concepts and Terminology'],
|
|
|
203 |
'Use Cases and Applications': blog[' Use Cases and Applications'],
|
204 |
'Benefits and Drawbacks': blog[' Benefits and Drawbacks'],
|
205 |
'Future Outlook': blog[' Future Outlook'],
|
206 |
'Conclusion': blog[' Conclusion'],
|
|
|
207 |
}
|
208 |
+
for k,image in image_prompts:
|
209 |
+
img = generat_image(image,f" {k}{topic}")
|
210 |
+
blog_data[f'{k}_image'] = f" {k}{topic}.png"
|
211 |
+
|
212 |
+
display_content_with_images(blog_data)
|
213 |
|
214 |
# Save blog with images
|
215 |
existing_ideas.append({topic: blog_data})
|