Demo-EM / app.py
wajid's picture
Update app.py
05cf6e9
raw
history blame
5.26 kB
# -*- 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
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()