yuyutsu07 commited on
Commit
8912a3a
1 Parent(s): 6cdc438

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -64
app.py CHANGED
@@ -1,65 +1,35 @@
1
  import streamlit as st
2
- from streamlit.components.v1 import html
3
-
4
- def generate_numbered_text(text, start, end):
5
- return [f"{i} {text}" for i in range(start, end + 1)]
6
-
7
- st.title("Numbered Text Generator")
8
-
9
- user_text = st.text_area("Enter your text (any language, numbers, or symbols):")
10
- col1, col2 = st.columns(2)
11
-
12
- with col1:
13
- start_num = st.number_input("Starting number", min_value=1, max_value=100, value=1)
14
-
15
- with col2:
16
- end_num = st.number_input("Ending number", min_value=1, max_value=100, value=5)
17
-
18
- if 'results' not in st.session_state:
19
- st.session_state.results = []
20
-
21
- if st.button("Generate"):
22
- if user_text and start_num <= end_num:
23
- st.session_state.results = generate_numbered_text(user_text, start_num, end_num)
24
- else:
25
- st.error("Please enter text and ensure the starting number is less than or equal to the ending number.")
26
-
27
- # Display results in separate text boxes
28
- for i, result in enumerate(st.session_state.results):
29
- st.text_input("", value=result, key=f"result_{i}", disabled=True)
30
-
31
- # Add copy button using custom HTML and JavaScript
32
- if st.session_state.results:
33
- copy_button_html = f"""
34
- <button onclick="copyAllResults()">Copy All Results</button>
35
- <p id="copyStatus"></p>
36
-
37
- <script>
38
- function copyAllResults() {{
39
- var results = {st.session_state.results};
40
- var allResults = results.join('\\n');
41
- var tempTextArea = document.createElement('textarea');
42
- tempTextArea.value = allResults;
43
- document.body.appendChild(tempTextArea);
44
- tempTextArea.select();
45
-
46
- try {{
47
- var successful = document.execCommand('copy');
48
- if (successful) {{
49
- document.getElementById('copyStatus').textContent = 'All results copied to clipboard!';
50
- }} else {{
51
- throw new Error('Copying failed');
52
- }}
53
- }} catch (err) {{
54
- document.getElementById('copyStatus').textContent = 'Error in copying text: ' + err;
55
- }}
56
-
57
- document.body.removeChild(tempTextArea);
58
- }}
59
- </script>
60
- """
61
- html(copy_button_html, height=100)
62
-
63
- st.markdown("---")
64
- st.markdown('<span style="color: #FF9933;">जय श्री राम ❤️</span>', unsafe_allow_html=True)
65
- st.markdown("Created by Yuyutsu")
 
1
  import streamlit as st
2
+ import pyperclip
3
+ import time
4
+
5
+ def main():
6
+ st.title("Text Number Prefixer")
7
+
8
+ # User input for text
9
+ user_text = st.text_input("Enter your text:")
10
+
11
+ # User input for number
12
+ number = st.number_input("Select a number between 1 and 100:", min_value=1, max_value=100, value=1)
13
+
14
+ # Generate the output
15
+ output_text = [f"{i+1}{user_text}" for i in range(number)]
16
+
17
+ # Display the output with copy buttons
18
+ for line in output_text:
19
+ col1, col2 = st.columns([4, 1])
20
+ with col1:
21
+ st.write(line)
22
+ with col2:
23
+ if st.button(f"Copy {line}"):
24
+ pyperclip.copy(line)
25
+ st.success(f"{line} copied to clipboard!")
26
+
27
+ # Copy all text to clipboard sequentially
28
+ if st.button("Copy All"):
29
+ for line in output_text:
30
+ pyperclip.copy(line)
31
+ time.sleep(0.1) # Small delay to ensure each copy operation completes
32
+ st.success("All text copied to clipboard sequentially!")
33
+
34
+ if __name__ == "__main__":
35
+ main()