raannakasturi commited on
Commit
9194514
·
1 Parent(s): 747f494

Refactor image handling by removing debug print statements, adding image cleanup, and improving post creation sleep duration

Browse files
Files changed (2) hide show
  1. image.py +2 -3
  2. post_blog.py +3 -3
image.py CHANGED
@@ -1,4 +1,5 @@
1
  import base64
 
2
  import pollinations as ai
3
  from PIL import Image
4
  import io
@@ -26,7 +27,6 @@ def generate_image(title, summary):
26
  enhance=True,
27
  nologo=True
28
  )
29
- print(data)
30
  model_obj.generate(
31
  prompt=r"{}".format(data),
32
  negative=("a bad image, low res, low quality, pixelated, blurry, bad lighting, bad angle, bad composition, bad focus, bad exposure, bad white balance, bad color, bad contrast, bad saturation, bad sharpness, bad noise, bad artifacts, bad framing, bad cropping, bad editing, bad filter, bad lens, bad camera, bad sensor, bad settings, bad post-processing, bad retouching, bad enhancement, bad manipulation, bad distortion, bad watermark, bad logo, bad text, bad overlay, bad background"),
@@ -55,11 +55,9 @@ def verify_image(image_data):
55
 
56
  def upload_image(data_uri, api_key):
57
  try:
58
- # Strip the `data:image/png;base64,` prefix
59
  base64_image = data_uri.split(",")[1]
60
  url = f'https://api.imgbb.com/1/upload?key={api_key}'
61
  response = requests.post(url, data={'image': base64_image}).json()
62
- print(response)
63
  if response.get('status') == 200:
64
  return response['data']['url']
65
  else:
@@ -74,5 +72,6 @@ def fetch_image(title, summary, api_key):
74
  image_data = base64.b64decode(data_uri.split(",")[1])
75
  if verify_image(image_data):
76
  image_url = upload_image(data_uri, api_key)
 
77
  return image_url
78
 
 
1
  import base64
2
+ import os
3
  import pollinations as ai
4
  from PIL import Image
5
  import io
 
27
  enhance=True,
28
  nologo=True
29
  )
 
30
  model_obj.generate(
31
  prompt=r"{}".format(data),
32
  negative=("a bad image, low res, low quality, pixelated, blurry, bad lighting, bad angle, bad composition, bad focus, bad exposure, bad white balance, bad color, bad contrast, bad saturation, bad sharpness, bad noise, bad artifacts, bad framing, bad cropping, bad editing, bad filter, bad lens, bad camera, bad sensor, bad settings, bad post-processing, bad retouching, bad enhancement, bad manipulation, bad distortion, bad watermark, bad logo, bad text, bad overlay, bad background"),
 
55
 
56
  def upload_image(data_uri, api_key):
57
  try:
 
58
  base64_image = data_uri.split(",")[1]
59
  url = f'https://api.imgbb.com/1/upload?key={api_key}'
60
  response = requests.post(url, data={'image': base64_image}).json()
 
61
  if response.get('status') == 200:
62
  return response['data']['url']
63
  else:
 
72
  image_data = base64.b64decode(data_uri.split(",")[1])
73
  if verify_image(image_data):
74
  image_url = upload_image(data_uri, api_key)
75
+ os.remove("image.png")
76
  return image_url
77
 
post_blog.py CHANGED
@@ -1,4 +1,5 @@
1
  import os
 
2
  import requests
3
  import dotenv
4
  import mistune
@@ -88,7 +89,6 @@ def post_post(title, category, body, image):
88
  "labels": [category, "ZZZZZZZZZ"]
89
  }
90
  data = requests.post(url, headers=headers, json=post_data).json()
91
- print(data)
92
  if data['status'] == 'LIVE':
93
  print(f"The post '{title}' is {data['status']}")
94
  return True
@@ -106,8 +106,8 @@ def post_blog(title, category, summary, mindmap, citation, uaccess_key):
106
  status = True
107
  post_title, post_category, post_body, post_image = create_post(title, category, summary, mindmap, citation)
108
  status = post_post(post_title, post_category, post_body, post_image)
109
- # print(f"Waiting for {2*60} seconds...")
110
- # time.sleep(2*60)
111
  if status:
112
  print('Post created successfully')
113
  return True
 
1
  import os
2
+ import time
3
  import requests
4
  import dotenv
5
  import mistune
 
89
  "labels": [category, "ZZZZZZZZZ"]
90
  }
91
  data = requests.post(url, headers=headers, json=post_data).json()
 
92
  if data['status'] == 'LIVE':
93
  print(f"The post '{title}' is {data['status']}")
94
  return True
 
106
  status = True
107
  post_title, post_category, post_body, post_image = create_post(title, category, summary, mindmap, citation)
108
  status = post_post(post_title, post_category, post_body, post_image)
109
+ print(f"Waiting for {2*60} seconds...")
110
+ time.sleep(2*60)
111
  if status:
112
  print('Post created successfully')
113
  return True