aazankhanYousafzai's picture
Update app.py
bf53cb5 verified
import streamlit as st
import re
st.set_page_config(
page_title="Text Case Converter",
layout="centered",
)
# ---------- Cool Tech Theme ----------
st.markdown("""
<style>
body {
background: linear-gradient(135deg, #0f2027, #203a43, #2c5364);
}
.main { background: transparent; }
.card {
background: rgba(0, 0, 0, 0.55);
backdrop-filter: blur(10px);
border-radius: 22px;
padding: 28px;
box-shadow: 0 0 25px rgba(0,255,255,0.25);
max-width: 720px;
margin: auto;
}
h1, p, label, h3 {
color: #e5f9ff !important;
text-align: center;
}
textarea {
border-radius: 14px !important;
background: #020617 !important;
color: #e5f9ff !important;
border: 1px solid #0ea5e9 !important;
}
.stButton>button {
width: 100%;
height: 45px;
border-radius: 12px;
border: none;
background: linear-gradient(90deg, #0ea5e9, #22d3ee);
color: #020617;
font-weight: bold;
transition: 0.25s ease;
}
.stButton>button:hover {
transform: scale(1.06);
box-shadow: 0 0 15px #22d3ee;
}
.footer {
text-align: center;
color: #94a3b8;
margin-top: 15px;
font-size: 13px;
}
</style>
""", unsafe_allow_html=True)
# ---------- Helper Function ----------
def paragraph_style(text):
sentences = re.split(r'(?<=[.!?])\s*', text.strip())
fixed = []
for s in sentences:
s = s.strip()
if not s:
continue
if not s.endswith(('.', '!', '?')):
s += '.'
fixed.append(s.capitalize())
return " ".join(fixed)
# ---------- UI ----------
st.markdown("<div class='card'>", unsafe_allow_html=True)
st.markdown("<h1>Text Case Converter</h1>", unsafe_allow_html=True)
st.markdown("<p>Change your text instantly</p>", unsafe_allow_html=True)
text = st.text_area("", placeholder="Type or paste your text here...", height=180)
st.markdown("### Choose Conversion")
col1, col2, col3 = st.columns(3)
with col1:
if st.button("UPPERCASE"):
st.session_state["out"] = text.upper()
if st.button("lowercase"):
st.session_state["out"] = text.lower()
with col2:
if st.button("Title Case"):
st.session_state["out"] = text.title()
if st.button("Sentence Case"):
st.session_state["out"] = text.capitalize()
with col3:
if st.button("Toggle Case"):
st.session_state["out"] = text.swapcase()
if st.button("Paragraph Style"):
st.session_state["out"] = paragraph_style(text)
if "out" in st.session_state:
st.markdown("### Output")
st.text_area("", st.session_state["out"], height=150)
st.markdown("</div>", unsafe_allow_html=True)
st.markdown("<div class='footer'>Made with ❤️ using Streamlit</div>", unsafe_allow_html=True)