Update app.py
Browse files
app.py
CHANGED
|
@@ -209,6 +209,18 @@ def generate_blog_content(topic, tone="professional", length="long"):
|
|
| 209 |
return f"Error generating content: {str(e)}"
|
| 210 |
|
| 211 |
# Generate feature image
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 212 |
|
| 213 |
# Convert blog into a colorful web page
|
| 214 |
def generate_webpage(blog_content, title, author):
|
|
@@ -232,20 +244,6 @@ def generate_webpage(blog_content, title, author):
|
|
| 232 |
</body>
|
| 233 |
</html>
|
| 234 |
"""
|
| 235 |
-
|
| 236 |
-
html_template = f"""
|
| 237 |
-
<html>
|
| 238 |
-
<head>
|
| 239 |
-
<style>
|
| 240 |
-
body {{ font-family: Arial, sans-serif; background-color: #f5f5f5; padding: 20px; }}
|
| 241 |
-
</style>
|
| 242 |
-
</head>
|
| 243 |
-
<body>
|
| 244 |
-
<h1>{title}</h1>
|
| 245 |
-
</body>
|
| 246 |
-
</html>
|
| 247 |
-
"""
|
| 248 |
-
|
| 249 |
temp_file = tempfile.NamedTemporaryFile(delete=False, suffix=".html", mode="w", encoding="utf-8")
|
| 250 |
temp_file.write(html_template)
|
| 251 |
temp_file.close()
|
|
|
|
| 209 |
return f"Error generating content: {str(e)}"
|
| 210 |
|
| 211 |
# Generate feature image
|
| 212 |
+
def generate_featured_image(topic):
|
| 213 |
+
try:
|
| 214 |
+
prompt = f"A vibrant, eye-catching blog cover image about {topic}, ultra HD, artistic"
|
| 215 |
+
payload = {"inputs": prompt, "parameters": {"height": 1024, "width": 1024, "num_inference_steps": 30}}
|
| 216 |
+
response = requests.post(IMAGE_API_URL, headers=HEADERS, json=payload)
|
| 217 |
+
response.raise_for_status()
|
| 218 |
+
image = Image.open(BytesIO(response.content))
|
| 219 |
+
temp_img = tempfile.NamedTemporaryFile(delete=False, suffix=".png")
|
| 220 |
+
image.save(temp_img.name)
|
| 221 |
+
return temp_img.name
|
| 222 |
+
except Exception as e:
|
| 223 |
+
return None
|
| 224 |
|
| 225 |
# Convert blog into a colorful web page
|
| 226 |
def generate_webpage(blog_content, title, author):
|
|
|
|
| 244 |
</body>
|
| 245 |
</html>
|
| 246 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 247 |
temp_file = tempfile.NamedTemporaryFile(delete=False, suffix=".html", mode="w", encoding="utf-8")
|
| 248 |
temp_file.write(html_template)
|
| 249 |
temp_file.close()
|