Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -0,0 +1,72 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import pandas as pd
|
3 |
+
import requests
|
4 |
+
|
5 |
+
# Helper functions to fetch data dynamically
|
6 |
+
def fetch_smartphones():
|
7 |
+
# Replace with a real API or dataset URL for smartphones
|
8 |
+
return pd.DataFrame([
|
9 |
+
{"Model": "iPhone 15", "Processor": "A17 Bionic", "RAM": "6 GB", "Battery": "3200 mAh"},
|
10 |
+
{"Model": "Samsung Galaxy S23", "Processor": "Snapdragon 8 Gen 2", "RAM": "8 GB", "Battery": "3900 mAh"}
|
11 |
+
])
|
12 |
+
|
13 |
+
def fetch_processors():
|
14 |
+
# Replace with a real API or dataset URL for processors
|
15 |
+
return pd.DataFrame([
|
16 |
+
{"Name": "Intel i9-13900K", "Cores": 24, "Threads": 32, "Base Clock": "3.0 GHz"},
|
17 |
+
{"Name": "AMD Ryzen 9 7950X", "Cores": 16, "Threads": 32, "Base Clock": "4.5 GHz"}
|
18 |
+
])
|
19 |
+
|
20 |
+
def fetch_gpus():
|
21 |
+
# Replace with a real API or dataset URL for GPUs
|
22 |
+
return pd.DataFrame([
|
23 |
+
{"Name": "NVIDIA RTX 4090", "VRAM": "24 GB", "Base Clock": "2.23 GHz"},
|
24 |
+
{"Name": "AMD RX 7900 XTX", "VRAM": "24 GB", "Base Clock": "2.3 GHz"}
|
25 |
+
])
|
26 |
+
|
27 |
+
def fetch_laptops():
|
28 |
+
# Replace with a real API or dataset URL for laptops
|
29 |
+
return pd.DataFrame([
|
30 |
+
{"Model": "MacBook Pro 16", "Processor": "M2 Max", "RAM": "32 GB", "Battery Life": "14 hours"},
|
31 |
+
{"Model": "Dell XPS 15", "Processor": "Intel i7-12700H", "RAM": "16 GB", "Battery Life": "10 hours"}
|
32 |
+
])
|
33 |
+
|
34 |
+
# Main App
|
35 |
+
def main():
|
36 |
+
st.title("Global Technology Comparisons")
|
37 |
+
st.sidebar.title("Choose a category")
|
38 |
+
|
39 |
+
# Define categories and their respective data-fetching functions
|
40 |
+
categories = {
|
41 |
+
"Smartphones": fetch_smartphones,
|
42 |
+
"Processors": fetch_processors,
|
43 |
+
"GPUs": fetch_gpus,
|
44 |
+
"Laptops": fetch_laptops
|
45 |
+
}
|
46 |
+
|
47 |
+
# User selects the category
|
48 |
+
category = st.sidebar.selectbox("Select a category:", list(categories.keys()))
|
49 |
+
|
50 |
+
# Fetch and display data dynamically
|
51 |
+
st.header(f"{category} Comparisons")
|
52 |
+
data = categories[category]()
|
53 |
+
st.table(data)
|
54 |
+
|
55 |
+
# Comparison tool
|
56 |
+
st.subheader(f"Compare {category}")
|
57 |
+
col1, col2 = st.columns(2)
|
58 |
+
|
59 |
+
# Dropdown for selecting items to compare
|
60 |
+
option1 = col1.selectbox("Select first item:", data.iloc[:, 0])
|
61 |
+
option2 = col2.selectbox("Select second item:", data.iloc[:, 0])
|
62 |
+
|
63 |
+
# Show comparison results
|
64 |
+
if option1 and option2:
|
65 |
+
st.write(f"### Comparison between {option1} and {option2}:")
|
66 |
+
item1 = data[data.iloc[:, 0] == option1].iloc[0]
|
67 |
+
item2 = data[data.iloc[:, 0] == option2].iloc[0]
|
68 |
+
comparison_df = pd.DataFrame({"Feature": data.columns, option1: item1.values, option2: item2.values})
|
69 |
+
st.table(comparison_df)
|
70 |
+
|
71 |
+
if __name__ == "__main__":
|
72 |
+
main()
|