arkxcc commited on
Commit
42193e2
1 Parent(s): 3d3b567

fix: reverting to the latest version with some updates

Browse files
Files changed (2) hide show
  1. __pycache__/server.cpython-39.pyc +0 -0
  2. server.py +6 -20
__pycache__/server.cpython-39.pyc CHANGED
Binary files a/__pycache__/server.cpython-39.pyc and b/__pycache__/server.cpython-39.pyc differ
 
server.py CHANGED
@@ -14,14 +14,11 @@ import recolorLumaConverterAlgo
14
  import recolorPaletteBasedTransfer
15
  import recolorReinhardV2Algo
16
  import recolorLinearColorTransfer
17
- import recolorStrictTransfer
18
  import matchCollection
19
  import ColorReplacer
20
  import ColorMask
21
  from typing import Optional
22
 
23
- import random
24
-
25
  app = FastAPI()
26
 
27
  app.add_middleware(
@@ -32,7 +29,7 @@ app.add_middleware(
32
  allow_headers=["*"],
33
  )
34
  @app.post("/dominantColor")
35
- async def dominant_color(file: UploadFile = File(...), num_colors: int = Form(...), ordered: bool = Form(False)):
36
  """
37
  Receive an image file and an integer and return the dominant color(s).
38
  """
@@ -44,7 +41,6 @@ async def dominant_color(file: UploadFile = File(...), num_colors: int = Form(..
44
  dominantColorsHex = [dominantColors.rgb_to_hex(color) for color in dominantColorsRGB]
45
  return {"dominantColors": dominantColorsHex}
46
 
47
-
48
  @app.post("/ColorPalettes/")
49
  async def color_palettes(colors: str = Form(...)):
50
  """
@@ -77,14 +73,13 @@ async def color_palettes(colors: str = Form(...)):
77
  return {"inputColor": colors, "complementaryColors": complementaryColors, "adjacentColors": adjacentColors, "gradientColors": gradientColors}
78
 
79
  @app.post("/recolor/")
80
- async def recolor(file: UploadFile = File(...), colors: str = Form(...), new_colors: str = Form(...), random_colors: bool = Form(False), model: str = Form(...), mask: Optional[UploadFile] = File(None)):
81
  """
82
  Receive an image file and an array of strings representing colors of a selected pallete and recolor an image.
83
  """
84
  method = model
85
  invertColors = False
86
  colors = [color.strip() for color in colors.split(',')]
87
- new_colors = [new_color.strip() for new_color in new_colors.split(',')]
88
  file_content = await file.read()
89
  image_bytes = io.BytesIO(file_content)
90
  image = Image.open(image_bytes)
@@ -96,43 +91,34 @@ async def recolor(file: UploadFile = File(...), colors: str = Form(...), new_col
96
  print('CCA generated')
97
  #Characteristic Color Analysis
98
  recolorReinhardAlgo.recolor(image_np, colors)
99
-
100
  elif method == "OTA":
101
  print('OTA generated')
102
  #Optimal Transport Algorithm transfer
103
  recolorOTAlgo.recolor(image_np, colors)
104
-
105
  elif method =="KMEANS":
106
  print('KMEANS generated')
107
  #K-means clustering transfer
108
  recolorTransferAlgo.recolor(image_np, colors)
109
-
110
  elif method == "LUMA":
111
  print('Luma generated')
112
  #Luma converter transfer
113
  recolorLumaConverterAlgo.remap_image_colors(image_np, colors)
114
-
115
  elif method == "palette":
116
  #palette transfer
117
  print('palette generated')
118
  recolorPaletteBasedTransfer.recolor(image_np, colors)
119
-
120
  elif method == "Reinhardv2":
121
  print('Reinhardv2 generated')
122
  recolorReinhardV2Algo.recolor(image_np, colors)
123
-
124
  elif method == "LinearColorTransfer":
125
  print('LinearColorTransfer generated')
126
  recolorLinearColorTransfer.recolor(image_np, colors)
127
-
128
- elif method == "StrictTransfer":
129
- print('StrictTransfer started')
130
- if random_colors:
131
- random.shuffle(new_colors)
132
- recolorStrictTransfer.recolor(image_np, colors, new_colors)
133
-
134
  elif method == "ColorMask":
135
  print('ColorMask started')
 
136
  ColorMask.create_mask(image_np, colors[0])
137
 
138
  #mask image:
 
14
  import recolorPaletteBasedTransfer
15
  import recolorReinhardV2Algo
16
  import recolorLinearColorTransfer
 
17
  import matchCollection
18
  import ColorReplacer
19
  import ColorMask
20
  from typing import Optional
21
 
 
 
22
  app = FastAPI()
23
 
24
  app.add_middleware(
 
29
  allow_headers=["*"],
30
  )
31
  @app.post("/dominantColor")
32
+ async def dominant_color(file: UploadFile = File(...), num_colors: int = Form(...)):
33
  """
34
  Receive an image file and an integer and return the dominant color(s).
35
  """
 
41
  dominantColorsHex = [dominantColors.rgb_to_hex(color) for color in dominantColorsRGB]
42
  return {"dominantColors": dominantColorsHex}
43
 
 
44
  @app.post("/ColorPalettes/")
45
  async def color_palettes(colors: str = Form(...)):
46
  """
 
73
  return {"inputColor": colors, "complementaryColors": complementaryColors, "adjacentColors": adjacentColors, "gradientColors": gradientColors}
74
 
75
  @app.post("/recolor/")
76
+ async def recolor(file: UploadFile = File(...), colors: str = Form(...), model: str = Form(...), mask: Optional[UploadFile] = File(None)):
77
  """
78
  Receive an image file and an array of strings representing colors of a selected pallete and recolor an image.
79
  """
80
  method = model
81
  invertColors = False
82
  colors = [color.strip() for color in colors.split(',')]
 
83
  file_content = await file.read()
84
  image_bytes = io.BytesIO(file_content)
85
  image = Image.open(image_bytes)
 
91
  print('CCA generated')
92
  #Characteristic Color Analysis
93
  recolorReinhardAlgo.recolor(image_np, colors)
 
94
  elif method == "OTA":
95
  print('OTA generated')
96
  #Optimal Transport Algorithm transfer
97
  recolorOTAlgo.recolor(image_np, colors)
 
98
  elif method =="KMEANS":
99
  print('KMEANS generated')
100
  #K-means clustering transfer
101
  recolorTransferAlgo.recolor(image_np, colors)
 
102
  elif method == "LUMA":
103
  print('Luma generated')
104
  #Luma converter transfer
105
  recolorLumaConverterAlgo.remap_image_colors(image_np, colors)
 
106
  elif method == "palette":
107
  #palette transfer
108
  print('palette generated')
109
  recolorPaletteBasedTransfer.recolor(image_np, colors)
 
110
  elif method == "Reinhardv2":
111
  print('Reinhardv2 generated')
112
  recolorReinhardV2Algo.recolor(image_np, colors)
 
113
  elif method == "LinearColorTransfer":
114
  print('LinearColorTransfer generated')
115
  recolorLinearColorTransfer.recolor(image_np, colors)
116
+ elif method == "ColorReplacer":
117
+ print('ColorReplacer started')
118
+ ColorReplacer.recolor_selected_area(image_np, colors[0], colors[1])
 
 
 
 
119
  elif method == "ColorMask":
120
  print('ColorMask started')
121
+ print(colors)
122
  ColorMask.create_mask(image_np, colors[0])
123
 
124
  #mask image: