Spaces:
Sleeping
Sleeping
Commit
·
577e5ce
1
Parent(s):
848efe8
ff.python
Browse files
f.python
ADDED
@@ -0,0 +1,100 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import torch
|
3 |
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
4 |
+
|
5 |
+
# Install necessary dependencies
|
6 |
+
!pip install -q gradio transformers
|
7 |
+
|
8 |
+
# Define the house price estimation function
|
9 |
+
def house_price_estimation(area, rooms, kitchens, doors, washrooms, manzalas, land_measurement, garden=False, garage=False, storage_room=False, electricity=False, gas=False, water=False, ac=False, geyser=False, roof=False):
|
10 |
+
# Perform calculations to estimate the house price based on the provided details
|
11 |
+
price = area * 100 + rooms * 2000 + kitchens * 1500
|
12 |
+
|
13 |
+
# Increase price based on land measurement
|
14 |
+
if land_measurement == "Marlas":
|
15 |
+
price += 500 * area
|
16 |
+
elif land_measurement == "Canals":
|
17 |
+
price += 1000 * area
|
18 |
+
|
19 |
+
# Increase price based on optional facilities
|
20 |
+
if garden:
|
21 |
+
price += 5000
|
22 |
+
if garage:
|
23 |
+
price += 4000
|
24 |
+
if storage_room:
|
25 |
+
price += 3000
|
26 |
+
if electricity:
|
27 |
+
price += 2000
|
28 |
+
if gas:
|
29 |
+
price += 3000
|
30 |
+
if water:
|
31 |
+
price += 2000
|
32 |
+
if ac:
|
33 |
+
price += 2000
|
34 |
+
if geyser:
|
35 |
+
price += 1000
|
36 |
+
if roof:
|
37 |
+
price += 2000
|
38 |
+
|
39 |
+
return price
|
40 |
+
|
41 |
+
# Define the inputs and outputs for the Gradio interface
|
42 |
+
input_area = gr.inputs.Slider(minimum=0, maximum=5000, step=100, default=1000, label="Area (in square feet)")
|
43 |
+
input_rooms = gr.inputs.Slider(minimum=0, maximum=10, step=1, default=3, label="Number of Rooms")
|
44 |
+
input_kitchens = gr.inputs.Slider(minimum=0, maximum=5, step=1, default=1, label="Number of Kitchens")
|
45 |
+
input_doors = gr.inputs.Slider(minimum=0, maximum=20, step=1, default=4, label="Number of Doors")
|
46 |
+
input_washrooms = gr.inputs.Slider(minimum=0, maximum=10, step=1, default=2, label="Number of Washrooms")
|
47 |
+
input_manzalas = gr.inputs.Slider(minimum=0, maximum=5, step=1, default=1, label="Number of Manzalas")
|
48 |
+
input_land_measurement = gr.inputs.Radio(["Marlas", "Canals"], label="Land Measurement")
|
49 |
+
|
50 |
+
input_garden = gr.inputs.Checkbox(label="Garden")
|
51 |
+
input_garage = gr.inputs.Checkbox(label="Garage")
|
52 |
+
input_storage_room = gr.inputs.Checkbox(label="Storage Room")
|
53 |
+
input_electricity = gr.inputs.Checkbox(label="Electricity")
|
54 |
+
input_gas = gr.inputs.Checkbox(label="Gas")
|
55 |
+
input_water = gr.inputs.Checkbox(label="Water")
|
56 |
+
input_ac = gr.inputs.Checkbox(label="Air Conditioning (AC)")
|
57 |
+
input_geyser = gr.inputs.Checkbox(label="Geyser")
|
58 |
+
input_roof = gr.inputs.Checkbox(label="Roof")
|
59 |
+
|
60 |
+
output_price = gr.outputs.Textbox(label="Estimated House Price")
|
61 |
+
|
62 |
+
# Load the pre-trained model and tokenizer from Hugging Face
|
63 |
+
model_name = "your_model_name" # Replace with the name or path of your pre-trained model
|
64 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
65 |
+
model = AutoModelForSequenceClassification.from_pretrained(model_name)
|
66 |
+
|
67 |
+
# Define the function to perform house price estimation using the loaded model
|
68 |
+
def estimate_house_price(area, rooms, kitchens, doors, washrooms, manzalas, land_measurement, garden=False, garage=False, storage_room=False, electricity=False, gas=False, water=False, ac=False, geyser=False, roof=False):
|
69 |
+
# Convert the input data to a formatted string
|
70 |
+
input_text = f"{area}, {rooms}, {kitchens}, {doors}, {washrooms}, {manzalas}, {land_measurement}, {garden}, {garage}, {storage_room}, {electricity}, {gas}, {water}, {ac}, {geyser}, {roof}"
|
71 |
+
|
72 |
+
# Tokenize the input text
|
73 |
+
inputs = tokenizer(input_text, padding=True, truncation=True, return_tensors="pt")
|
74 |
+
|
75 |
+
# Make predictions with the pre-trained model
|
76 |
+
outputs = model(**inputs)
|
77 |
+
predicted_price = outputs.logits.item()
|
78 |
+
|
79 |
+
return predicted_price
|
80 |
+
|
81 |
+
# Create the Gradio interface
|
82 |
+
interface = gr.Interface(
|
83 |
+
fn=estimate_house_price,
|
84 |
+
inputs=[
|
85 |
+
input_area, input_rooms, input_kitchens, input_doors, input_washrooms, input_manzalas,
|
86 |
+
input_land_measurement, input_garden, input_garage, input_storage_room,
|
87 |
+
input_electricity, input_gas, input_water, input_ac, input_geyser, input_roof
|
88 |
+
],
|
89 |
+
outputs=output_price,
|
90 |
+
examples=[
|
91 |
+
[1000, 3, 1, 4, 2, 1, "Marlas", True, False, True, True, False, True, False, False, True],
|
92 |
+
[1500, 4, 2, 6, 3, 1, "Canals", False, True, False, False, True, True, False, False, True],
|
93 |
+
[800, 2, 1, 2, 1, 1, "Marlas", True, False, False, True, True, True, False, True, False]
|
94 |
+
],
|
95 |
+
title="House Price Estimation",
|
96 |
+
description="Estimate the price of a house based on the provided requirements."
|
97 |
+
)
|
98 |
+
|
99 |
+
# Launch the Gradio interface
|
100 |
+
interface.launch()
|