Spaces:
Running
Running
Update post_blog.py
Browse files- post_blog.py +8 -7
post_blog.py
CHANGED
@@ -22,10 +22,13 @@ def extract_summary(text):
|
|
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})
|
26 |
-
|
27 |
-
|
28 |
-
|
|
|
|
|
|
|
29 |
|
30 |
def generate_image(title, summary, category):
|
31 |
extracted_summary = extract_summary(summary)
|
@@ -35,9 +38,7 @@ def generate_image(title, summary, category):
|
|
35 |
data = requests.get(url).content
|
36 |
encoded_image = base64.b64encode(data)
|
37 |
image = encoded_image.decode('utf-8')
|
38 |
-
image_url
|
39 |
-
if status_code != 200:
|
40 |
-
return f"data:image/png;base64,{image}"
|
41 |
return image_url
|
42 |
|
43 |
def generate_post_html(title, summary, mindmap, category, citation):
|
|
|
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)
|
|
|
38 |
data = requests.get(url).content
|
39 |
encoded_image = base64.b64encode(data)
|
40 |
image = encoded_image.decode('utf-8')
|
41 |
+
image_url = upload_image(image, os.getenv('IMGBB_API_KEY'))
|
|
|
|
|
42 |
return image_url
|
43 |
|
44 |
def generate_post_html(title, summary, mindmap, category, citation):
|