jayparmr commited on
Commit
f1235a4
·
1 Parent(s): 874521e

Upload folder using huggingface_hub

Browse files
internals/data/dataAccessor.py CHANGED
@@ -11,7 +11,7 @@ from internals.util.slack import Slack
11
 
12
  def updateSource(sourceId, userId, state):
13
  print("update source is called")
14
- url = api_endpoint() + f"/comic-crecoai/source/{sourceId}"
15
  headers = {
16
  "Content-Type": "application/json",
17
  "user-id": str(userId),
@@ -33,7 +33,12 @@ def updateSource(sourceId, userId, state):
33
 
34
  def saveGeneratedImages(sourceId, userId, has_nsfw: bool):
35
  print("save generation called")
36
- url = api_endpoint() + "/comic-crecoai/source/" + str(sourceId) + "/generatedImages"
 
 
 
 
 
37
  headers = {
38
  "Content-Type": "application/json",
39
  "user-id": str(userId),
@@ -53,7 +58,8 @@ def saveGeneratedImages(sourceId, userId, has_nsfw: bool):
53
 
54
 
55
  def getStyles() -> Optional[Dict]:
56
- url = api_endpoint() + "/comic-crecoai/style"
 
57
  try:
58
  response = requests.get(
59
  url,
@@ -64,12 +70,13 @@ def getStyles() -> Optional[Dict]:
64
  except requests.exceptions.Timeout:
65
  print("Request timed out while fetching styles")
66
  except requests.exceptions.RequestException as e:
 
67
  print(f"Error while fetching styles: {e}")
68
  return None
69
 
70
 
71
  def getCharacters(model_id: str) -> Optional[List]:
72
- url = api_endpoint() + "/comic-crecoai/model/{}".format(model_id)
73
  try:
74
  response = requests.get(url, timeout=10, headers=api_headers())
75
  response = response.json()
 
11
 
12
  def updateSource(sourceId, userId, state):
13
  print("update source is called")
14
+ url = api_endpoint() + f"/autodraft-crecoai/source/{sourceId}"
15
  headers = {
16
  "Content-Type": "application/json",
17
  "user-id": str(userId),
 
33
 
34
  def saveGeneratedImages(sourceId, userId, has_nsfw: bool):
35
  print("save generation called")
36
+ url = (
37
+ api_endpoint()
38
+ + "/autodraft-crecoai/source/"
39
+ + str(sourceId)
40
+ + "/generatedImages"
41
+ )
42
  headers = {
43
  "Content-Type": "application/json",
44
  "user-id": str(userId),
 
58
 
59
 
60
  def getStyles() -> Optional[Dict]:
61
+ url = api_endpoint() + "/autodraft-crecoai/style"
62
+ print(url)
63
  try:
64
  response = requests.get(
65
  url,
 
70
  except requests.exceptions.Timeout:
71
  print("Request timed out while fetching styles")
72
  except requests.exceptions.RequestException as e:
73
+ raise e
74
  print(f"Error while fetching styles: {e}")
75
  return None
76
 
77
 
78
  def getCharacters(model_id: str) -> Optional[List]:
79
+ url = api_endpoint() + "/autodraft-crecoai/model/{}".format(model_id)
80
  try:
81
  response = requests.get(url, timeout=10, headers=api_headers())
82
  response = response.json()
internals/pipelines/remove_background.py CHANGED
@@ -8,7 +8,7 @@ from PIL import Image
8
  from rembg import remove
9
 
10
  from carvekit.api.high import HiInterface
11
- from internals.util.commons import read_url
12
 
13
 
14
  class RemoveBackground:
@@ -38,7 +38,7 @@ class RemoveBackgroundV2:
38
  def remove(self, image: Union[str, Image.Image]) -> Image.Image:
39
  img_path = Path.home() / ".cache" / "rm_bg.png"
40
  if type(image) is str:
41
- image = Image.open(io.BytesIO(read_url(image)))
42
 
43
  image.save(img_path)
44
  images_without_background = self.interface([img_path])
 
8
  from rembg import remove
9
 
10
  from carvekit.api.high import HiInterface
11
+ from internals.util.commons import download_image, read_url
12
 
13
 
14
  class RemoveBackground:
 
38
  def remove(self, image: Union[str, Image.Image]) -> Image.Image:
39
  img_path = Path.home() / ".cache" / "rm_bg.png"
40
  if type(image) is str:
41
+ image = download_image(image)
42
 
43
  image.save(img_path)
44
  images_without_background = self.interface([img_path])
internals/util/commons.py CHANGED
@@ -101,22 +101,19 @@ def upload_images(images, processName: str, taskId: str):
101
  image.save(img_io, "JPEG", quality=100)
102
  img_io.seek(0)
103
  key = "crecoAI/{}{}_{}.png".format(taskId, processName, i)
104
- requests.post(
105
  api_endpoint()
106
- + "/comic-content/v1.0/upload/crecoai-assets-2?fileName="
107
  + "{}{}_{}.png".format(taskId, processName, i),
108
  headers=api_headers(),
109
  files={"file": ("image.png", img_io, "image/png")},
110
  )
 
111
  # t = s3.put_object(
112
  # Bucket="comic-assets", Key=key, Body=img_io.getvalue(), ACL="public-read"
113
  # )
114
  # print("uploading done to s3", key, t)
115
- imageUrls.append(
116
- "https://comic-assets.s3.ap-south-1.amazonaws.com/crecoAI/{}{}_{}.png".format(
117
- taskId, processName, i
118
- )
119
- )
120
 
121
  print({"promptImages": imageUrls})
122
 
@@ -130,17 +127,24 @@ def upload_image(image: Union[Image.Image, BytesIO], out_path):
130
  image = buffer
131
 
132
  image.seek(0)
133
- requests.post(
 
 
 
 
 
134
  api_endpoint()
135
- + "/comic-content/v1.0/upload/crecoai-assets-2?fileName="
136
  + str(out_path).replace("crecoAI/", ""),
137
  headers=api_headers(),
138
  files={"file": ("image.png", image, "image/png")},
139
  )
 
 
140
  # s3.upload_fileobj(image, "comic-assets", out_path, ExtraArgs={"ACL": "public-read"})
141
  image.close()
142
 
143
- image_url = "https://comic-assets.s3.ap-south-1.amazonaws.com/" + out_path
144
  print({"promptImages": image_url})
145
 
146
  return image_url
@@ -188,7 +192,7 @@ def pickPoses():
188
 
189
 
190
  def construct_default_s3_url(key):
191
- return "https://comic-assets.s3.ap-south-1.amazonaws.com/" + key
192
 
193
 
194
  def safe_index(array, index) -> Optional[Any]:
 
101
  image.save(img_io, "JPEG", quality=100)
102
  img_io.seek(0)
103
  key = "crecoAI/{}{}_{}.png".format(taskId, processName, i)
104
+ res = requests.post(
105
  api_endpoint()
106
+ + "/autodraft-content/v1.0/upload/crecoai-assets-2?fileName="
107
  + "{}{}_{}.png".format(taskId, processName, i),
108
  headers=api_headers(),
109
  files={"file": ("image.png", img_io, "image/png")},
110
  )
111
+ imgUrl = res.json()["imageUrl"]
112
  # t = s3.put_object(
113
  # Bucket="comic-assets", Key=key, Body=img_io.getvalue(), ACL="public-read"
114
  # )
115
  # print("uploading done to s3", key, t)
116
+ imageUrls.append(imgUrl)
 
 
 
 
117
 
118
  print({"promptImages": imageUrls})
119
 
 
127
  image = buffer
128
 
129
  image.seek(0)
130
+ print(
131
+ api_endpoint()
132
+ + "/autodraft-content/v1.0/upload/crecoai-assets-2?fileName="
133
+ + str(out_path).replace("crecoAI/", ""),
134
+ )
135
+ res = requests.post(
136
  api_endpoint()
137
+ + "/autodraft-content/v1.0/upload/crecoai-assets-2?fileName="
138
  + str(out_path).replace("crecoAI/", ""),
139
  headers=api_headers(),
140
  files={"file": ("image.png", image, "image/png")},
141
  )
142
+ print(res.text)
143
+ imgUrl = res.json()["imageUrl"]
144
  # s3.upload_fileobj(image, "comic-assets", out_path, ExtraArgs={"ACL": "public-read"})
145
  image.close()
146
 
147
+ image_url = imgUrl
148
  print({"promptImages": image_url})
149
 
150
  return image_url
 
192
 
193
 
194
  def construct_default_s3_url(key):
195
+ return "https://assets.autodraft.in/" + key
196
 
197
 
198
  def safe_index(array, index) -> Optional[Any]:
internals/util/config.py CHANGED
@@ -88,9 +88,9 @@ def api_headers():
88
 
89
  def api_endpoint():
90
  if env == "prod":
91
- return "https://prod.pratilipicomics.com"
92
  else:
93
- return "https://gamma.pratilipicomics.com"
94
 
95
 
96
  def comic_url():
 
88
 
89
  def api_endpoint():
90
  if env == "prod":
91
+ return "https://api.autodraft.in"
92
  else:
93
+ return "https://api.autodraft.in"
94
 
95
 
96
  def comic_url():