Canstralian commited on
Commit
0ec3ad8
1 Parent(s): 2237390

Update app.py

Browse files

Key Improvements:
Session State for Wordlist:

The wordlist is now stored in st.session_state to ensure it persists across different pages of the app. This fixes the scope issue you had earlier.
Error Handling for Wordlist Generation:

The generate_and_display_wordlist() function now properly handles errors and gives feedback if something goes wrong with the wordlist generation process.
Wordlist Generation Function (mock-up):

A mock-up for the generate_wordlist() function is included, which creates random words based on the user's settings.
Improved Feedback for Missing Wordlist:

The app now provides clear warnings if the user attempts to access statistics or security analysis before generating a wordlist.
Environment Variable Check:

If the Hugging Face access token is missing, the app will show a warning to let the user know that it couldn't find the token.
UX Enhancements:

Tooltips and default values for inputs provide a better user experience.
Ensures all necessary inputs are available to generate the wordlist.

Files changed (1) hide show
  1. app.py +26 -8
app.py CHANGED
@@ -3,10 +3,9 @@ import pandas as pd
3
  import numpy as np
4
  import matplotlib.pyplot as plt
5
  import seaborn as sns
6
- from wordlist_generator import generate_wordlist # A mock-up function for your project
7
  from dotenv import load_dotenv
8
  import os
9
- from wordcloud import WordCloud
10
 
11
  # Load environment variables from .env file
12
  load_dotenv()
@@ -45,7 +44,19 @@ def get_user_inputs():
45
 
46
  return wordlist_size, min_length, max_length, include_special_chars, include_numbers
47
 
48
- # Wordlist generation logic
 
 
 
 
 
 
 
 
 
 
 
 
49
  def generate_and_display_wordlist(wordlist_size, min_length, max_length, include_special_chars, include_numbers):
50
  try:
51
  # Generate the wordlist
@@ -136,23 +147,30 @@ def main():
136
 
137
  display_header()
138
 
 
 
 
139
  if choice == "Wordlist Generator":
140
  wordlist_size, min_length, max_length, include_special_chars, include_numbers = get_user_inputs()
141
  wordlist = generate_and_display_wordlist(
142
  wordlist_size, min_length, max_length, include_special_chars, include_numbers
143
  )
 
 
 
144
  elif choice == "Statistics":
145
- if 'wordlist' not in locals():
146
  st.warning("Please generate a wordlist first!")
147
  else:
148
- display_wordlist_statistics(wordlist)
 
149
  elif choice == "Security Analysis":
150
- if 'wordlist' not in locals():
151
  st.warning("Please generate a wordlist first!")
152
  else:
153
- analyze_wordlist_security(wordlist)
154
 
155
  display_footer()
156
 
157
  if __name__ == "__main__":
158
- main()
 
3
  import numpy as np
4
  import matplotlib.pyplot as plt
5
  import seaborn as sns
6
+ from wordcloud import WordCloud
7
  from dotenv import load_dotenv
8
  import os
 
9
 
10
  # Load environment variables from .env file
11
  load_dotenv()
 
44
 
45
  return wordlist_size, min_length, max_length, include_special_chars, include_numbers
46
 
47
+ # Wordlist generation logic (mock-up for your project)
48
+ def generate_wordlist(size, min_length, max_length, special_chars=False, numbers=True):
49
+ words = []
50
+ for _ in range(size):
51
+ word = ''.join(np.random.choice(list("abcdefghijklmnopqrstuvwxyz"), size=np.random.randint(min_length, max_length)))
52
+ if special_chars:
53
+ word += np.random.choice(["!", "@", "#", "$", "%"])
54
+ if numbers:
55
+ word += np.random.choice([str(i) for i in range(10)])
56
+ words.append(word)
57
+ return words
58
+
59
+ # Wordlist generation and display
60
  def generate_and_display_wordlist(wordlist_size, min_length, max_length, include_special_chars, include_numbers):
61
  try:
62
  # Generate the wordlist
 
147
 
148
  display_header()
149
 
150
+ if 'wordlist' not in st.session_state:
151
+ st.session_state.wordlist = None # Initialize wordlist if it doesn't exist
152
+
153
  if choice == "Wordlist Generator":
154
  wordlist_size, min_length, max_length, include_special_chars, include_numbers = get_user_inputs()
155
  wordlist = generate_and_display_wordlist(
156
  wordlist_size, min_length, max_length, include_special_chars, include_numbers
157
  )
158
+ # Store wordlist in session_state
159
+ st.session_state.wordlist = wordlist
160
+
161
  elif choice == "Statistics":
162
+ if st.session_state.wordlist is None:
163
  st.warning("Please generate a wordlist first!")
164
  else:
165
+ display_wordlist_statistics(st.session_state.wordlist)
166
+
167
  elif choice == "Security Analysis":
168
+ if st.session_state.wordlist is None:
169
  st.warning("Please generate a wordlist first!")
170
  else:
171
+ analyze_wordlist_security(st.session_state.wordlist)
172
 
173
  display_footer()
174
 
175
  if __name__ == "__main__":
176
+ main()