import streamlit as st import pandas as pd import requests # Helper functions to fetch data dynamically def fetch_smartphones(): # Replace with a real API or dataset URL for smartphones return pd.DataFrame([ {"Model": "iPhone 15", "Processor": "A17 Bionic", "RAM": "6 GB", "Battery": "3200 mAh"}, {"Model": "Samsung Galaxy S23", "Processor": "Snapdragon 8 Gen 2", "RAM": "8 GB", "Battery": "3900 mAh"} ]) def fetch_processors(): # Replace with a real API or dataset URL for processors return pd.DataFrame([ {"Name": "Intel i9-13900K", "Cores": 24, "Threads": 32, "Base Clock": "3.0 GHz"}, {"Name": "AMD Ryzen 9 7950X", "Cores": 16, "Threads": 32, "Base Clock": "4.5 GHz"} ]) def fetch_gpus(): # Replace with a real API or dataset URL for GPUs return pd.DataFrame([ {"Name": "NVIDIA RTX 4090", "VRAM": "24 GB", "Base Clock": "2.23 GHz"}, {"Name": "AMD RX 7900 XTX", "VRAM": "24 GB", "Base Clock": "2.3 GHz"} ]) def fetch_laptops(): # Replace with a real API or dataset URL for laptops return pd.DataFrame([ {"Model": "MacBook Pro 16", "Processor": "M2 Max", "RAM": "32 GB", "Battery Life": "14 hours"}, {"Model": "Dell XPS 15", "Processor": "Intel i7-12700H", "RAM": "16 GB", "Battery Life": "10 hours"} ]) # Main App def main(): st.title("Global Technology Comparisons") st.sidebar.title("Choose a category") # Define categories and their respective data-fetching functions categories = { "Smartphones": fetch_smartphones, "Processors": fetch_processors, "GPUs": fetch_gpus, "Laptops": fetch_laptops } # User selects the category category = st.sidebar.selectbox("Select a category:", list(categories.keys())) # Fetch and display data dynamically st.header(f"{category} Comparisons") data = categories[category]() st.table(data) # Comparison tool st.subheader(f"Compare {category}") col1, col2 = st.columns(2) # Dropdown for selecting items to compare option1 = col1.selectbox("Select first item:", data.iloc[:, 0]) option2 = col2.selectbox("Select second item:", data.iloc[:, 0]) # Show comparison results if option1 and option2: st.write(f"### Comparison between {option1} and {option2}:") item1 = data[data.iloc[:, 0] == option1].iloc[0] item2 = data[data.iloc[:, 0] == option2].iloc[0] comparison_df = pd.DataFrame({"Feature": data.columns, option1: item1.values, option2: item2.values}) st.table(comparison_df) if __name__ == "__main__": main()