Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -0,0 +1,67 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio.inputs
|
2 |
+
import gradio as gr
|
3 |
+
|
4 |
+
import pickle
|
5 |
+
import pandas as pd
|
6 |
+
import sklearn
|
7 |
+
from sklearn.preprocessing import OneHotEncoder
|
8 |
+
from sklearn.preprocessing import OrdinalEncoder
|
9 |
+
from sklearn.pipeline import Pipeline
|
10 |
+
from sklearn.compose import ColumnTransformer
|
11 |
+
from sklearn.compose import make_column_selector as selector
|
12 |
+
#from sklearn.ensemble import HistGradientBoostingClassifier
|
13 |
+
|
14 |
+
|
15 |
+
with open('./model_leads.pck', 'rb') as f:
|
16 |
+
model = pickle.load(f)
|
17 |
+
|
18 |
+
labels = ["No, no será cliente", "Sí, será un cliente"]
|
19 |
+
|
20 |
+
def convert(lead_origin, lead_source, do_not_email, totalvisits,total_time_spent_on_website, page_views_per_visit, last_activity,
|
21 |
+
specialization, what_is_your_current_occupation, tags, city, a_free_copy_of_mastering_the_interview, last_notable_activity ):
|
22 |
+
#Se crea un dataframe con los datos enviados
|
23 |
+
df = pd.DataFrame()
|
24 |
+
df['lead_origin'] = [lead_origin]
|
25 |
+
df['lead_source'] = [lead_source]
|
26 |
+
df['do_not_email'] = [do_not_email]
|
27 |
+
df['totalvisits'] = [totalvisits]
|
28 |
+
df['total_time_spent_on_website'] = [total_time_spent_on_website]
|
29 |
+
df['page_views_per_visit'] = [page_views_per_visit]
|
30 |
+
df['last_activity'] = [last_activity]
|
31 |
+
df['specialization'] = [specialization]
|
32 |
+
df['what_is_your_current_occupation'] = [what_is_your_current_occupation]
|
33 |
+
df['tags'] = [tags]
|
34 |
+
df['city'] = [city]
|
35 |
+
df['a_free_copy_of_mastering_the_interview'] = [a_free_copy_of_mastering_the_interview]
|
36 |
+
df['last_notable_activity'] = [last_notable_activity]
|
37 |
+
#El modelo hace su predicción
|
38 |
+
prediction = model.predict_proba(df).flatten()
|
39 |
+
print(prediction)
|
40 |
+
#Se devuelve el percentaje que el modelo ha predicho para cada etiqueta
|
41 |
+
return {labels[i]: float(prediction[i]) for i in range(2)}
|
42 |
+
#return {"No, no será cliente": prediction[0], "Sí, será un cliente": prediction[1]}
|
43 |
+
|
44 |
+
|
45 |
+
iface = gr.Interface(
|
46 |
+
fn=convert,
|
47 |
+
inputs= [
|
48 |
+
gr.inputs.Dropdown(["landing_page_submission", "api", "lead_add_form", "lead_import"]),
|
49 |
+
gr.inputs.Dropdown(['olark_chat', 'organic_search', 'direct_traffic', 'google', 'referral_sites', 'reference', 'welingak_website', 'social_media' ,'others', 'live_chat']),
|
50 |
+
gr.inputs.Checkbox(),
|
51 |
+
gr.inputs.Slider(0, 150),
|
52 |
+
gr.inputs.Slider(0, 1000),
|
53 |
+
gr.inputs.Slider(0, 15),
|
54 |
+
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']),
|
55 |
+
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']),
|
56 |
+
gr.inputs.Dropdown(['unemployed', 'student' ,'working_professional', 'businessman', 'other', 'housewife']),
|
57 |
+
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']),
|
58 |
+
gr.inputs.Dropdown(['mumbai', 'thane_&_outskirts', 'other_metro_cities', 'other_cities', 'other_cities_of_maharashtra', 'tier_ii_cities']),
|
59 |
+
gr.inputs.Checkbox(),
|
60 |
+
gr.inputs.Dropdown(['modified', 'email_opened', 'page_visited_on_website', 'other_notable_activity', 'email_link_clicked', 'olark_chat_conversation', 'sms_sent']),
|
61 |
+
],
|
62 |
+
outputs="label",
|
63 |
+
title="¿Se convetirá en cliente?",
|
64 |
+
description="Aplicación de aprendizaje automático que predice la probabilidad de que un potencial cliente contrate los servicios de nuestra empresa",
|
65 |
+
)
|
66 |
+
|
67 |
+
iface.launch()
|