MBG0903 commited on
Commit
4cafddd
·
verified ·
1 Parent(s): c060a17

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +63 -38
src/streamlit_app.py CHANGED
@@ -1,40 +1,65 @@
1
- import altair as alt
2
- import numpy as np
3
- import pandas as pd
4
  import streamlit as st
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
 
6
- """
7
- # Welcome to Streamlit!
8
-
9
- Edit `/streamlit_app.py` to customize this app to your heart's desire :heart:.
10
- If you have any questions, checkout our [documentation](https://docs.streamlit.io) and [community
11
- forums](https://discuss.streamlit.io).
12
-
13
- In the meantime, below is an example of what you can do with just a few lines of code:
14
- """
15
-
16
- num_points = st.slider("Number of points in spiral", 1, 10000, 1100)
17
- num_turns = st.slider("Number of turns in spiral", 1, 300, 31)
18
-
19
- indices = np.linspace(0, 1, num_points)
20
- theta = 2 * np.pi * num_turns * indices
21
- radius = indices
22
-
23
- x = radius * np.cos(theta)
24
- y = radius * np.sin(theta)
25
-
26
- df = pd.DataFrame({
27
- "x": x,
28
- "y": y,
29
- "idx": indices,
30
- "rand": np.random.randn(num_points),
31
- })
32
-
33
- st.altair_chart(alt.Chart(df, height=700, width=700)
34
- .mark_point(filled=True)
35
- .encode(
36
- x=alt.X("x", axis=None),
37
- y=alt.Y("y", axis=None),
38
- color=alt.Color("idx", legend=None, scale=alt.Scale()),
39
- size=alt.Size("rand", legend=None, scale=alt.Scale(range=[1, 150])),
40
- ))
 
 
 
 
1
  import streamlit as st
2
+ from streamlit_drawable_canvas import st_canvas
3
+ import numpy as np
4
+ from tensorflow.keras.models import load_model
5
+ from tensorflow.keras.preprocessing.image import img_to_array
6
+ from PIL import Image
7
+
8
+ # Branding Colors
9
+ PRIMARY_COLOR = "#0F2C59" # Procelevate navy
10
+ ACCENT_COLOR = "#FFD700" # Gold highlight
11
+ BG_COLOR = "#F5F5F5" # Light background
12
+
13
+ # Load Model
14
+ model = load_model("quickdraw_model.h5")
15
+ CLASSES = ["cat", "dog", "house", "car", "tree", "airplane", "sun", "fish", "flower", "bird"]
16
+
17
+ # Page Config
18
+ st.set_page_config(page_title="Guess the Doodle - Procelevate", page_icon="✏️", layout="wide")
19
+
20
+ # Sidebar with logo
21
+ st.sidebar.image("procelevate_logo.png", use_column_width=True)
22
+ st.sidebar.markdown(
23
+ f"<h3 style='color:{PRIMARY_COLOR};'>🚀 Procelevate Academy</h3>"
24
+ "<p>Where AI meets fun & learning!</p>",
25
+ unsafe_allow_html=True
26
+ )
27
+
28
+ # Title Section
29
+ st.markdown(
30
+ f"""
31
+ <div style='text-align:center;'>
32
+ <h1 style='color:{PRIMARY_COLOR};'>🎨 Guess the Doodle – AI Game</h1>
33
+ <p style='font-size:18px;'>Draw something below, and let AI guess it in real-time!</p>
34
+ </div>
35
+ """,
36
+ unsafe_allow_html=True
37
+ )
38
+
39
+ # Drawing Canvas
40
+ canvas_result = st_canvas(
41
+ fill_color=BG_COLOR, stroke_width=10, stroke_color="black",
42
+ background_color="white", width=280, height=280,
43
+ drawing_mode="freedraw", key="canvas",
44
+ )
45
+
46
+ # Prediction
47
+ if canvas_result.image_data is not None:
48
+ img = Image.fromarray((canvas_result.image_data).astype("uint8")).convert("L")
49
+ img = img.resize((28,28))
50
+ img_array = img_to_array(img) / 255.0
51
+ img_array = np.expand_dims(img_array, axis=0)
52
+
53
+ preds = model.predict(img_array)[0]
54
+ top_indices = preds.argsort()[-3:][::-1]
55
+
56
+ st.markdown(f"<h2 style='color:{ACCENT_COLOR};'>🤖 AI’s Best Guesses:</h2>", unsafe_allow_html=True)
57
+
58
+ for idx in top_indices:
59
+ bar = f"<div style='background:{ACCENT_COLOR}; width:{int(preds[idx]*100)}%; height:20px;'></div>"
60
+ st.markdown(
61
+ f"<p><b>{CLASSES[idx]}</b> – {preds[idx]*100:.2f}%</p>{bar}<br>",
62
+ unsafe_allow_html=True
63
+ )
64
 
65
+ st.success("💡 Tip: Try drawing a cat 🐱, car 🚗, tree 🌳, or sun ☀️!")