File size: 1,537 Bytes
06a851e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import streamlit as st
import numpy as np
import torch
from babel.numbers import format_currency

from bert.tokenize import get_tokenizer
from bert.model import CamembertRegressor
from bert.performance import predict




MODEL_STATE_DICT_PATH = './bert/trained_model/model_epoch_5.pt'



# ENVRIONMENT SET UP
if torch.cuda.is_available():       
    device = torch.device("cuda")
else:
    device = torch.device("cpu")


# MODEL LOADING
saved_model_dict = torch.load(MODEL_STATE_DICT_PATH, map_location=device)
model = CamembertRegressor()
model.load_state_dict(saved_model_dict['model_state_dict'])

tokenizer = get_tokenizer()
max_len = saved_model_dict['max_input_len']
scaler = saved_model_dict['labels_scaler']
    
    
# WEB APP
st.title("Text 2 Price - Real Estate")
st.markdown("")


example_description = "Superbe maison de 500m2 à Pétaouchnok..."
description = st.text_area("Décris ton bien immobilier : ", example_description)


if (len(description)>0) & (description != example_description):
    predicted_price = predict([description], tokenizer, scaler, model, device, 
                              max_len, 32, return_scaled=False)[0]
    predicted_price_formatted = format_currency(predicted_price, 'EUR', 
                                                locale='fr_FR')
    st.markdown('')
    st.markdown('')
    st.markdown('On estime que ton bien immobilier serait annoncé à :')
    st.markdown("<h1 style='text-align: center;'>" \
                + predicted_price_formatted + "</h1>", unsafe_allow_html=True)