Ilia Azizi commited on
Commit
04f132f
1 Parent(s): 6a99c92

Launched app

Browse files
Files changed (3) hide show
  1. README.md +3 -5
  2. app.py +86 -0
  3. requirements.txt +5 -0
README.md CHANGED
@@ -1,12 +1,10 @@
1
  ---
2
  title: Real_estate_ie
3
- emoji: 🐨
4
  colorFrom: indigo
5
  colorTo: blue
6
  sdk: gradio
7
  sdk_version: 3.0.11
8
  app_file: app.py
9
- pinned: false
10
- ---
11
-
12
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces#reference
 
1
  ---
2
  title: Real_estate_ie
3
+ emoji: 🏡
4
  colorFrom: indigo
5
  colorTo: blue
6
  sdk: gradio
7
  sdk_version: 3.0.11
8
  app_file: app.py
9
+ pinned: true
10
+ ---
 
 
app.py ADDED
@@ -0,0 +1,86 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # all the imports
2
+ from transformers import pipeline
3
+ import gradio as gr
4
+ import torch
5
+ import re
6
+
7
+ #---------------------------------------------------------------------------------
8
+ # function modified for the demo
9
+ def get_native_feature_demo(language, input_description, target_feature, question, return_numbers = True):
10
+ task = 'question-answering'
11
+ french_model = 'etalab-ia/camembert-base-squadFR-fquad-piaf'
12
+ english_model = 'deepset/roberta-base-squad2'
13
+ if language == "French":
14
+ model = pipeline(task, model=french_model, tokenizer=french_model)
15
+ else:
16
+ model = pipeline(task, model=english_model, tokenizer=english_model)
17
+ answer = model({
18
+ 'question': question,
19
+ 'context': input_description
20
+ })
21
+ if target_feature == "price":
22
+ # price median
23
+ reference_target_value = 1650
24
+ else:
25
+ # living space median
26
+ reference_target_value = 85
27
+ try:
28
+ if return_numbers:
29
+ nums = re.findall(r"\d*\.\d+|\d+\,\d+|\d{1,3}'[\d{3}']+\d{1,3}\.?\d*|(?<!m)\d+",answer['answer'])
30
+ nums = [re.sub("\,|\'", "", num) for num in nums]
31
+ # turn every number into float
32
+ if len(nums) > 1:
33
+ nums = [float(x) for x in nums]
34
+ answer_processed = min(nums, key=lambda x:abs(x-reference_target_value))
35
+ elif len(nums) == 1:
36
+ answer_processed = float(''.join(nums))
37
+ else:
38
+ answer = answer['answer']
39
+ answer_full = answer['answer']
40
+ score = answer['score']
41
+ return round(answer_processed), score, answer_full
42
+ except:
43
+ return "No answer!", None, None
44
+
45
+ #---------------------------------------------------------------------------------
46
+ # define the parameters
47
+ title = "Extract relevant features from Real Estate Descriptions!"
48
+
49
+ description = """
50
+ <center>
51
+ <img src="https://i0.wp.com/lightersideofrealestate.com/wp-content/uploads/2014/11/2-koalafications.jpg" width=300px>
52
+ </center>
53
+ <div style="text-align: justify">
54
+ Features with missing instances can negatively impact the performance of machine learning models. Information Extraction (IE) can improve the availability of tabular data by identifying relevant information from unstructured textual descriptions. This project demonstrated the application of IE on descriptions of online real estate listings, whereby the required missing values are retrieved from the text. Inspired by question-answering tasks, the aim was to recover these values by asking a set of questions. We tested two ways to achieve this goal. The first one focuses on a model specific to the language of the description (French) to perform IE, while the second translates the descriptions into English before IE. The project compared the performance of both approaches while delivering insights on how the formulation of the questions can impact the effectiveness of Q&A models.
55
+ </div>
56
+ """
57
+ article = """
58
+ <center>
59
+
60
+ Created by [Ilia Azizi](https://iliaazizi.netlify.app/) 2022
61
+
62
+ </center>
63
+ """
64
+
65
+ interesting_case = """ Venez découvrir votre futur appartement lors des portes ouvertes Quai Ouest à Renens le samedi 6 mars de 9h00 à 12h00. Afin de respecter les mesures de sécurité, merci d'inscrire une personne par tranche horaire. Merci de laisser vos coordonnées (nom, email et téléphone) afin que l'on puisse vous joindre pour confirmer le rendez-vous et l'adresse. Lorsque vous entrer votre nom pour vous inscrire, merci d'indiquer également l'appartement que vous souhaitez visiter (n° ou nombre de pièces). En cas d'intérêt, merci de venir avec un dossier complet : - 3 dernières fiches de salaire - Extrait de l'office des poursuites - Copie carte d'identité ou permis de séjour - Copie de votre police d'assurance RC (responsabilité civile) et ménage Un formulaire de location sera à disposition sur place. Pour en savoir plus: https://quai-ouest.ch/location/logements\nINSCRIPTIONS : https://doodle.com/poll/5cvrqyt2ueaah3su?utm_source=poll&utm_medium=link\nNouvelle promotion de 89 logements en location idéalement située à la Gare de Renens, Quai Ouest ouvrira ses bras aux futurs locataires avec plusieurs options de logements, commerces et bureaux.\nCe magnifique appartement de 4.5 pièces se situe au 3° étage et a été construit avec de très beaux matériaux et se compose comme suit:\nSpacieux séjour de 40m2\nSuite parentale de 23.9m2 avec salle de douche italienne attenante\nDeux chambres à coucher d'environ 13m2 chacune\nRaccordement pour colonne de lavage\nUne salle de bains/WC\nCuisine ouverte avec îlot central et entièrement agencée avec lave-vaisselle\nStores électriques\nEntrée avec armoires murales\nLoyer net : CHF 2'600 .-\nCharges: CHF 320.-\nTotal: CHF 2'920.-\nAdresse: Place de la Gare à 1020 Renens\nPlus d'informations sur www.quai-ouest.ch/location/logements ainsi que chez Omnia Immobilier au 021 943 54 54 ou riviera@omnia.ch"""
66
+
67
+ examples = [["French", interesting_case, 'price', "Combien payez-vous de loyer?"],
68
+ ["French", interesting_case, 'living_space', "Quelle est la surface en m2?"]]
69
+
70
+ #---------------------------------------------------------------------------------
71
+ # run the demo
72
+ demo = gr.Interface(
73
+ fn=get_native_feature_demo,
74
+ inputs=[
75
+ gr.inputs.Radio(["French", "English"], label="Language", type = "value"),
76
+ gr.inputs.Textbox(lines=10, label="Real Estate Description", placeholder="Type a real estate description here."),
77
+ gr.inputs.Dropdown(["price", "living_space"], label="Target Feature", type = "value"),
78
+ gr.inputs.Textbox(lines=2, label="Question", placeholder="Ask to retrieve a feature.")],
79
+ outputs = [gr.outputs.Textbox(label = "Extracted Feature"), gr.outputs.Textbox(label = "Probability of the prediction"), gr.outputs.Textbox(label = "Full Q&A answer")],
80
+ title = title,
81
+ description = description,
82
+ article = article,
83
+ examples=examples
84
+ )
85
+
86
+ demo.launch(inline=False)
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ transformers
2
+ torch
3
+ regex
4
+ gradio
5
+ sentencepiece