dcorcoran commited on
Commit
344a607
·
1 Parent(s): cce3ec8

Edited frontend layout

Browse files
app.py CHANGED
@@ -42,35 +42,19 @@ st.caption("Upload a Pokémon card image to extract its data and find similar ca
42
  # ----- UPLOAD -------------------
43
  # --------------------------------
44
 
45
- uploaded_file = st.file_uploader(
46
- "Upload a Pokémon card image",
47
- type=["png", "jpg", "jpeg"],
48
- key="card_uploader"
49
- )
50
-
51
- st.write("Uploaded file object:", uploaded_file)
52
-
53
- if uploaded_file is not None:
54
- st.write("File detected")
55
- st.write(uploaded_file.name)
56
 
 
57
  if uploaded_file:
 
58
  image_bytes = uploaded_file.read()
59
- st.caption("Reading card...")
60
-
61
  image = Image.open(io.BytesIO(image_bytes))
62
 
63
- st.caption("Successfully uploaded card")
64
-
65
  col1, col2 = st.columns([1, 2])
66
 
67
- st.caption("Made 3 columns")
68
-
69
  with col1:
70
- st.subheader("Uploaded Card")
71
- st.image(image, use_column_width=True)
72
-
73
- st.caption("Showing card")
74
 
75
  with col2:
76
  with st.spinner("Analyzing card..."):
 
42
  # ----- UPLOAD -------------------
43
  # --------------------------------
44
 
45
+ uploaded_file = render_upload_section()
 
 
 
 
 
 
 
 
 
 
46
 
47
+ # Check if file was uploaded
48
  if uploaded_file:
49
+ # Reading Pokemon Card
50
  image_bytes = uploaded_file.read()
 
 
51
  image = Image.open(io.BytesIO(image_bytes))
52
 
53
+ # Separate page into two columns
 
54
  col1, col2 = st.columns([1, 2])
55
 
 
 
56
  with col1:
57
+ st.image(image, width="content")
 
 
 
58
 
59
  with col2:
60
  with st.spinner("Analyzing card..."):
components/display_structured_data.py CHANGED
@@ -1,24 +1,35 @@
1
  import streamlit as st
2
 
3
  def render_card_data(result: dict):
 
4
  st.subheader("Extracted Card Data")
5
 
 
6
  col1, col2 = st.columns(2)
7
 
 
8
  with col1:
9
  st.metric("Name", result.get("name") or "Not detected")
10
  st.metric("HP", result.get("hp") or "Not detected")
11
 
 
12
  with col2:
13
  types = result.get("types")
14
  st.metric("Types", ", ".join(types) if types else "Not detected")
15
 
16
- # Moves
17
  moves = result.get("moves")
 
 
18
  if moves:
19
  st.markdown("**Moves**")
 
 
20
  for move in moves:
 
21
  with st.expander(f"{move.get('name')} — {move.get('damage', '?')} damage"):
22
  st.write(move.get("text") or "No description available.")
 
 
23
  else:
24
  st.metric("Moves", "Not detected")
 
1
  import streamlit as st
2
 
3
  def render_card_data(result: dict):
4
+ # Header for the uploaded card data
5
  st.subheader("Extracted Card Data")
6
 
7
+ # Create two columns
8
  col1, col2 = st.columns(2)
9
 
10
+ # Column one filled with name and HP
11
  with col1:
12
  st.metric("Name", result.get("name") or "Not detected")
13
  st.metric("HP", result.get("hp") or "Not detected")
14
 
15
+ # Column two filled with Pokemon types
16
  with col2:
17
  types = result.get("types")
18
  st.metric("Types", ", ".join(types) if types else "Not detected")
19
 
20
+ # Display moves below above columns
21
  moves = result.get("moves")
22
+
23
+ # Check if moves category exists
24
  if moves:
25
  st.markdown("**Moves**")
26
+
27
+ # Loop through all resulting moves
28
  for move in moves:
29
+ # Write the move name, dmaage done and text
30
  with st.expander(f"{move.get('name')} — {move.get('damage', '?')} damage"):
31
  st.write(move.get("text") or "No description available.")
32
+
33
+ # Placeholder if no moves detected
34
  else:
35
  st.metric("Moves", "Not detected")
components/similarity_grid.py CHANGED
@@ -4,26 +4,35 @@ from PIL import Image
4
  import io
5
 
6
  def render_similarity_grid(similar_cards: list):
 
7
  if not similar_cards:
8
  st.info("No similar cards found.")
9
  return
10
 
 
11
  cols = st.columns(len(similar_cards))
12
 
 
13
  for col, card in zip(cols, similar_cards):
14
  with col:
15
  # Load and display card image
16
  image_url = card.get("image_url")
 
 
17
  if image_url:
 
18
  try:
19
  response = requests.get(image_url, timeout=5)
20
  image = Image.open(io.BytesIO(response.content))
21
- st.image(image, use_column_width=True)
 
 
22
  except:
23
  st.write("Image unavailable")
24
 
25
- st.markdown(f"**{card.get('name')}**")
26
- st.caption(f"Set: {card.get('set') or 'Unknown'}")
27
- st.caption(f"Types: {', '.join(card.get('types') or [])}")
28
- st.caption(f"Rarity: {card.get('rarity') or 'Unknown'}")
29
- st.caption(f"Score: {round(card.get('score', 0), 3)}")
 
 
4
  import io
5
 
6
  def render_similarity_grid(similar_cards: list):
7
+ # Check if there are no similar cards returned
8
  if not similar_cards:
9
  st.info("No similar cards found.")
10
  return
11
 
12
+ # Create however many columns as there are cards
13
  cols = st.columns(len(similar_cards))
14
 
15
+ # Loop through list of similar cards
16
  for col, card in zip(cols, similar_cards):
17
  with col:
18
  # Load and display card image
19
  image_url = card.get("image_url")
20
+
21
+ # Check if the card image url exists
22
  if image_url:
23
+ # Attempt to get the image url and render the image
24
  try:
25
  response = requests.get(image_url, timeout=5)
26
  image = Image.open(io.BytesIO(response.content))
27
+ st.image(image, width="content")
28
+
29
+ # Write error message if image is unavailable
30
  except:
31
  st.write("Image unavailable")
32
 
33
+ # Display the card's name, ser, types, rarity, and similarity score
34
+ st.header(f"**{card.get('name')}**")
35
+ st.subheader(f"Set: {card.get('set') or 'Unknown'}")
36
+ st.subheader(f"Types: {', '.join(card.get('types') or [])}")
37
+ st.subheader(f"Rarity: {card.get('rarity') or 'Unknown'}")
38
+ st.subheader(f"Similarity Score: {round(card.get('score', 0), 3)}")