cd14 commited on
Commit
fe913b9
·
1 Parent(s): c249a13

bug fixing for df_recom_extra

Browse files
Files changed (1) hide show
  1. app.py +25 -3
app.py CHANGED
@@ -42,6 +42,21 @@ def create_image(width, height, rgb_color=(0, 0, 0)):
42
  image[:] = color
43
  return image
44
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
45
  def add_bg_from_url():
46
  st.markdown(
47
  f"""
@@ -439,7 +454,12 @@ def select_cta_button(ccolor, text):
439
  #st.write(st.session_state)
440
  buttons_out=[]
441
  for x in np.arange(len(st.session_state.ccolor)):
442
- ctab=st.button("Call_To_Action text: "+str(st.session_state.text[x])+"; color: "+str(st.session_state.ccolor[x]), key = x)
 
 
 
 
 
443
  res=[]
444
  res.append(x)
445
  val={}
@@ -663,6 +683,8 @@ def get_predictions(selected_variable, selected_industry, selected_campaign,
663
  # df_recom_opt_rank = df_recom_opt.nlargest(3, [selected_variable])
664
 
665
  print(f"\nTo get a higher {selected_variable}, the model recommends the following options: ")
 
 
666
  if len(df_recom_opt_rank_out) < 2:
667
  # st.markdown('##### Youve already achieved the highest {} with the current Call-To-Action Colors!'.format(selected_variable), unsafe_allow_html=True)
668
  # print("You've already achieved the highest", selected_variable,
@@ -676,7 +698,7 @@ def get_predictions(selected_variable, selected_industry, selected_campaign,
676
  color_img=create_image(100,30,color_rgb)
677
  st.image(color_img, channels='BGR')
678
  # st.markdown('##### recom_cta is: <span style="color:yellow">{}</span>'.format(recom_cta), unsafe_allow_html=True)
679
- st.markdown('##### target_rate for recom_cta is: <span style="color:yellow">{}</span>'.format(round(target_rate*100, 2)), unsafe_allow_html=True)
680
 
681
 
682
  print(f" {(color(' ', fore='#ffffff', back=recom_cta))} \x1b[1m{round(target_rate*100, 2)}%\x1b[22m")
@@ -689,7 +711,7 @@ def get_predictions(selected_variable, selected_industry, selected_campaign,
689
  color_img=create_image(100,30,color_rgb)
690
  st.image(color_img, channels='BGR')
691
  # st.markdown('##### recom_cta is: {}'.format(recom_cta), unsafe_allow_html=True)
692
- st.markdown('##### target_rate for recom_cta is: <span style="color:yellow">{}</span>'.format(round(target_rate*100, 2)), unsafe_allow_html=True)
693
  print(f" {(color(' ', fore='#ffffff', back=recom_cta))} \x1b[1m{round(target_rate*100, 2)}%\x1b[22m")
694
 
695
  elif selected_cta == 'Text':
 
42
  image[:] = color
43
  return image
44
 
45
+ def add_text(image, cta_txt):
46
+ font = cv2.FONT_HERSHEY_SIMPLEX
47
+ # fontScale
48
+ fontScale = 1
49
+ # Blue color in BGR
50
+ color = (0, 0, 255)
51
+
52
+ # Line thickness of 2 px
53
+ h=img.shape[0]/2
54
+ w=img.shape[1]/2
55
+ thickness = 2
56
+ image = cv2.putText(image, cta_txt, (h,w), font,
57
+ fontScale, color, thickness, cv2.LINE_AA)
58
+ return image
59
+
60
  def add_bg_from_url():
61
  st.markdown(
62
  f"""
 
454
  #st.write(st.session_state)
455
  buttons_out=[]
456
  for x in np.arange(len(st.session_state.ccolor)):
457
+ color_rgb=get_rgb(recom_cta)
458
+ color_img=create_image(100,30,color_rgb)
459
+ color_img=add_text(color_img,"Call_To_Action text: "+str(st.session_state.text[x]))
460
+ st.image(color_img, channels='BGR')
461
+ # ctab=st.button("Call_To_Action text: "+str(st.session_state.text[x])+"; color: "+str(st.session_state.ccolor[x]), key = x)
462
+ ctab=st.button("Select This CTA button to optimize", key = x)
463
  res=[]
464
  res.append(x)
465
  val={}
 
683
  # df_recom_opt_rank = df_recom_opt.nlargest(3, [selected_variable])
684
 
685
  print(f"\nTo get a higher {selected_variable}, the model recommends the following options: ")
686
+ st.markdown('##### To get a higher {}, the model recommends the following options:'.format(selected_variable), unsafe_allow_html=True)
687
+
688
  if len(df_recom_opt_rank_out) < 2:
689
  # st.markdown('##### Youve already achieved the highest {} with the current Call-To-Action Colors!'.format(selected_variable), unsafe_allow_html=True)
690
  # print("You've already achieved the highest", selected_variable,
 
698
  color_img=create_image(100,30,color_rgb)
699
  st.image(color_img, channels='BGR')
700
  # st.markdown('##### recom_cta is: <span style="color:yellow">{}</span>'.format(recom_cta), unsafe_allow_html=True)
701
+ st.markdown('##### target_rate for above recommended CTA button Color is: <span style="color:yellow">{}</span>'.format(round(target_rate*100, 2)), unsafe_allow_html=True)
702
 
703
 
704
  print(f" {(color(' ', fore='#ffffff', back=recom_cta))} \x1b[1m{round(target_rate*100, 2)}%\x1b[22m")
 
711
  color_img=create_image(100,30,color_rgb)
712
  st.image(color_img, channels='BGR')
713
  # st.markdown('##### recom_cta is: {}'.format(recom_cta), unsafe_allow_html=True)
714
+ st.markdown('##### target_rate for above recommended CTA button Color is: <span style="color:yellow">{}</span>'.format(round(target_rate*100, 2)), unsafe_allow_html=True)
715
  print(f" {(color(' ', fore='#ffffff', back=recom_cta))} \x1b[1m{round(target_rate*100, 2)}%\x1b[22m")
716
 
717
  elif selected_cta == 'Text':