hanwang commited on
Commit
c550680
·
1 Parent(s): 76bc9a7

add table and detail display

Browse files
Files changed (2) hide show
  1. main.py +29 -0
  2. met_api.py +6 -3
main.py CHANGED
@@ -1,6 +1,13 @@
1
  import streamlit as st
2
  import met_api
3
  import pandas as pd
 
 
 
 
 
 
 
4
  # Page setup
5
  st.set_page_config(page_title="The METrics", layout="centered")
6
 
@@ -37,6 +44,28 @@ st.markdown(
37
  # Columns with fixed-height images
38
  col1, col2, col3 = st.columns(3)
39
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
40
  with col1:
41
  st.markdown(
42
  "<div class='img-box'><img src='https://images.metmuseum.org/CRDImages/ep/web-large/DP-29324-001.jpg'></div>",
 
1
  import streamlit as st
2
  import met_api
3
  import pandas as pd
4
+
5
+ from met_api import search_for_images
6
+
7
+ @st.cache_data
8
+ def cached_search_for_images(query):
9
+ return search_for_images(query, 2,departments=[1,3,4,5,6,7])
10
+
11
  # Page setup
12
  st.set_page_config(page_title="The METrics", layout="centered")
13
 
 
44
  # Columns with fixed-height images
45
  col1, col2, col3 = st.columns(3)
46
 
47
+ q = st.text_input("Search term (for images only)", value="UFO", key="search_query")
48
+
49
+ r = cached_search_for_images(q)
50
+
51
+ summary = r[["primaryImageSmall","title","department","objectName"]]
52
+
53
+ config = {
54
+ "primaryImageSmall": st.column_config.ImageColumn(),
55
+ }
56
+
57
+ event = st.dataframe(summary, column_config=config, use_container_width=True, on_select="rerun", selection_mode="single-row")
58
+
59
+ if event.selection.rows:
60
+ selected_index = event.selection.rows[0] # Get the index of the first selected row
61
+ selected_row_data = r.iloc[selected_index]
62
+
63
+ st.subheader("Details of Selected Row:")
64
+ st.image(selected_row_data["primaryImage"], caption=selected_row_data["title"], width=500)
65
+ st.write(selected_row_data)
66
+ else:
67
+ st.info("Select a row in the table to see its details.")
68
+
69
  with col1:
70
  st.markdown(
71
  "<div class='img-box'><img src='https://images.metmuseum.org/CRDImages/ep/web-large/DP-29324-001.jpg'></div>",
met_api.py CHANGED
@@ -148,7 +148,7 @@ def search_for_images(query,
148
  "objectName": obj.get("objectName"),
149
  "classification": obj.get("classification"),
150
  "primaryImageSmall": obj.get("primaryImageSmall"),
151
- #"primaryImage": obj.get("primaryImage"),
152
  "objectURL": obj.get("objectURL"),
153
  "isPublicDomain": obj.get("isPublicDomain"),
154
  })
@@ -163,7 +163,7 @@ def search_for_images(query,
163
  Displays the departments to allow user to input a department
164
  Then searches the department based on input, and displays the results with images.
165
  """
166
- if __name__ == '__main__':
167
  print("Welcome to Met Search")
168
  departments = list_met_departments()
169
  print(departments.to_string(index=False))
@@ -178,4 +178,7 @@ if __name__ == '__main__':
178
  if results.empty:
179
  print("No results found.")
180
  continue
181
- print(results.to_string(index=False))
 
 
 
 
148
  "objectName": obj.get("objectName"),
149
  "classification": obj.get("classification"),
150
  "primaryImageSmall": obj.get("primaryImageSmall"),
151
+ "primaryImage": obj.get("primaryImage"),
152
  "objectURL": obj.get("objectURL"),
153
  "isPublicDomain": obj.get("isPublicDomain"),
154
  })
 
163
  Displays the departments to allow user to input a department
164
  Then searches the department based on input, and displays the results with images.
165
  """
166
+ def main():
167
  print("Welcome to Met Search")
168
  departments = list_met_departments()
169
  print(departments.to_string(index=False))
 
178
  if results.empty:
179
  print("No results found.")
180
  continue
181
+ print(results.to_string(index=False))
182
+
183
+ if __name__ == '__main__':
184
+ main()