Spaces:
Running
Running
Commit
·
5e3b796
1
Parent(s):
2713c62
Refactor generate_image and generate_post_html functions to remove category parameter and improve URL encoding
Browse files- post_blog.py +7 -6
post_blog.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
import re
|
2 |
import os
|
3 |
import time
|
4 |
-
import
|
5 |
import requests
|
6 |
import dotenv
|
7 |
import mistune
|
@@ -20,20 +20,21 @@ def extract_summary(text):
|
|
20 |
return match.group(1).replace("#", "").replace("\n", "").strip()
|
21 |
return None
|
22 |
|
23 |
-
def generate_image(title, summary
|
24 |
extracted_summary = extract_summary(summary)
|
25 |
if extracted_summary is None:
|
26 |
extracted_summary = title
|
27 |
-
|
|
|
28 |
requests.get(url).content
|
29 |
return url
|
30 |
|
31 |
-
def generate_post_html(title, summary, mindmap,
|
32 |
title = title.replace("{", r"{{").replace("}", r"}}")
|
33 |
summary = summary.replace("{", r"{{").replace("}", r"}}")
|
34 |
mindmap = mindmap.replace("{", r"{{").replace("}", r"}}")
|
35 |
citation = citation.replace("{", r"{{").replace("}", r"}}")
|
36 |
-
image = generate_image(title, summary
|
37 |
html_summary = mistune.html(summary)
|
38 |
post = f"""
|
39 |
<div>
|
@@ -71,7 +72,7 @@ height: 80dvh;
|
|
71 |
def create_post(title, category, summary, mindmap, citation):
|
72 |
post_title = title
|
73 |
post_category = f"{category}"
|
74 |
-
post_body, post_image = generate_post_html(title, summary, mindmap,
|
75 |
return post_title, post_category, post_body, post_image
|
76 |
|
77 |
def post_post(title, category, body, image):
|
|
|
1 |
import re
|
2 |
import os
|
3 |
import time
|
4 |
+
from urllib.parse import quote
|
5 |
import requests
|
6 |
import dotenv
|
7 |
import mistune
|
|
|
20 |
return match.group(1).replace("#", "").replace("\n", "").strip()
|
21 |
return None
|
22 |
|
23 |
+
def generate_image(title, summary):
|
24 |
extracted_summary = extract_summary(summary)
|
25 |
if extracted_summary is None:
|
26 |
extracted_summary = title
|
27 |
+
data = quote(f"{title} : {extracted_summary}")
|
28 |
+
url = f"https://image.pollinations.ai/prompt/{data}?width=1280&height=720&seed=623862700&nologo=true&model=turbo"
|
29 |
requests.get(url).content
|
30 |
return url
|
31 |
|
32 |
+
def generate_post_html(title, summary, mindmap, citation):
|
33 |
title = title.replace("{", r"{{").replace("}", r"}}")
|
34 |
summary = summary.replace("{", r"{{").replace("}", r"}}")
|
35 |
mindmap = mindmap.replace("{", r"{{").replace("}", r"}}")
|
36 |
citation = citation.replace("{", r"{{").replace("}", r"}}")
|
37 |
+
image = generate_image(title, summary)
|
38 |
html_summary = mistune.html(summary)
|
39 |
post = f"""
|
40 |
<div>
|
|
|
72 |
def create_post(title, category, summary, mindmap, citation):
|
73 |
post_title = title
|
74 |
post_category = f"{category}"
|
75 |
+
post_body, post_image = generate_post_html(title, summary, mindmap, citation)
|
76 |
return post_title, post_category, post_body, post_image
|
77 |
|
78 |
def post_post(title, category, body, image):
|