Spaces:
Running
Running
Commit
·
cc2c2ad
1
Parent(s):
0b2021f
Remove image upload functionality and use base64 encoding directly in generate_image
Browse files- post_blog.py +1 -11
post_blog.py
CHANGED
@@ -20,16 +20,6 @@ def extract_summary(text):
|
|
20 |
return match.group(1).replace("#", "").replace("\n", "").strip()
|
21 |
return None
|
22 |
|
23 |
-
def upload_image(image, api_key):
|
24 |
-
url = f'https://api.imgbb.com/1/upload?key={api_key}'
|
25 |
-
response = requests.post(url, data = {'image': image}).json()
|
26 |
-
print(response)
|
27 |
-
if response['status'] != 200:
|
28 |
-
image_url = f"data:image/png;base64,{image}"
|
29 |
-
else:
|
30 |
-
image_url = response['data']['image']['url']
|
31 |
-
return image_url
|
32 |
-
|
33 |
def generate_image(title, summary, category):
|
34 |
extracted_summary = extract_summary(summary)
|
35 |
if extracted_summary is None:
|
@@ -38,7 +28,7 @@ def generate_image(title, summary, category):
|
|
38 |
data = requests.get(url).content
|
39 |
encoded_image = base64.b64encode(data)
|
40 |
image = encoded_image.decode('utf-8')
|
41 |
-
image_url =
|
42 |
return image_url
|
43 |
|
44 |
def generate_post_html(title, summary, mindmap, category, citation):
|
|
|
20 |
return match.group(1).replace("#", "").replace("\n", "").strip()
|
21 |
return None
|
22 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
def generate_image(title, summary, category):
|
24 |
extracted_summary = extract_summary(summary)
|
25 |
if extracted_summary is None:
|
|
|
28 |
data = requests.get(url).content
|
29 |
encoded_image = base64.b64encode(data)
|
30 |
image = encoded_image.decode('utf-8')
|
31 |
+
image_url = f"data:image/png;base64,{image}"
|
32 |
return image_url
|
33 |
|
34 |
def generate_post_html(title, summary, mindmap, category, citation):
|