Spaces:
Runtime error
Runtime error
File size: 3,678 Bytes
acb1948 caff405 acb1948 caff405 b684cd1 acb1948 caff405 acb1948 caff405 d6d9f5d caff405 b684cd1 caff405 c4fc411 b684cd1 c4fc411 b684cd1 caff405 b684cd1 caff405 b684cd1 caff405 acb1948 caff405 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | import gradio as gr
import os
import plotly
import plotly.express as px
from tinder_plots import (
get_usage_df,
tinder_usage_overview,
tinder_colored_matches,
tinder_seasonality,
)
import pandas as pd
def fn(files):
if not isinstance(files, list):
files = [files]
dfs = []
for i, file in enumerate(files):
df = get_usage_df(file)
df["id"] = i
dfs.append(df)
if len(dfs) == 1:
df = dfs[0]
else:
df = pd.concat(dfs, join="inner")
figs = [
tinder_usage_overview(df),
tinder_seasonality(df),
tinder_colored_matches(df),
]
return figs
def create_with_interface():
inputs = [
gr.File(
value="./public_data.json",
file_count="multiple",
elem_id="upload-element",
label="tinder data.json file(s)",
)
]
outputs = [
gr.Plot(label="Usage overview"),
gr.Plot(label="Seasonality"),
gr.Plot(label="Colored matches"),
]
demo = gr.Interface(
fn,
inputs,
outputs,
# examples=[
# ["What a beautiful morning for a walk!"],
# ["It was the best of times, it was the worst of times."],
# ],
)
demo.launch()
def create_with_blocks():
with gr.Blocks(css="theme.css") as demo:
gr.Markdown(
"""
# Explore your Tinder data
Upload your myData.zip or data.json file and get interactive plots, just like with the provided example file.
Upload several files at once to compare different stats.
"""
)
with gr.Accordion(
"How to get your tinder data files?",
open=False,
):
gr.Markdown(
"""
To get your data, visit https://www.help.tinder.com/hc/en-us/articles/115005626726-How-do-I-request-a-copy-of-my-personal-data-
You shoud then receive a `myData.zip`. You can either upload directly the archive, or
you can extract the data.json file and remove all the sensitive informationsyou can to avoid uploading personal informations
(Which we would not look at on our side: you can check the source code!). See below on how to do anonymise your data.json.
Keep only numbers using this small python script, then upload public_data.json instead of data.json or myData.zip:
```python
import json
file = "./data.json"
with open(file) as f:
data = json.load(f)
new_data = {}
new_data["Usage"] = {k:v for k,v in data["Usage"].items() if k not in ["idfa", "advertising_id"]}
with open("./public_data.json", "w") as f:
json.dump(new_data, f)
```
"""
)
inputs = [
gr.File(
value="./public_data.json",
file_count="multiple",
elem_id="upload-element",
label="Upload your tinder file(s)! Click on the cross at the top-right corner to upload new file(s)!",
)
]
btn = gr.Button("Explore data!")
outputs = []
with gr.Row():
outputs += [gr.Plot(label="Usage overview"), gr.Plot(label="Seasonality")]
with gr.Row():
outputs += [gr.Plot(label="Colored matches")]
btn.click(fn=fn, inputs=inputs, outputs=outputs)
demo.launch()
if __name__ == "__main__":
# create_with_interface()
create_with_blocks()
|