Spaces:
Sleeping
Sleeping
Update src/app.py
Browse files- src/app.py +132 -42
src/app.py
CHANGED
|
@@ -1,65 +1,155 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
import random
|
|
|
|
|
|
|
| 3 |
|
| 4 |
-
#
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
)
|
| 10 |
|
| 11 |
-
# ---
|
| 12 |
-
st.image("src/procelevate_logo.png", width=150)
|
| 13 |
st.markdown(
|
| 14 |
-
"""
|
| 15 |
-
<
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
<
|
| 19 |
-
|
| 20 |
-
</h4>
|
| 21 |
""",
|
| 22 |
-
unsafe_allow_html=True
|
| 23 |
)
|
| 24 |
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
st.
|
| 29 |
-
|
| 30 |
|
| 31 |
-
#
|
| 32 |
facts = [
|
| 33 |
"AI predicts youโll be a Future Innovator ๐",
|
| 34 |
-
"
|
| 35 |
-
"You might be the Next Data Scientist ๐",
|
| 36 |
"AI says youโll shape the Future of Tech ๐ค",
|
| 37 |
-
"Leadership is in your DNA
|
| 38 |
-
"AI foresees
|
| 39 |
]
|
| 40 |
|
| 41 |
-
|
| 42 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
st.markdown(
|
| 44 |
f"""
|
| 45 |
-
<
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
""",
|
| 52 |
-
unsafe_allow_html=True
|
| 53 |
)
|
| 54 |
|
| 55 |
-
|
| 56 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
|
| 58 |
-
|
| 59 |
-
st.markdown("---")
|
| 60 |
st.markdown(
|
| 61 |
-
"<p style='text-align:center; font-size:14px;'>"
|
| 62 |
-
"ยฉ 2025 Procelevate Consulting | Elevating Processes. Empowering People."
|
| 63 |
-
"</p>",
|
| 64 |
unsafe_allow_html=True
|
| 65 |
)
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import random
|
| 3 |
+
from io import BytesIO
|
| 4 |
+
from PIL import Image, ImageDraw, ImageFont
|
| 5 |
|
| 6 |
+
# ---------- CONFIG ----------
|
| 7 |
+
BRAND = "#0F2C59" # Procelevate navy
|
| 8 |
+
ACCENT = "#00FFFF" # Cyan glow
|
| 9 |
+
PINK = "#FF00FF" # Magenta glow
|
| 10 |
+
|
| 11 |
+
st.set_page_config(page_title="AI Name Magic - Procelevate", page_icon="โจ", layout="centered")
|
| 12 |
|
| 13 |
+
# ---------- HEADER ----------
|
|
|
|
| 14 |
st.markdown(
|
| 15 |
+
f"""
|
| 16 |
+
<div style="text-align:center; margin-top:10px;">
|
| 17 |
+
<h1 style="margin:0; color:{BRAND};">AI Name Magic โจ</h1>
|
| 18 |
+
<div style="font-size:20px; color:#1f2937;">Powered by <b style="color:{BRAND};">Procelevate Consulting</b></div>
|
| 19 |
+
</div>
|
| 20 |
+
<hr style="opacity:.2;"/>
|
|
|
|
| 21 |
""",
|
| 22 |
+
unsafe_allow_html=True,
|
| 23 |
)
|
| 24 |
|
| 25 |
+
# ---------- INPUT ----------
|
| 26 |
+
with st.form("name_form", clear_on_submit=False):
|
| 27 |
+
st.subheader("๐ฎ Type Your Name & See AI Magic")
|
| 28 |
+
name = st.text_input("Enter your name:")
|
| 29 |
+
submitted = st.form_submit_button("Show My AI Prediction ๐")
|
| 30 |
|
| 31 |
+
# ---------- FUN FACTS ----------
|
| 32 |
facts = [
|
| 33 |
"AI predicts youโll be a Future Innovator ๐",
|
| 34 |
+
"You have the next big idea that transform the world ๐ก",
|
| 35 |
+
"You might be the Next Data Scientist / Data Engineer ๐",
|
| 36 |
"AI says youโll shape the Future of Tech ๐ค",
|
| 37 |
+
"Leadership and technology is in your DNA ๐",
|
| 38 |
+
"AI foresees the future CEO / CTO of a biggest company...! ๐",
|
| 39 |
]
|
| 40 |
|
| 41 |
+
def make_card(name_text: str, fact_text: str) -> bytes:
|
| 42 |
+
"""Create a branded PNG 'Future Me Card'."""
|
| 43 |
+
W, H = 1200, 630
|
| 44 |
+
img = Image.new("RGB", (W, H), (15,44,89)) # #0F2C59 background
|
| 45 |
+
draw = ImageDraw.Draw(img)
|
| 46 |
+
|
| 47 |
+
# subtle gradient overlay
|
| 48 |
+
grad = Image.new("RGB", (W, H))
|
| 49 |
+
for y in range(H):
|
| 50 |
+
c = int(255 * (y / H) * 0.18) # very light cyan tint
|
| 51 |
+
grad.putpixel((0, y), (0, 180, 180 - c))
|
| 52 |
+
grad = grad.resize((W, H))
|
| 53 |
+
img = Image.blend(img, grad, 0.15)
|
| 54 |
+
draw = ImageDraw.Draw(img)
|
| 55 |
+
|
| 56 |
+
# Load logo if available
|
| 57 |
+
try:
|
| 58 |
+
logo = Image.open("src/procelevate_logo.png").convert("RGBA")
|
| 59 |
+
base = 140
|
| 60 |
+
logo = logo.resize((base, base))
|
| 61 |
+
img.paste(logo, (50, 50), logo)
|
| 62 |
+
except Exception:
|
| 63 |
+
pass
|
| 64 |
+
|
| 65 |
+
# Fallback fonts (Pillow will map to system fonts in slim image)
|
| 66 |
+
try:
|
| 67 |
+
title_font = ImageFont.truetype("DejaVuSans-Bold.ttf", 70)
|
| 68 |
+
name_font = ImageFont.truetype("DejaVuSans-Bold.ttf", 120)
|
| 69 |
+
fact_font = ImageFont.truetype("DejaVuSans.ttf", 46)
|
| 70 |
+
except:
|
| 71 |
+
title_font = ImageFont.load_default()
|
| 72 |
+
name_font = ImageFont.load_default()
|
| 73 |
+
fact_font = ImageFont.load_default()
|
| 74 |
+
|
| 75 |
+
# Title
|
| 76 |
+
title = "YOUR AI PREDICTION"
|
| 77 |
+
tw, th = draw.textlength(title, font=title_font), title_font.size
|
| 78 |
+
draw.rounded_rectangle([(400, 70), (400+tw+60, 70+th+40)], radius=18, fill=(255,255,255))
|
| 79 |
+
draw.text((430, 90), title, font=title_font, fill=(15,44,89))
|
| 80 |
+
|
| 81 |
+
# Name (neon effect)
|
| 82 |
+
name_text = name_text.upper()
|
| 83 |
+
nx, ny = 120, 260
|
| 84 |
+
# Magenta / cyan shadow
|
| 85 |
+
draw.text((nx+6, ny+6), name_text, font=name_font, fill=(255,0,255))
|
| 86 |
+
draw.text((nx-6, ny-6), name_text, font=name_font, fill=(0,255,255))
|
| 87 |
+
draw.text((nx, ny), name_text, font=name_font, fill=(255,255,255))
|
| 88 |
+
|
| 89 |
+
# Fact
|
| 90 |
+
fact_box_y = ny + 170
|
| 91 |
+
draw.rounded_rectangle([(80, fact_box_y), (W-80, fact_box_y+170)], radius=24, fill=(255,255,255))
|
| 92 |
+
draw.text((110, fact_box_y+55), f"โจ {fact_text}", font=fact_font, fill=(15,44,89))
|
| 93 |
+
|
| 94 |
+
# Footer
|
| 95 |
+
footer = "ยฉ Procelevate Academy โข Learn -> Transform -> Elevate."
|
| 96 |
+
fw, _ = draw.textlength(footer, font=ImageFont.truetype("DejaVuSans.ttf", 28)), 28
|
| 97 |
+
draw.text(((W-fw)//2, H-60), footer, font=ImageFont.truetype("DejaVuSans.ttf", 28), fill=(230,240,245))
|
| 98 |
+
|
| 99 |
+
buf = BytesIO()
|
| 100 |
+
img.save(buf, format="PNG")
|
| 101 |
+
buf.seek(0)
|
| 102 |
+
return buf.getvalue()
|
| 103 |
+
|
| 104 |
+
# ---------- OUTPUT ----------
|
| 105 |
+
if submitted and name.strip():
|
| 106 |
+
fact = random.choice(facts)
|
| 107 |
+
|
| 108 |
+
# Confetti ๐
|
| 109 |
+
st.balloons()
|
| 110 |
+
|
| 111 |
+
# Neon Name Banner
|
| 112 |
st.markdown(
|
| 113 |
f"""
|
| 114 |
+
<div style="
|
| 115 |
+
margin: 10px auto 0 auto;
|
| 116 |
+
max-width: 820px;
|
| 117 |
+
text-align:center;
|
| 118 |
+
padding: 18px 22px;
|
| 119 |
+
border-radius: 16px;
|
| 120 |
+
background:
|
| 121 |
+
radial-gradient(circle at 20% 10%, rgba(0,255,255,.25), transparent 40%),
|
| 122 |
+
radial-gradient(circle at 80% 0%, rgba(255,0,255,.25), transparent 35%),
|
| 123 |
+
linear-gradient(180deg, #ffffff 0%, #f7fbff 100%);
|
| 124 |
+
border: 2px solid #e6eef7;">
|
| 125 |
+
<div style="font-size:14px; letter-spacing:1px; color:{BRAND}; font-weight:700;
|
| 126 |
+
display:inline-block; padding:6px 12px; border-radius:999px; background:#e6f3ff; margin-bottom:8px;">
|
| 127 |
+
YOUR AI PREDICTION
|
| 128 |
+
</div>
|
| 129 |
+
<h1 style="margin:4px 0 8px 0; font-size:56px; color:{BRAND};
|
| 130 |
+
text-shadow: 2px 2px {ACCENT}, -2px -2px {PINK};">
|
| 131 |
+
{name.upper()}
|
| 132 |
+
</h1>
|
| 133 |
+
<div style="font-size:22px; color:#0b2239; padding:12px 16px; border-radius:12px;
|
| 134 |
+
background:#f0f9ff; display:inline-block;">
|
| 135 |
+
โจ {fact}
|
| 136 |
+
</div>
|
| 137 |
+
</div>
|
| 138 |
""",
|
| 139 |
+
unsafe_allow_html=True,
|
| 140 |
)
|
| 141 |
|
| 142 |
+
# Build and show downloadable card
|
| 143 |
+
png_bytes = make_card(name, fact)
|
| 144 |
+
st.download_button("โฌ๏ธ Download My Future Me Card (PNG)", data=png_bytes,
|
| 145 |
+
file_name=f"{name.replace(' ','_')}_future_me.png", mime="image/png")
|
| 146 |
+
|
| 147 |
+
st.caption("Tip: Save the card or share it with your friends!")
|
| 148 |
+
elif submitted:
|
| 149 |
+
st.warning("Please enter your name first ๐")
|
| 150 |
|
| 151 |
+
st.markdown("<hr style='opacity:.2;'/>", unsafe_allow_html=True)
|
|
|
|
| 152 |
st.markdown(
|
| 153 |
+
"<p style='text-align:center; font-size:14px;'>ยฉ 2025 Procelevate Consulting</p>",
|
|
|
|
|
|
|
| 154 |
unsafe_allow_html=True
|
| 155 |
)
|