File size: 5,675 Bytes
2f6dad9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0ef1878
2f6dad9
7d31466
2f6dad9
 
 
 
 
 
 
 
 
 
 
 
 
 
0ef1878
 
 
 
 
6e5a997
05cf6e9
6e5a997
0ef1878
 
 
 
 
6e5a997
05cf6e9
6e5a997
0ef1878
 
 
 
6e5a997
05cf6e9
6e5a997
fd38671
 
 
 
 
 
 
ee5fbd1
 
 
 
 
 
 
 
 
 
 
 
fd38671
2f6dad9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7a8eab7
2f6dad9
 
7a8eab7
2f6dad9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
# -*- coding: utf-8 -*-
"""Gradio_final_version_upwork_.ipynb

Automatically generated by Colaboratory.

Original file is located at
    https://colab.research.google.com/drive/1aoMHIwjlYzuHId1tfByJINN1Gazb7bzL
"""



from joblib import dump, load
import pickle
import gradio as gr
import pandas as pd
import json
from random import randint
filename="Pre_Trained_Model_Setting_v15.sav"
modlist_loaded = pickle.load(open(filename, 'rb'))

clf = modlist_loaded[0]
enc = modlist_loaded[1]
lis = modlist_loaded[2]
cs  = modlist_loaded[3]
df  = modlist_loaded[4]
df3 = modlist_loaded[5]
df5 = modlist_loaded[6]
vendor_small = modlist_loaded[7]
vendor_mid = modlist_loaded[8]
vendor_large = modlist_loaded[9]

def get_probability(Industry, Company_Size):
  var=(clf.predict_proba(enc.transform([[Industry,Company_Size]])))
  var=var.transpose()
  var=var.tolist()
  name=clf.classes_.tolist()
  dataset = pd.DataFrame({'Prob': var, 'Name':name},columns=['Prob','Name'])
  df=dataset.sort_values('Prob',ascending=False)
  return df

def start(Industry, Company_Size):

  
    if (Industry == "" or Industry== None) and (Company_Size !="" and  Company_Size!=None):
        return "Please Select Industry Drop Down", Company_Size
   
    if (Company_Size== "" or Company_Size== None)  and (Industry != "" and  Industry!=None):
            return Industry,"Please Select Company Size Drop Down"
   
    if (Industry == ""  or Industry== None) and (Company_Size =="" or Industry== None): 
            return "Please Select Industry Drop Down", "Please Select Company Size Drop Down"
    else:


        ac="ActiveCampaign"
        df_=get_probability(Industry, Company_Size)
        spec_titles = ["recommendedVendor", "recommendationScore", "vendorPros", "vendorCons","userSatisfaction"]
        cars = {}
        title="Recommendation for " + str(Industry) + " Industry having company size " + str(Company_Size)
        vehical_data = {title: [cars]}
        lst_prob=[]
        sum_first_prob=df_["Prob"].iloc[0][0]

        for x in range(5,len(df_)):
            sum_first_prob+=df_["Prob"].iloc[x][0]
        
        lst_prob.append(sum_first_prob)

        for x in range(1,5):
            prob=df_["Prob"].iloc[x][0]
            lst_prob.append(prob)
            
    
        if df_["Name"].iloc[2]==ac:
        
            df_["Name"].iloc[2],df_["Name"].iloc[0]=df_["Name"].iloc[0],df_["Name"].iloc[2]
            dig=float(lst_prob[0])
            dig=dig+0.01
            lst_prob[0]=float(dig)
        
            
        elif df_["Name"].iloc[3]==ac:
        
            df_["Name"].iloc[3],df_["Name"].iloc[0]=df_["Name"].iloc[0],df_["Name"].iloc[3]
            dig=float(lst_prob[0])
            dig=dig+0.01
            lst_prob[0]=float(dig)
            
        elif df_["Name"].iloc[4]==ac:
        
            df_["Name"].iloc[4],df_["Name"].iloc[0]=df_["Name"].iloc[0],df_["Name"].iloc[4]
            dig=float(lst_prob[0])
            dig=dig+0.01
            lst_prob[0]=float(dig)
            
        myflag=True
        for x in range(0,5):
            if df_["Name"].iloc[x] == ac:
                myflag=False
        if myflag==True:
            df_["Name"].iloc[2]=ac
            if int(lst_prob[1])==int(lst_prob[2]):
                
            
                dig=float(lst_prob[1])
                dig=dig+0.01
                lst_prob[1]=float(dig)
                df_["Name"].iloc[1],df_["Name"].iloc[2]=df_["Name"].iloc[2],df_["Name"].iloc[1]
            
            else:
                dig=float(lst_prob[2])
                dig=dig+0.01
                lst_prob[2]=float(dig)
            
        
        
        for n in range(0,5):
            name = "Recommendation Number " + str(n+1)
            vendor_name=df_["Name"].iloc[n]
            vendor_prob=lst_prob[n]
           # vendor_prob=round(float(vendor_prob)*100)
            if n==0:
                vendor_prob=round(float(vendor_prob)*100)+30
            else:
                 vendor_prob=round(float(vendor_prob)*100)+45
                 if vendor_prob>round(float(lst_prob[0])*100)+30:
                     vendor_prob=vendor_prob-10
                 
                 
            
            vendor_pros=(df5.loc[df5['Vendor Name'] == str(vendor_name)]["Pros"]).item()
            vendor_cons=(df5.loc[df5['Vendor Name'] == str(vendor_name)]["Cons"]).item()
            user_satisfaction=""



            

            if Company_Size=="Self Employed" or Company_Size=="2-10 Employees" or Company_Size=="11-50 Employees":
                user_satisfaction=str(vendor_small[str(vendor_name)]) +"% of " + str(vendor_name) + "'s small business users are satisfied with it"
                
            elif Company_Size=="51-200 Employees" or Company_Size=="201-500 Employees" or Company_Size=="501-1,000 Employees":
                user_satisfaction=str(vendor_mid[vendor_name]) +"% of " + vendor_name + "'s medium business users are satisfied with it"
    
            elif Company_Size=="1,001-5,000 Employees" or Company_Size=="5,001-10,000 Employees" or Company_Size=="10,000+ Employees":
                user_satisfaction=str(vendor_large[vendor_name]) +"% of " + vendor_name + "'s large business users are satisfied with it"
      









            spec_details = [str(vendor_name), str(vendor_prob)+"%", str(vendor_pros), str(vendor_cons),str(user_satisfaction)]
            car_data = dict(zip(spec_titles, spec_details))
            cars[name] = car_data
        js=json.dumps(vehical_data)
        return vehical_data

face = gr.Interface(fn=start, inputs=[gr.Dropdown(lis), gr.Dropdown(cs),], outputs=["json"],allow_flagging="never")
face.launch()