Spaces:
Sleeping
Sleeping
init: Frontend: Streamlit + Backend + ML
Browse files- .ipynb_checkpoints/CIDM - Mini Project-checkpoint.ipynb +0 -0
- CIDM - Mini Project.ipynb +0 -0
- Tourist_related.json +0 -0
- app.py +131 -0
- data.csv +0 -0
- model_card.md +23 -0
- requirements.txt +15 -0
- result.html +15 -0
- vertezml-0.0.20-cp311-cp311-win_amd64.whl +0 -0
.ipynb_checkpoints/CIDM - Mini Project-checkpoint.ipynb
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
CIDM - Mini Project.ipynb
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
Tourist_related.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
app.py
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
import streamlit as st
|
| 12 |
+
from sklearn.preprocessing import LabelEncoder
|
| 13 |
+
from sklearn.ensemble import RandomForestClassifier
|
| 14 |
+
from geopy.distance import geodesic
|
| 15 |
+
import osmnx as ox
|
| 16 |
+
from sklearn.linear_model import LogisticRegression
|
| 17 |
+
from sklearn.svm import SVC
|
| 18 |
+
from sklearn.tree import DecisionTreeClassifier
|
| 19 |
+
|
| 20 |
+
# Read data
|
| 21 |
+
pd.set_option('display.max_columns', None)
|
| 22 |
+
df = pd.read_json("./Tourist_related.json")
|
| 23 |
+
|
| 24 |
+
# Convert data to CSV
|
| 25 |
+
with open('./data.csv', 'w') as data_file:
|
| 26 |
+
csv_writer = csv.writer(data_file)
|
| 27 |
+
csv_writer.writerow(df.columns)
|
| 28 |
+
csv_writer.writerows(df.values)
|
| 29 |
+
|
| 30 |
+
# Read CSV data
|
| 31 |
+
read_dat = pd.read_csv('./data.csv', on_bad_lines='skip')
|
| 32 |
+
|
| 33 |
+
# Function for data quality test
|
| 34 |
+
def data_quality_test():
|
| 35 |
+
check_na = read_dat.isnull().sum()
|
| 36 |
+
for features, count in check_na.items():
|
| 37 |
+
print(f'{features}: {count}')
|
| 38 |
+
|
| 39 |
+
# Function for correlation analysis
|
| 40 |
+
def correlation_analysis():
|
| 41 |
+
plt.figure(figsize=(12, 6))
|
| 42 |
+
sns.heatmap(df.corr(), annot=True)
|
| 43 |
+
st.pyplot()
|
| 44 |
+
|
| 45 |
+
# Geo Plot Visualization Function
|
| 46 |
+
def geo_plot_visualization():
|
| 47 |
+
df['lat'] = df['location'].apply(lambda x: x.get('lat', None))
|
| 48 |
+
df['lng'] = df['location'].apply(lambda x: x.get('lng', None))
|
| 49 |
+
|
| 50 |
+
color_scale = [(0, 'orange'), (1, 'red')]
|
| 51 |
+
|
| 52 |
+
fig = px.scatter_mapbox(df,
|
| 53 |
+
lat="lat",
|
| 54 |
+
lon="lng",
|
| 55 |
+
color_continuous_scale=color_scale,
|
| 56 |
+
zoom=8,
|
| 57 |
+
height=800,
|
| 58 |
+
width=800)
|
| 59 |
+
|
| 60 |
+
fig.update_layout(mapbox_style="open-street-map")
|
| 61 |
+
fig.update_layout(margin={"r": 0, "t": 0, "l": 0, "b": 0})
|
| 62 |
+
|
| 63 |
+
st.plotly_chart(fig)
|
| 64 |
+
|
| 65 |
+
# Function for image category recognition
|
| 66 |
+
def predict_image_category(image_url):
|
| 67 |
+
# Replace this part with your image classification logic
|
| 68 |
+
# For example, you can use a pre-trained deep learning model
|
| 69 |
+
# Here, I'm using a placeholder
|
| 70 |
+
categories = ['Category A', 'Category B', 'Category C']
|
| 71 |
+
prediction = np.random.choice(categories)
|
| 72 |
+
return prediction
|
| 73 |
+
|
| 74 |
+
# Random Forest Classifier
|
| 75 |
+
def train_random_forest():
|
| 76 |
+
# Assuming 'target' is the target variable
|
| 77 |
+
X = df.drop('target', axis=1)
|
| 78 |
+
y = df['target']
|
| 79 |
+
|
| 80 |
+
# Assuming 'categorical_columns' is a list of categorical columns
|
| 81 |
+
le = LabelEncoder()
|
| 82 |
+
for col in categorical_columns:
|
| 83 |
+
X[col] = le.fit_transform(X[col])
|
| 84 |
+
|
| 85 |
+
# Create and train the random forest classifier
|
| 86 |
+
rf_classifier = RandomForestClassifier()
|
| 87 |
+
rf_classifier.fit(X, y)
|
| 88 |
+
|
| 89 |
+
return rf_classifier
|
| 90 |
+
|
| 91 |
+
# Streamlit UI
|
| 92 |
+
def main():
|
| 93 |
+
st.title("Tourist Analysis App")
|
| 94 |
+
|
| 95 |
+
# Sidebar
|
| 96 |
+
st.sidebar.subheader("Navigation")
|
| 97 |
+
page = st.sidebar.radio("Go to", ("Home", "Data Quality Test", "Correlation Analysis", "Geo Plot Visualization", "Image Upload"))
|
| 98 |
+
|
| 99 |
+
if page == "Home":
|
| 100 |
+
st.write("# Welcome to Tourist Analysis App")
|
| 101 |
+
st.write("Use the sidebar to navigate to different sections.")
|
| 102 |
+
|
| 103 |
+
elif page == "Data Quality Test":
|
| 104 |
+
st.write("# Data Quality Test")
|
| 105 |
+
data_quality_test()
|
| 106 |
+
|
| 107 |
+
elif page == "Correlation Analysis":
|
| 108 |
+
st.write("# Correlation Analysis")
|
| 109 |
+
correlation_analysis()
|
| 110 |
+
|
| 111 |
+
elif page == "Geo Plot Visualization":
|
| 112 |
+
st.write("# Geo Plot Visualization")
|
| 113 |
+
geo_plot_visualization()
|
| 114 |
+
|
| 115 |
+
elif page == "Image Upload":
|
| 116 |
+
st.write("# Image Upload")
|
| 117 |
+
uploaded_file = st.file_uploader("Choose an image...", type="jpg")
|
| 118 |
+
|
| 119 |
+
if uploaded_file is not None:
|
| 120 |
+
image = Image.open(uploaded_file)
|
| 121 |
+
st.image(image, caption="Uploaded Image.", use_column_width=True)
|
| 122 |
+
st.write("")
|
| 123 |
+
st.write("Classifying...")
|
| 124 |
+
|
| 125 |
+
# Predict the image category
|
| 126 |
+
prediction = predict_image_category(image)
|
| 127 |
+
|
| 128 |
+
st.write("Prediction:", prediction)
|
| 129 |
+
|
| 130 |
+
if __name__ == "__main__":
|
| 131 |
+
main()
|
data.csv
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
model_card.md
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
tags:
|
| 3 |
+
- machine-learning
|
| 4 |
+
- data-visualization
|
| 5 |
+
- geospatial
|
| 6 |
+
---
|
| 7 |
+
|
| 8 |
+
# CIDM TEAM A Location Recommender
|
| 9 |
+
|
| 10 |
+
This script uses machine learning to recommend locations based on swiped images and visualizes them on a map.
|
| 11 |
+
|
| 12 |
+
## Usage
|
| 13 |
+
|
| 14 |
+
1. Open the Jupyter Notebook in the [Hugging Face Spaces](https://huggingface.co/spaces) environment.
|
| 15 |
+
2. Execute the cells one by one.
|
| 16 |
+
3. View the generated map to see recommended locations and the closest one.
|
| 17 |
+
|
| 18 |
+
## Dependencies
|
| 19 |
+
|
| 20 |
+
- pandas
|
| 21 |
+
- scikit-learn
|
| 22 |
+
- plotly
|
| 23 |
+
- geopy
|
requirements.txt
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
pandas
|
| 2 |
+
scikit-learn
|
| 3 |
+
plotly
|
| 4 |
+
geopy
|
| 5 |
+
PIL
|
| 6 |
+
json
|
| 7 |
+
csv
|
| 8 |
+
io
|
| 9 |
+
requests
|
| 10 |
+
flask
|
| 11 |
+
osmnx
|
| 12 |
+
numpy
|
| 13 |
+
seaborn
|
| 14 |
+
matplotlib
|
| 15 |
+
streamlit
|
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>
|
vertezml-0.0.20-cp311-cp311-win_amd64.whl
ADDED
|
Binary file (96.8 kB). View file
|
|
|