DILSHAD737 commited on
Commit
ef89224
Β·
1 Parent(s): dbec292

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -22
app.py CHANGED
@@ -14,9 +14,18 @@ from itertools import permutations, combinations
14
  from mnemonic import Mnemonic
15
  import coincurve
16
  from eth_utils import keccak, to_checksum_address
17
- import spaces
18
 
19
- @spaces.GPU
 
 
 
 
 
 
 
 
 
 
20
  def _noop():
21
  return "ok"
22
 
@@ -129,20 +138,24 @@ def generate_phrases_for_words(wordlist, mode):
129
  yield " ".join(combo)
130
 
131
  # ============================================================
132
- # Scan Function
133
  # ============================================================
134
 
 
135
  def run_scan(my_phrase, num_phrases, addresses_file, phrase_mode,
136
  start_index, end_index, passphrase, progress=gr.Progress()):
137
 
 
 
 
 
 
 
 
138
  if not os.path.exists(addresses_file):
139
  return f"❌ File nahi mili: {addresses_file}", ""
140
 
141
- num_phrases = int(num_phrases)
142
- start_index = int(start_index)
143
- end_index = int(end_index)
144
-
145
- progress(0, desc="Loading addresses...")
146
  try:
147
  known = load_addresses_cached(addresses_file)
148
  except Exception as e:
@@ -209,25 +222,29 @@ def run_scan(my_phrase, num_phrases, addresses_file, phrase_mode,
209
  return log_text, matches_text
210
 
211
  # ============================================================
212
- # Bulletproof UI
213
  # ============================================================
214
- with gr.Blocks() as demo:
215
  gr.Markdown("# πŸ” Phrase Scanner")
216
 
217
- my_phrase = gr.Textbox(
218
- label="πŸ”‘ Apni Phrase (optional)",
219
- value="lesson cushion crane affair federal decline limb spend reunion chief cart zebra",
220
- lines=2,
221
- )
 
222
 
223
- num_phrases = gr.Number(label="Kitni Random Phrases Check Karein?", value=10, precision=0, minimum=0)
224
- addresses_file = gr.Textbox(label="Addresses File", value="12730802_addresses.csv")
 
225
 
226
- phrase_mode = gr.Radio(choices=["replace", "order", "subset"], value="replace", label="Phrase Mode")
227
- start_index = gr.Number(label="Start Index", value=0, precision=0, minimum=0)
228
- end_index = gr.Number(label="End Index", value=20, precision=0, minimum=0)
 
229
 
230
- passphrase = gr.Textbox(label="BIP39 Passphrase (khali chhod dein)", value="", type="password")
 
231
 
232
  run_btn = gr.Button("πŸš€ Scan Shuru Karein", variant="primary")
233
 
@@ -242,6 +259,7 @@ with gr.Blocks() as demo:
242
  inputs=[my_phrase, num_phrases, addresses_file, phrase_mode,
243
  start_index, end_index, passphrase],
244
  outputs=[log_output, matches_output],
 
245
  )
246
 
247
  # ZeroGPU requirement
@@ -249,7 +267,7 @@ _noop()
249
 
250
  _original_launch = demo.launch
251
  def _patched_launch(**kwargs):
252
- kwargs.setdefault("ssr_mode", False)
253
  kwargs.setdefault("share", True)
254
  kwargs.setdefault("server_name", "0.0.0.0")
255
  kwargs.setdefault("server_port", 7860)
 
14
  from mnemonic import Mnemonic
15
  import coincurve
16
  from eth_utils import keccak, to_checksum_address
 
17
 
18
+ # ============================================================
19
+ # Spaces GPU Fallback (Prevents crashes if run locally)
20
+ # ============================================================
21
+ try:
22
+ import spaces
23
+ gpu_decorator = spaces.GPU
24
+ except ImportError:
25
+ def gpu_decorator(func):
26
+ return func
27
+
28
+ @gpu_decorator
29
  def _noop():
30
  return "ok"
31
 
 
138
  yield " ".join(combo)
139
 
140
  # ============================================================
141
+ # Scan Function WITH Progress Bar
142
  # ============================================================
143
 
144
+ @gpu_decorator
145
  def run_scan(my_phrase, num_phrases, addresses_file, phrase_mode,
146
  start_index, end_index, passphrase, progress=gr.Progress()):
147
 
148
+ # Safe type casting to prevent crashes if UI inputs are cleared
149
+ num_phrases = int(num_phrases or 0)
150
+ start_index = int(start_index or 0)
151
+ end_index = int(end_index or 0)
152
+ my_phrase = my_phrase or ""
153
+ passphrase = passphrase or ""
154
+
155
  if not os.path.exists(addresses_file):
156
  return f"❌ File nahi mili: {addresses_file}", ""
157
 
158
+ progress(0, desc="Addresses load ho rahe hain...")
 
 
 
 
159
  try:
160
  known = load_addresses_cached(addresses_file)
161
  except Exception as e:
 
222
  return log_text, matches_text
223
 
224
  # ============================================================
225
+ # Simple, Flat UI (No Layout Bugs)
226
  # ============================================================
227
+ with gr.Blocks(title="Phrase Scanner") as demo:
228
  gr.Markdown("# πŸ” Phrase Scanner")
229
 
230
+ with gr.Row():
231
+ my_phrase = gr.Textbox(
232
+ label="πŸ”‘ Apni Phrase (optional)",
233
+ value="lesson cushion crane affair federal decline limb spend reunion chief cart zebra",
234
+ lines=2,
235
+ )
236
 
237
+ with gr.Row():
238
+ num_phrases = gr.Number(label="Kitni Random Phrases Check Karein?", value=10, precision=0, minimum=0)
239
+ addresses_file = gr.Textbox(label="Addresses File", value="12730802_addresses.csv")
240
 
241
+ with gr.Row():
242
+ phrase_mode = gr.Radio(choices=["replace", "order", "subset"], value="replace", label="Phrase Mode")
243
+ start_index = gr.Number(label="Start Index", value=0, precision=0, minimum=0)
244
+ end_index = gr.Number(label="End Index", value=20, precision=0, minimum=0)
245
 
246
+ with gr.Row():
247
+ passphrase = gr.Textbox(label="BIP39 Passphrase (khali chhod dein)", value="", type="password")
248
 
249
  run_btn = gr.Button("πŸš€ Scan Shuru Karein", variant="primary")
250
 
 
259
  inputs=[my_phrase, num_phrases, addresses_file, phrase_mode,
260
  start_index, end_index, passphrase],
261
  outputs=[log_output, matches_output],
262
+ show_progress="full"
263
  )
264
 
265
  # ZeroGPU requirement
 
267
 
268
  _original_launch = demo.launch
269
  def _patched_launch(**kwargs):
270
+ # Removed invalid 'ssr_mode' parameter which crashes Gradio 4+
271
  kwargs.setdefault("share", True)
272
  kwargs.setdefault("server_name", "0.0.0.0")
273
  kwargs.setdefault("server_port", 7860)