Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added initial gui files #4

Merged
merged 3 commits into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .streamlit/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[theme]
primaryColor="#ffffff"
backgroundColor="#181d27"
secondaryBackgroundColor = "#2c374d"
textColor = "#ffbf00"
108 changes: 108 additions & 0 deletions docs/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
import streamlit as st
from image_cipher import ImageCipher
import tempfile
import os


def save_uploaded_file_to_temp(uploaded_file):
temp_dir = tempfile.mkdtemp()
temp_file_path = os.path.join(temp_dir, uploaded_file.name)
with open(temp_file_path, "wb") as f:
f.write(uploaded_file.getbuffer())
return temp_file_path


def encrypt_image(image_path, message, encrypt):
cipher = ImageCipher()
encoded_image_path = cipher.encode(image_path, message, encrypt=encrypt)
return encoded_image_path, cipher.key


def decrypt_image(image_path, key):
cipher = ImageCipher()
decoded_message = cipher.decode(image_path, key)
return decoded_message


def main():
st.sidebar.image("docs/assets/image1.png", use_column_width=True)
with open("docs/css/styles.css") as f:
st.markdown(f"<style>{f.read()}</style>", unsafe_allow_html=True)
st.sidebar.markdown(
"""<a href='https://github.com/samadpls/ImageCipher'>\
<img src='https://img.shields.io/github/stars/samadpls/ImageCipher?\
color=red&label=star%20me&logoColor=red&style=social'></a>""",
unsafe_allow_html=True,
)
st.title("Image Cipher")
app_mode = st.sidebar.radio(
"Choose the app mode", ["Encrypt", "Decrypt", "About Us"]
)

if app_mode == "Encrypt":
st.header("Encrypt Image")
uploaded_image = st.file_uploader(
"Choose an image...", type=["png", "jpg", "jpeg"]
)
message = st.text_area("Enter your message")
use_encryption = st.checkbox("Use Encryption")

if st.button("Encrypt"):
if uploaded_image and message:
temp_image_path = save_uploaded_file_to_temp(uploaded_image)
encoded_image_path, key = encrypt_image(
temp_image_path, message, use_encryption
)
if use_encryption:
st.markdown("### Encryption Key:")
st.markdown(f"```\n{key.decode()}\n```")
with open(encoded_image_path, "rb") as file:
st.download_button(
"Download Encrypted Image",
file,
file_name="encrypted_image.png",
)
st.image(encoded_image_path, caption="Encrypted Image")
else:
st.error(
"Please upload an image and enter a message\
to encrypt."
)

elif app_mode == "Decrypt":
st.header("Decrypt Image")
uploaded_image = st.file_uploader(
"Choose an image...", type=["png", "jpg", "jpeg"]
)
key = st.text_input("Enter key (if any)")

if st.button("Decrypt"):
try:
if uploaded_image:
temp_path = save_uploaded_file_to_temp(uploaded_image)
decrypted_message = decrypt_image(temp_path, key)
st.text_area(
"Decrypted Message",
value=decrypted_message,
height=200
)

else:
st.error("Please upload an image to decrypt.")

except Exception as e:
st.error(e)

elif app_mode == "About Us":
st.header("About Us")
st.markdown(
"This project is developed by <ul> <li>[Abdul Samad]\
(https://github.com/samadpls/) </li>\
<li> [Maira Usman](https://github.com/Myrausman/)</li> \
</ul>",
unsafe_allow_html=True,
)


if __name__ == "__main__":
main()
Binary file added docs/assets/image1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
97 changes: 97 additions & 0 deletions docs/css/styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/* Main container */
body {
background-color: #181d27;
color: #ffbf00;
}

/* Sidebar */
.css-1d391kg {
background-color: #4f535a;
}

.css-1lcbmhc, .css-1d2azem {
color: #ffbf00;
}

.css-1v8qudd {
background-color: #2c374d;
color: #ffbf00;
}

/* Header */
.css-1siy2j7 {
color: #ffbf00;
}

/* Radio buttons and text input */
.css-1ex6qaa {
background-color: #2c374d;
color: #ffbf00;
}

.css-1ex6qaa input[type="radio"] {
background-color: #2c374d;
color: #ffbf00;
}

.css-1ex6qaa input[type="text"] {
background-color: #2c374d;
color: #ffbf00;
}

.css-1ex6qaa textarea {
background-color: #2c374d;
color: #ffbf00;
}

/* Buttons */
.css-1df45cr, .css-1f1iwnp, .css-1ktajzc {
background-color: #152544;
color: #ffbf00;
}

.css-1df45cr:hover, .css-1f1iwnp:hover, .css-1ktajzc:hover {
background-color: #152544;
color: #ffffff;
}

/* Download button */
.css-10trblm {
background-color: #152544;
color: #ffbf00;
}

.css-10trblm:hover {
background-color: #152544;
color: #ffffff;
}

/* Image */
.css-11v1u3b img {
border: 2px solid #ffbf00;
}

/* Text */
.css-qrbaxs p {
color: #ffbf00;
}

/* Error messages */
.css-19hj99j {
background-color: #2c374d;
color: #ffbf00;
}

/* Markdown */
.css-1uix8eu h1, .css-1uix8eu h2, .css-1uix8eu h3, .css-1uix8eu h4, .css-1uix8eu h5, .css-1uix8eu h6, .css-1uix8eu p {
color: #ffbf00;
}

/* Links */
a {
color: #ffbf00;
}

a:hover {
color: #ffffff;
}
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ Pillow
cryptography
pytest
flake8
streamlit
Loading