SurenRavi commited on
Commit
1e5c067
·
1 Parent(s): 605cae1

Frontend + Backend

Browse files
Files changed (3) hide show
  1. app.py +121 -0
  2. index.html +18 -0
  3. result.html +15 -0
app.py ADDED
@@ -0,0 +1,121 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # app.py
2
+
3
+ import pandas as pd
4
+ import numpy as np
5
+ import matplotlib.pyplot as plt
6
+ import seaborn as sns
7
+ import plotly.express as px
8
+ from PIL import Image
9
+ import json
10
+ import csv
11
+ from io import BytesIO
12
+ import requests
13
+ from sklearn.preprocessing import LabelEncoder
14
+ from sklearn.ensemble import RandomForestClassifier
15
+ from geopy.distance import geodesic
16
+ import osmnx as ox
17
+ from sklearn.linear_model import LogisticRegression
18
+ from sklearn.svm import SVC
19
+ from sklearn.tree import DecisionTreeClassifier
20
+ from flask import Flask, request, render_template
21
+
22
+ app = Flask(__name__)
23
+
24
+ # Read data
25
+ pd.set_option('display.max_columns', None)
26
+ df = pd.read_json("./Tourist_related.json")
27
+
28
+ # Convert data to CSV
29
+ with open('./data.csv', 'w') as data_file:
30
+ csv_writer = csv.writer(data_file)
31
+ csv_writer.writerow(df.columns)
32
+ csv_writer.writerows(df.values)
33
+
34
+ # Read CSV data
35
+ read_dat = pd.read_csv('./data.csv', on_bad_lines='skip')
36
+
37
+ # Function for data quality test
38
+ def data_quality_test():
39
+ check_na = read_dat.isnull().sum()
40
+ for features, count in check_na.items():
41
+ print(f'{features}: {count}')
42
+
43
+ # Function for correlation analysis
44
+ def correlation_analysis():
45
+ plt.figure(figsize=(12, 6))
46
+ sns.heatmap(df.corr(), annot=True)
47
+ plt.show()
48
+
49
+ # Geo Plot Visualization Function
50
+ def geo_plot_visualization():
51
+ df['lat'] = df['location'].apply(lambda x: x.get('lat', None))
52
+ df['lng'] = df['location'].apply(lambda x: x.get('lng', None))
53
+
54
+ color_scale = [(0, 'orange'), (1, 'red')]
55
+
56
+ fig = px.scatter_mapbox(df,
57
+ lat="lat",
58
+ lon="lng",
59
+ color_continuous_scale=color_scale,
60
+ zoom=8,
61
+ height=800,
62
+ width=800)
63
+
64
+ fig.update_layout(mapbox_style="open-street-map")
65
+ fig.update_layout(margin={"r": 0, "t": 0, "l": 0, "b": 0})
66
+
67
+ fig.show()
68
+
69
+ # Function for image category recognition
70
+ def predict_image_category(image_url):
71
+ # Replace this part with your image classification logic
72
+ # For example, you can use a pre-trained deep learning model
73
+ # Here, I'm using a placeholder
74
+ categories = ['Category A', 'Category B', 'Category C']
75
+ prediction = np.random.choice(categories)
76
+ return prediction
77
+
78
+ # Random Forest Classifier
79
+ def train_random_forest():
80
+ # Assuming 'target' is the target variable
81
+ X = df.drop('target', axis=1)
82
+ y = df['target']
83
+
84
+ # Assuming 'categorical_columns' is a list of categorical columns
85
+ le = LabelEncoder()
86
+ for col in categorical_columns:
87
+ X[col] = le.fit_transform(X[col])
88
+
89
+ # Create and train the random forest classifier
90
+ rf_classifier = RandomForestClassifier()
91
+ rf_classifier.fit(X, y)
92
+
93
+ return rf_classifier
94
+
95
+ # Home route
96
+ @app.route('/')
97
+ def home():
98
+ return render_template('index.html')
99
+
100
+ # Image upload route
101
+ @app.route('/upload', methods=['POST'])
102
+ def upload():
103
+ if request.method == 'POST':
104
+ file = request.files['file']
105
+ if file:
106
+ # Read the uploaded image
107
+ img = Image.open(file.stream)
108
+
109
+ # Display the image
110
+ plt.imshow(img)
111
+ plt.axis('off')
112
+ plt.show()
113
+
114
+ # Predict the image category
115
+ prediction = predict_image_category(file.stream)
116
+
117
+ return render_template('result.html', prediction=prediction)
118
+
119
+ # Start the Flask app
120
+ if __name__ == '__main__':
121
+ app.run(debug=True)
index.html ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!-- templates/index.html -->
2
+
3
+ <!DOCTYPE html>
4
+ <html lang="en">
5
+ <head>
6
+ <meta charset="UTF-8">
7
+ <meta http-equiv="X-UA-Compatible" content="IE=edge">
8
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
9
+ <title>Image Category Recognition</title>
10
+ </head>
11
+ <body>
12
+ <h1>Image Category Recognition</h1>
13
+ <form action="/upload" method="post" enctype="multipart/form-data">
14
+ <input type="file" name="file" accept="image/*">
15
+ <input type="submit" value="Upload">
16
+ </form>
17
+ </body>
18
+ </html>
result.html ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!-- templates/result.html -->
2
+
3
+ <!DOCTYPE html>
4
+ <html lang="en">
5
+ <head>
6
+ <meta charset="UTF-8">
7
+ <meta http-equiv="X-UA-Compatible" content="IE=edge">
8
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
9
+ <title>Image Category Recognition Result</title>
10
+ </head>
11
+ <body>
12
+ <h1>Image Category Recognition Result</h1>
13
+ <p>Prediction: {{ prediction }}</p>
14
+ </body>
15
+ </html>