Omnibus commited on
Commit
ada0ea4
·
verified ·
1 Parent(s): 331b121

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +50 -41
app.py CHANGED
@@ -67,56 +67,65 @@ def load_model(model_drop):
67
 
68
 
69
  def run_dif_color(out_prompt,im_path,model_drop,tint,im_height,im_width):
 
70
  p_seed=""
71
  out_box=[]
72
  out_html=""
73
- for i,ea in enumerate(im_path.root):
74
- print(f'root::{im_path.root[i]}')
75
- #print(f'ea:: {ea}')
76
- #print(f'impath:: {im_path.path}')
77
- url = base_url+im_path.root[i].image.path
78
- myimg = cv2.imread(im_path.root[i].image.path)
79
- avg_color_per_row = numpy.average(myimg, axis=0)
80
- avg_color = numpy.average(avg_color_per_row, axis=0)
81
- #print(avg_color)
82
-
83
- #h=color.lstrip('#')
84
- #h = input('Enter hex: ').lstrip('#')
85
- #print('RGB =', tuple(int(h[i:i+2], 16) for i in (0, 2, 4)))
86
- #color=tuple(int(h[i:i+2], 16) for i in (0, 2, 4))
87
- r,g,b= avg_color
88
-
89
- color = (int(r),int(g),int(b))
90
-
91
 
92
- print (color)
 
 
 
 
93
 
94
- #for i,ea in enumerate(loaded_model):
 
 
 
 
 
 
 
 
 
 
 
 
 
95
 
 
 
96
 
97
-
98
- #for i in range(int(cnt)):
99
- rand=random.randint(1,500)
100
- for i in range(rand):
101
- p_seed+=" "
102
- try:
103
- #model=gr.load(f'models/{model[int(model_drop)]}')
104
- model=loaded_model[int(model_drop)]
105
- out_img=model(out_prompt+p_seed)
106
- print(out_img)
107
-
108
- raw=Image.open(out_img)
109
- raw=raw.convert('RGB')
110
-
111
- colorize = RGBTransform().mix_with(color,factor=float(tint)).applied_to(raw)
 
112
 
113
- out_box.append(colorize)
114
- except Exception as e:
115
- print(e)
116
- out_html=str(e)
117
- pass
118
 
119
- yield out_box,out_html
 
 
 
 
 
 
 
120
 
121
 
122
 
 
67
 
68
 
69
  def run_dif_color(out_prompt,im_path,model_drop,tint,im_height,im_width):
70
+ uid=uuid.uuid4()
71
  p_seed=""
72
  out_box=[]
73
  out_html=""
74
+ #for i,ea in enumerate(im_path.root):
75
+ cnt = 0
76
+ for hh in range(int(im_height/grid_wide)):
77
+ for b in range(int(im_width/grid_wide)):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
78
 
79
+ print(f'root::{im_path.root[cnt]}')
80
+ #print(f'ea:: {ea}')
81
+ #print(f'impath:: {im_path.path}')
82
+ url = base_url+im_path.root[cnt].image.path
83
+ print(url)
84
 
85
+ myimg = cv2.imread(im_path.root[cnt].image.path)
86
+ avg_color_per_row = numpy.average(myimg, axis=0)
87
+ avg_color = numpy.average(avg_color_per_row, axis=0)
88
+ r,g,b= avg_color
89
+ color = (int(r),int(g),int(b))
90
+ print (color)
91
+ rand=random.randint(1,500)
92
+ for i in range(rand):
93
+ p_seed+=" "
94
+ try:
95
+ #model=gr.load(f'models/{model[int(model_drop)]}')
96
+ model=loaded_model[int(model_drop)]
97
+ out_img=model(out_prompt+p_seed)
98
+ print(out_img)
99
 
100
+ raw=Image.open(out_img)
101
+ raw=raw.convert('RGB')
102
 
103
+ colorize = RGBTransform().mix_with(color,factor=float(tint)).applied_to(raw)
104
+
105
+ out_box.append(colorize)
106
+ if out_box:
107
+ if len(out_box)>1:
108
+ im_roll = get_concat_v_cut(f'{out_box[0]}',f'{out_box[1]}')
109
+ im_roll.save(f'comb-{uid}-tmp.png')
110
+ for i in range(2,len(out_box)):
111
+ im_roll = get_concat_v_cut(f'comb-{uid}-tmp.png',f'{out_box[i]}')
112
+ im_roll.save(f'comb-{uid}-tmp.png')
113
+ out = f'comb-{uid}-tmp.png'
114
+ else:
115
+ #tmp_im = Image.open(out_box[0])
116
+ tmp_im = out_box[0]
117
+ tmp_im.save(f'comb-{uid}-tmp.png')
118
+ out = f'comb-{uid}-tmp.png'
119
 
 
 
 
 
 
120
 
121
+ except Exception as e:
122
+ print(e)
123
+ out_html=str(e)
124
+ pass
125
+
126
+ cnt+=1
127
+
128
+ yield out,out_html
129
 
130
 
131