predict_cliente / app.py
Marisa's picture
Update app.py
4bc709a
raw
history blame
No virus
3.84 kB
import gradio.inputs
import gradio as gr
import pickle
import pandas as pd
import sklearn
from sklearn.preprocessing import OneHotEncoder
from sklearn.preprocessing import OrdinalEncoder
from sklearn.pipeline import Pipeline
from sklearn.compose import ColumnTransformer
from sklearn.compose import make_column_selector as selector
#from sklearn.ensemble import HistGradientBoostingClassifier
with open('./model_leads.pck', 'rb') as f:
model = pickle.load(f)
labels = ["No, no será cliente", "Sí, será un cliente"]
def convert(lead_origin, lead_source, do_not_email, totalvisits,total_time_spent_on_website, page_views_per_visit, last_activity,
specialization, what_is_your_current_occupation, tags, city, a_free_copy_of_mastering_the_interview, last_notable_activity ):
#Se crea un dataframe con los datos enviados
df = pd.DataFrame()
df['lead_origin'] = [lead_origin]
df['lead_source'] = [lead_source]
df['do_not_email'] = [do_not_email]
df['totalvisits'] = [totalvisits]
df['total_time_spent_on_website'] = [total_time_spent_on_website]
df['page_views_per_visit'] = [page_views_per_visit]
df['last_activity'] = [last_activity]
df['specialization'] = [specialization]
df['what_is_your_current_occupation'] = [what_is_your_current_occupation]
df['tags'] = [tags]
df['city'] = [city]
df['a_free_copy_of_mastering_the_interview'] = [a_free_copy_of_mastering_the_interview]
df['last_notable_activity'] = [last_notable_activity]
#El modelo hace su predicción
prediction = model.predict_proba(df).flatten()
print(prediction)
#Se devuelve el percentaje que el modelo ha predicho para cada etiqueta
return {labels[i]: float(prediction[i]) for i in range(2)}
#return {"No, no será cliente": prediction[0], "Sí, será un cliente": prediction[1]}
iface = gr.Interface(
fn=convert,
inputs= [
gr.inputs.Dropdown(["landing_page_submission", "api", "lead_add_form", "lead_import"]),
gr.inputs.Dropdown(['olark_chat', 'organic_search', 'direct_traffic', 'google', 'referral_sites', 'reference', 'welingak_website', 'social_media' ,'others', 'live_chat']),
gr.inputs.Checkbox(),
gr.inputs.Slider(0, 150),
gr.inputs.Slider(0, 1000),
gr.inputs.Slider(0, 15),
gr.inputs.Dropdown(['page_visited_on_website', 'email_opened', 'others', 'converted_to_lead', 'olark_chat_conversation', 'email_bounced', 'email_link_clicked', 'form_submitted_on_website', 'sms_sent']),
gr.inputs.Dropdown(['not_specified', 'business_administration', 'media_and_advertising', 'management_specializations', 'travel_and_tourism', 'banking,_investment_and_insurance', 'international_business', 'e-commerce', 'services_excellence', 'rural_and_agribusiness', 'e-business']),
gr.inputs.Dropdown(['unemployed', 'student' ,'working_professional', 'businessman', 'other', 'housewife']),
gr.inputs.Dropdown(['interested_in_other_courses', 'ringing', 'will_revert_after_reading_the_email', 'not_specified', 'lost_to_eins', 'other_tags', 'busy', 'closed_by_horizzon', 'interested__in_full_time_mba', 'lateral_student']),
gr.inputs.Dropdown(['mumbai', 'thane_&_outskirts', 'other_metro_cities', 'other_cities', 'other_cities_of_maharashtra', 'tier_ii_cities']),
gr.inputs.Checkbox(),
gr.inputs.Dropdown(['modified', 'email_opened', 'page_visited_on_website', 'other_notable_activity', 'email_link_clicked', 'olark_chat_conversation', 'sms_sent']),
],
outputs="label",
title="¿Se convetirá en cliente?",
description="Aplicación de aprendizaje automático que predice la probabilidad de que un potencial cliente contrate los servicios de nuestra empresa",
)
iface.launch()