Upload app.py
Browse files
app.py
ADDED
@@ -0,0 +1,122 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# -*- coding: utf-8 -*-
|
2 |
+
"""Gradio_final_version_upwork_.ipynb
|
3 |
+
|
4 |
+
Automatically generated by Colaboratory.
|
5 |
+
|
6 |
+
Original file is located at
|
7 |
+
https://colab.research.google.com/drive/1aoMHIwjlYzuHId1tfByJINN1Gazb7bzL
|
8 |
+
"""
|
9 |
+
|
10 |
+
|
11 |
+
|
12 |
+
from joblib import dump, load
|
13 |
+
import pickle
|
14 |
+
import gradio as gr
|
15 |
+
import pandas as pd
|
16 |
+
import json
|
17 |
+
from random import randint
|
18 |
+
filename="Pre_Trained_Model_Setting_v15.sav"
|
19 |
+
modlist_loaded = pickle.load(open(filename, 'rb'))
|
20 |
+
|
21 |
+
clf = modlist_loaded[0]
|
22 |
+
enc = modlist_loaded[1]
|
23 |
+
lis = modlist_loaded[2]
|
24 |
+
cs = modlist_loaded[3]
|
25 |
+
df = modlist_loaded[4]
|
26 |
+
df3 = modlist_loaded[5]
|
27 |
+
df5 = modlist_loaded[6]
|
28 |
+
vendor_small = modlist_loaded[7]
|
29 |
+
vendor_mid = modlist_loaded[8]
|
30 |
+
vendor_large = modlist_loaded[9]
|
31 |
+
|
32 |
+
def get_probability(Industry, Company_Size):
|
33 |
+
var=(clf.predict_proba(enc.transform([[Industry,Company_Size]])))
|
34 |
+
var=var.transpose()
|
35 |
+
var=var.tolist()
|
36 |
+
name=clf.classes_.tolist()
|
37 |
+
dataset = pd.DataFrame({'Prob': var, 'Name':name},columns=['Prob','Name'])
|
38 |
+
df=dataset.sort_values('Prob',ascending=False)
|
39 |
+
return df
|
40 |
+
|
41 |
+
def start(Industry, Company_Size):
|
42 |
+
|
43 |
+
|
44 |
+
if (Industry == "" or Industry== None) and (Company_Size !="" and Company_Size!=None):
|
45 |
+
return "Please Select Industry Drop Down", Company_Size
|
46 |
+
|
47 |
+
if (Company_Size== "" or Company_Size== None) and (Industry != "" and Industry!=None):
|
48 |
+
return Industry,"Please Select Company Size Drop Down"
|
49 |
+
|
50 |
+
if (Industry == "" or Industry== None) and (Company_Size =="" or Industry== None):
|
51 |
+
return "Please Select Industry Drop Down", "Please Select Company Size Drop Down"
|
52 |
+
else:
|
53 |
+
|
54 |
+
|
55 |
+
|
56 |
+
df_=get_probability(Industry, Company_Size)
|
57 |
+
spec_titles = ["recommendedVendor", "recommendationScore", "vendorPros", "vendorCons"]
|
58 |
+
cars = {}
|
59 |
+
title="Recommendation for " + str(Industry) + " Industry having company size " + str(Company_Size)
|
60 |
+
vehical_data = {title: [cars]}
|
61 |
+
lst_prob=[]
|
62 |
+
sum_first_prob=df_["Prob"].iloc[0][0]
|
63 |
+
|
64 |
+
for x in range(5,len(df_)):
|
65 |
+
sum_first_prob+=df_["Prob"].iloc[x][0]
|
66 |
+
|
67 |
+
lst_prob.append(sum_first_prob)
|
68 |
+
|
69 |
+
for x in range(1,5):
|
70 |
+
prob=df_["Prob"].iloc[x][0]
|
71 |
+
lst_prob.append(prob)
|
72 |
+
|
73 |
+
|
74 |
+
for n in range(0,5):
|
75 |
+
name = "Recommendation Number " + str(n+1)
|
76 |
+
vendor_name=df_["Name"].iloc[n]
|
77 |
+
vendor_prob=lst_prob[n]
|
78 |
+
# vendor_prob=round(float(vendor_prob)*100)
|
79 |
+
if n==0:
|
80 |
+
vendor_prob=round(float(vendor_prob)*100)+30
|
81 |
+
else:
|
82 |
+
vendor_prob=round(float(vendor_prob)*100)+45
|
83 |
+
if vendor_prob>round(float(lst_prob[0])*100)+30:
|
84 |
+
vendor_prob=vendor_prob-10
|
85 |
+
|
86 |
+
|
87 |
+
|
88 |
+
vendor_pros=(df5.loc[df5['Vendor Name'] == str(vendor_name)]["Pros"]).item()
|
89 |
+
vendor_cons=(df5.loc[df5['Vendor Name'] == str(vendor_name)]["Cons"]).item()
|
90 |
+
user_satisfaction=""
|
91 |
+
|
92 |
+
|
93 |
+
|
94 |
+
|
95 |
+
|
96 |
+
if Company_Size=="Self Employed" or Company_Size=="2-10 Employees" or Company_Size=="11-50 Employees":
|
97 |
+
user_satisfaction=str(vendor_small[str(vendor_name)]) +"% of " + str(vendor_name) + "'s small business users are satisfied with it"
|
98 |
+
|
99 |
+
elif Company_Size=="51-200 Employees" or Company_Size=="201-500 Employees" or Company_Size=="501-1,000 Employees":
|
100 |
+
user_satisfaction=str(vendor_mid[vendor_name]) +"% of" + vendor_name + "'s medium business users are satisfied with it"
|
101 |
+
|
102 |
+
elif Company_Size=="1,001-5,000 Employees" or Company_Size=="5,001-10,000 Employees" or Company_Size=="10,000+ Employees":
|
103 |
+
user_satisfaction=str(vendor_large[vendor_name]) +"% of" + vendor_name + "'s large business users are satisfied with it"
|
104 |
+
|
105 |
+
|
106 |
+
|
107 |
+
|
108 |
+
|
109 |
+
|
110 |
+
|
111 |
+
|
112 |
+
|
113 |
+
|
114 |
+
spec_details = [str(vendor_name), str(vendor_prob)+"%", str(vendor_pros), str(vendor_cons),str(user_satisfaction)]
|
115 |
+
car_data = dict(zip(spec_titles, spec_details))
|
116 |
+
cars[name] = car_data
|
117 |
+
js=json.dumps(vehical_data)
|
118 |
+
return vehical_data
|
119 |
+
|
120 |
+
face = gr.Interface(fn=start, inputs=[gr.Dropdown(lis), gr.Dropdown(cs),], outputs=["json"],allow_flagging="never")
|
121 |
+
face.launch()
|
122 |
+
|