omchaudhari2644 commited on
Commit
6278eca
·
verified ·
1 Parent(s): d2c4332

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +55 -39
src/streamlit_app.py CHANGED
@@ -1,40 +1,56 @@
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
+ # save this file as app.py
 
 
2
  import streamlit as st
3
+ import ast
4
+ import pyperclip as pyp
5
+
6
+ class encdec:
7
+ def __init__(self, name):
8
+ self.name = name
9
+ self.enc = name
10
+
11
+ def encode(self):
12
+ enc = []
13
+ new_name = list(self.name)
14
+ for ch in new_name:
15
+ enc.append(ord(ch) + 7)
16
+ self.enc = enc
17
+ return enc
18
+
19
+ def decode(self, enc):
20
+ dec = []
21
+ for ch1 in self.enc:
22
+ val = ch1
23
+ dec.append(chr(val - 7))
24
+ return ''.join(dec)
25
+
26
+ # Streamlit UI
27
+ st.title("Text Encoder / Decoder")
28
+
29
+ choice = st.radio("Select Action:", ("Encode", "Decode"))
30
+
31
+ if choice == "Encode":
32
+ user_input = st.text_input("Enter text to encode:")
33
+ if st.button("Encode"):
34
+ obj = encdec(user_input)
35
+ encoded = obj.encode()
36
+ st.success(f"Encoded: {encoded}")
37
+ pyp.copy(str(encoded)) # copy encoded list to clipboard
38
+ st.info("Encoded value copied to clipboard!")
39
+
40
+ elif choice == "Decode":
41
+ password = st.text_input("Enter password for decoding:", type="password")
42
+ if password:
43
+ if password == "notgood":
44
+ user_input = st.text_input("Enter text to decode (e.g., [118, 116]):")
45
+ if st.button("Decode"):
46
+ try:
47
+ user_input1 = ast.literal_eval(user_input)
48
+ obj = encdec(user_input1)
49
+ decoded = obj.decode(user_input1)
50
+ st.success(f"Decoded: {decoded}")
51
+ pyp.copy(decoded) # copy decoded text to clipboard
52
+ st.info("Decoded value copied to clipboard!")
53
+ except:
54
+ st.error("Invalid input! Enter a valid list like [118, 116].")
55
+ else:
56
+ st.error("Incorrect password! Access denied.")