Spaces:
Sleeping
Sleeping
| # app.py | |
| import gradio as gr | |
| import pandas as pd | |
| import joblib | |
| # --- Step 1: Load the pre-calculated analysis data --- | |
| print("Loading network analysis data...") | |
| try: | |
| df_wallets = joblib.load('wallet_influence.joblib') | |
| df_domains = joblib.load('domain_centrality.joblib') | |
| # Format the scores for better readability | |
| df_wallets['Influence Score'] = (df_wallets['Influence Score'] * 10000).round(4) # Scale score to be more readable | |
| df_domains['Centrality Score'] = (df_domains['Centrality Score'] * 10000).round(4) | |
| print("β Network analysis data loaded successfully.") | |
| except FileNotFoundError: | |
| print("β ERROR: Data files not found. Make sure 'wallet_influence.joblib' and 'domain_centrality.joblib' are uploaded.") | |
| df_wallets = pd.DataFrame({'Error': ['wallet_influence.joblib not found.']}) | |
| df_domains = pd.DataFrame({'Error': ['domain_centrality.joblib not found.']}) | |
| # --- Step 2: Define the functions to display the data --- | |
| # These functions simply return the top N results from the loaded dataframes. | |
| def get_top_wallets(top_n=20): | |
| return df_wallets.head(int(top_n)) | |
| def get_top_domains(top_n=20): | |
| return df_domains.head(int(top_n)) | |
| # --- Step 3: Create and launch the Gradio Tabbed Interface --- | |
| with gr.Blocks() as demo: | |
| gr.Markdown("# Doma Wallet & Domain Influence Analyzer (Model 5)") | |
| gr.Markdown("This tool uses the PageRank algorithm on the Doma ownership graph to identify the most influential wallets and centrally important domains in the ecosystem.") | |
| with gr.Tabs(): | |
| with gr.TabItem("π Top Influential Wallets"): | |
| wallet_slider = gr.Slider(10, 100, value=20, step=10, label="Number of Wallets to Display") | |
| wallet_output = gr.DataFrame(headers=['Wallet', 'Influence Score'], datatype=['str', 'number']) | |
| wallet_slider.change(get_top_wallets, inputs=wallet_slider, outputs=wallet_output) | |
| # Load initial data | |
| demo.load(get_top_wallets, inputs=wallet_slider, outputs=wallet_output) | |
| with gr.TabItem("π Top Central Domains"): | |
| domain_slider = gr.Slider(10, 100, value=20, step=10, label="Number of Domains to Display") | |
| domain_output = gr.DataFrame(headers=['Domain', 'Centrality Score'], datatype=['str', 'number']) | |
| domain_slider.change(get_top_domains, inputs=domain_slider, outputs=domain_output) | |
| # Load initial data | |
| demo.load(get_top_domains, inputs=domain_slider, outputs=domain_output) | |
| # Launch the app | |
| if __name__ == "__main__": | |
| demo.launch() |