Spaces:
Sleeping
Sleeping
Commit ·
7ca9d2b
1
Parent(s): 6200c7b
Upload untitled2.py
Browse files- untitled2.py +46 -0
untitled2.py
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# -*- coding: utf-8 -*-
|
| 2 |
+
"""Untitled2.ipynb
|
| 3 |
+
|
| 4 |
+
Automatically generated by Colaboratory.
|
| 5 |
+
|
| 6 |
+
Original file is located at
|
| 7 |
+
https://colab.research.google.com/drive/1EU-VIsBUmCvPXWODe7G3MMx3nOyrhLE3
|
| 8 |
+
"""
|
| 9 |
+
|
| 10 |
+
!pip install pygal
|
| 11 |
+
|
| 12 |
+
!pip install gradio
|
| 13 |
+
|
| 14 |
+
import pandas as pd
|
| 15 |
+
import pygal
|
| 16 |
+
from sklearn.cluster import DBSCAN
|
| 17 |
+
import numpy as np
|
| 18 |
+
|
| 19 |
+
import gradio as gr
|
| 20 |
+
def Predict(inputName):
|
| 21 |
+
dataFrame = pd.read_json(r"MOCK_DATA (1).json")
|
| 22 |
+
safe_distance = 0.0020288 # a radial distance of 6 feet in kilometers
|
| 23 |
+
model = DBSCAN(eps=safe_distance, min_samples=2, metric='haversine').fit(dataFrame[['Latitude', 'Longitude']])
|
| 24 |
+
core_samples_mask = np.zeros_like(model.labels_, dtype=bool)
|
| 25 |
+
core_samples_mask[model.core_sample_indices_] = True
|
| 26 |
+
labels = model.labels_
|
| 27 |
+
dataFrame['Cluster'] = model.labels_.tolist()
|
| 28 |
+
inputNameClusters = set()
|
| 29 |
+
for i in range(len(dataFrame)):
|
| 30 |
+
if dataFrame['User'][i] == inputName:
|
| 31 |
+
inputNameClusters.add(dataFrame['Cluster'][i])
|
| 32 |
+
infected = set()
|
| 33 |
+
for cluster in inputNameClusters:
|
| 34 |
+
if cluster != -1:
|
| 35 |
+
namesInCluster = dataFrame.loc[dataFrame['Cluster'] == cluster, 'User']
|
| 36 |
+
for i in range(len(namesInCluster)):
|
| 37 |
+
name = namesInCluster.iloc[i]
|
| 38 |
+
if name != inputName:
|
| 39 |
+
infected.add(name)
|
| 40 |
+
return infected
|
| 41 |
+
|
| 42 |
+
gui = gr.Interface(fn=Predict,
|
| 43 |
+
inputs="text",
|
| 44 |
+
outputs="text")
|
| 45 |
+
gui.launch()
|
| 46 |
+
|