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()