File size: 3,122 Bytes
77dc67f
 
9327810
77dc67f
 
 
 
 
 
 
 
9327810
a165958
45a7450
e63418f
 
b951dc3
75a7b9a
 
 
 
b951dc3
 
 
9327810
 
75a7b9a
 
 
b951dc3
77dc67f
 
 
 
 
b951dc3
77dc67f
9327810
 
77dc67f
 
9327810
 
 
77dc67f
 
9327810
77dc67f
 
9327810
77dc67f
 
 
01ca6ce
77dc67f
 
75a7b9a
 
77dc67f
75a7b9a
 
 
77dc67f
 
75a7b9a
77dc67f
75a7b9a
77dc67f
9327810
b951dc3
9327810
45a7450
 
 
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
# Gradio app function to update CheckboxGroup and filtered data
def app(selected_country, selected_industry):
    investor_list, filtered_data = filter_investors_by_country_and_industry(selected_country, selected_industry)
    logger.info("Updating CheckboxGroup and filtered data holder.")
    
    # Use gr.update() to create an update dictionary for the CheckboxGroup
    return gr.update(
        choices=investor_list,
        value=investor_list,
        visible=True
    ), filtered_data

# Gradio Interface
def main():
    country_list = ["All"] + sorted(data["Country"].dropna().unique())
    industry_list = ["All"] + sorted(data["Industry"].dropna().unique())
    
    # Ensure the default values for dropdowns exist
    default_country = "United States" if "United States" in country_list else "All"
    default_industry = "Enterprise Tech" if "Enterprise Tech" in industry_list else "All"
    
    logger.info(f"Available countries: {country_list}")
    logger.info(f"Available industries: {industry_list}")
    
    with gr.Blocks() as demo:
        with gr.Row():
            # Set default value for country and industry dropdowns
            country_filter = gr.Dropdown(choices=country_list, label="Filter by Country", value=default_country)
            industry_filter = gr.Dropdown(choices=industry_list, label="Filter by Industry", value=default_industry)
        
        filtered_investor_list = gr.CheckboxGroup(choices=[], label="Select Investors", visible=False)
        graph_output = gr.Plot(label="Venture Network Graph")
        valuation_display = gr.Markdown(value="Click on a company node to see its valuation.", label="Company Valuation")
        
        filtered_data_holder = gr.State()
        
        # Event handlers for filters
        country_filter.change(
            app,
            inputs=[country_filter, industry_filter],
            outputs=[filtered_investor_list, filtered_data_holder]
        )
        industry_filter.change(
            app,
            inputs=[country_filter, industry_filter],
            outputs=[filtered_investor_list, filtered_data_holder]
        )
        
        # Generate graph when investors are selected
        filtered_investor_list.change(
            generate_graph,
            inputs=[filtered_investor_list, filtered_data_holder],
            outputs=graph_output
        )
        
        # Handle plot click to display valuation
        def display_valuation(plotly_event):
            if not plotly_event or "points" not in plotly_event or not plotly_event["points"]:
                return "Click on a company node to see its valuation."
            point_data = plotly_event["points"][0]
            if "customdata" in point_data and point_data["customdata"]:
                return f"**Valuation:** {point_data['customdata']}"
            return "Click on a company node to see its valuation."
        
        graph_output.events().on_click(
            fn=display_valuation,
            inputs=[graph_output],
            outputs=valuation_display
        )
    
    demo.launch()

if __name__ == "__main__":
    main()