Granitagushi commited on
Commit
beac17c
·
verified ·
1 Parent(s): c3cf212

Upload 2 files

Browse files
Files changed (2) hide show
  1. app (1).py +77 -0
  2. requirements.txt +5 -0
app (1).py ADDED
@@ -0,0 +1,77 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import numpy as np
3
+ import pandas as pd
4
+ import matplotlib.pyplot as plt
5
+
6
+ # Dummy-Funktion zur Vorhersage des Apartmentpreises
7
+ def predict_apartment(rooms, area, town):
8
+ # Basispreis und inkrementelle Berechnungen
9
+ base_price = 1000
10
+ price = base_price + rooms * 200 + area * 10
11
+ # Standortfaktor (Beispielwerte, können angepasst werden)
12
+ location_factor = {"Zürich": 1.5, "Kloten": 1.2, "Uster": 1.3, "Illnau-Effretikon": 1.1}
13
+ factor = location_factor.get(town, 1.0)
14
+ return price * factor
15
+
16
+ # Funktion zur Erstellung eines Plots, der den Einfluss eines Features zeigt
17
+ def visualize_influence(feature='area', fixed_rooms=3, fixed_town='Zürich'):
18
+ if feature == 'area':
19
+ x_values = np.linspace(30, 150, 50) # Beispielbereich für Wohnfläche in qm
20
+ elif feature == 'rooms':
21
+ x_values = np.arange(1, 6) # Beispielbereich für Zimmeranzahl
22
+ else:
23
+ return "Feature not supported"
24
+
25
+ predictions = []
26
+ for x in x_values:
27
+ if feature == 'area':
28
+ price = predict_apartment(fixed_rooms, x, fixed_town)
29
+ elif feature == 'rooms':
30
+ price = predict_apartment(x, 100, fixed_town) # Feste Wohnfläche von 100 qm
31
+ predictions.append(price)
32
+
33
+ # Erstelle den Plot
34
+ fig, ax = plt.subplots(figsize=(8, 4))
35
+ ax.plot(x_values, predictions, marker='o')
36
+ ax.set_xlabel('Wohnfläche (qm)' if feature == 'area' else 'Zimmeranzahl')
37
+ ax.set_ylabel('Vorhergesagter Preis')
38
+ ax.set_title(f'Einfluss von {"Wohnfläche" if feature=="area" else "Zimmeranzahl"} auf den Preis')
39
+ ax.grid(True)
40
+ fig.tight_layout()
41
+ return fig
42
+
43
+ # Wrapper-Funktion für Gradio, die die Visualisierung zurückgibt
44
+ def gradio_visualization(feature, fixed_rooms, fixed_town):
45
+ return visualize_influence(feature, fixed_rooms, fixed_town)
46
+
47
+ # Gradio-Interface für die Apartment-Preisvorhersage
48
+ preis_interface = gr.Interface(
49
+ fn=predict_apartment,
50
+ inputs=[
51
+ gr.Number(label="Zimmeranzahl", value=3),
52
+ gr.Number(label="Wohnfläche (qm)", value=100),
53
+ gr.Dropdown(choices=["Zürich", "Kloten", "Uster", "Illnau-Effretikon"], label="Ort", value="Zürich")
54
+ ],
55
+ outputs=gr.Number(label="Vorhergesagter Preis"),
56
+ title="Apartment Preisvorhersage",
57
+ description="Gib die Anzahl der Zimmer, die Wohnfläche und den Ort ein, um den Apartmentpreis vorherzusagen."
58
+ )
59
+
60
+ # Gradio-Interface für die Visualisierung der Einflussfaktoren
61
+ visual_interface = gr.Interface(
62
+ fn=gradio_visualization,
63
+ inputs=[
64
+ gr.Dropdown(choices=["area", "rooms"], label="Feature auswählen", value="area"),
65
+ gr.Number(label="Zimmeranzahl (fest)", value=3),
66
+ gr.Dropdown(choices=["Zürich", "Kloten", "Uster", "Illnau-Effretikon"], label="Ort (fest)", value="Zürich")
67
+ ],
68
+ outputs=gr.Plot(label="Einflussfaktoren-Visualisierung"),
69
+ title="Einflussfaktoren-Visualisierung",
70
+ description="Visualisiere, wie sich Wohnfläche oder Zimmeranzahl auf den vorhergesagten Preis auswirken."
71
+ )
72
+
73
+ # Beide Interfaces in einem TabbedInterface zusammenführen
74
+ tabs = gr.TabbedInterface([preis_interface, visual_interface], ["Preisvorhersage", "Visualisierung"])
75
+
76
+ if __name__ == "__main__":
77
+ tabs.launch()
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ gradio
2
+ numpy
3
+ pandas
4
+ matplotlib
5
+ scikit-learn