DILSHAD737 commited on
Commit
e12a5db
Β·
1 Parent(s): 45d8cd1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +49 -79
app.py CHANGED
@@ -129,11 +129,11 @@ def generate_phrases_for_words(wordlist, mode):
129
  yield " ".join(combo)
130
 
131
  # ============================================================
132
- # Gradio Scan Function (Returns final result, no yield)
133
  # ============================================================
134
 
135
- def run_scan_sync(my_phrase, num_phrases, addresses_file, phrase_mode,
136
- start_index, end_index, passphrase):
137
 
138
  if not os.path.exists(addresses_file):
139
  return f"❌ File nahi mili: {addresses_file}", ""
@@ -160,33 +160,30 @@ def run_scan_sync(my_phrase, num_phrases, addresses_file, phrase_mode,
160
  for _ in range(num_phrases):
161
  phrases.append(mnemo.generate(strength=128))
162
 
163
- log_lines = [
164
- f"βœ… Loaded {len(known):,} addresses (cached)",
165
- f"πŸ”§ Mode: {phrase_mode}",
166
- f"πŸ”‘ Index range: {start_index}–{end_index}",
167
- f"πŸ“ Total phrases: {len(phrases)}",
168
- "",
169
- "**Phrases:**",
170
- ]
171
- for i, p in enumerate(phrases, 1):
172
- tag = " **(AAPKI)**" if i == 1 and len(my_words) == 12 else ""
173
- log_lines.append(f"{i}. `{p}`{tag}")
174
 
175
- log_lines.append("---")
 
 
 
 
176
 
177
  matches = []
178
  start = time.time()
179
  total_phrases = len(phrases)
180
 
181
  for p_idx, phrase in enumerate(phrases, 1):
182
- log_lines.append(f"**πŸ” [{p_idx}/{total_phrases}] Checking:** `{phrase}`")
183
  words = phrase.strip().split()
184
 
185
  if len(words) != 12:
186
- log_lines.append(" ⚠️ Skipped (not 12 words)")
187
  continue
188
 
189
  for idx in range(start_index, end_index + 1):
 
190
  for phrase_str in generate_phrases_for_words(words, phrase_mode):
191
  if not is_valid_bip39(phrase_str):
192
  continue
@@ -199,79 +196,52 @@ def run_scan_sync(my_phrase, num_phrases, addresses_file, phrase_mode,
199
  continue
200
 
201
  if normalize(addr) in known:
202
- match_line = (
203
- f"### πŸŽ‰ MATCH!\n"
204
- f"**Phrase:** `{phrase_str}`\n"
205
- f"**Index:** {idx}\n"
206
- f"**Key:** `{priv.hex()}`\n"
207
- f"**Addr:** `{addr}`\n"
208
- )
209
- log_lines.append(match_line)
210
- matches.append((phrase_str, idx, priv.hex(), addr))
211
 
212
  elapsed = time.time() - start
213
- log_lines.append("---")
214
- log_lines.append(f"**=== DONE ===**")
215
- log_lines.append(f"**Total time:** {elapsed:.1f}s")
216
- log_lines.append(f"**Total matches:** {len(matches)}")
217
 
218
- matches_text = "\n\n".join(
219
- f"**Phrase:** `{p}`\n**Index:** {i}\n**Key:** `{k}`\n**Addr:** `{a}`"
220
- for p, i, k, a in matches
221
- ) if matches else "Koi match nahi mila"
222
 
223
- # Return as Markdown
224
- return "\n\n".join(log_lines), matches_text
225
 
226
  # ============================================================
227
- # Build UI (Clean Layout, No Generators)
228
  # ============================================================
229
- with gr.Blocks(title="Phrase Scanner", css=".log-box { font-family: monospace; max-height: 400px; overflow-y: auto; }") as demo:
230
  gr.Markdown("# πŸ” Phrase Scanner")
231
- gr.Markdown("Apni phrase ya random phrases check karein, index range ke saath.")
232
-
233
  with gr.Row():
234
- with gr.Column(scale=1):
235
- gr.Markdown("### Settings")
236
- my_phrase = gr.Textbox(
237
- label="πŸ”‘ Apni Phrase (optional)",
238
- value="lesson cushion crane affair federal decline limb spend reunion chief cart zebra",
239
- lines=2,
240
- )
241
- num_phrases = gr.Number(
242
- label="Kitni Random Phrases Check Karein?",
243
- value=10, precision=0, minimum=0,
244
- )
245
- addresses_file = gr.Textbox(
246
- label="Addresses File",
247
- value="12730802_addresses.csv",
248
- )
249
- phrase_mode = gr.Radio(
250
- choices=["replace", "order", "subset"],
251
- value="replace",
252
- label="Phrase Mode",
253
- )
254
- with gr.Row():
255
- start_index = gr.Number(label="Start Index", value=0, precision=0, minimum=0)
256
- end_index = gr.Number(label="End Index", value=20, precision=0, minimum=0)
257
- passphrase = gr.Textbox(label="BIP39 Passphrase (khali chhod dein)", value="", type="password")
258
- run_btn = gr.Button("πŸš€ Scan Shuru Karein", variant="primary")
259
-
260
- with gr.Column(scale=2):
261
- gr.Markdown("### Output")
262
- # gr.Markdown handles long text and scrolls perfectly
263
- log_output = gr.Markdown(
264
- value="Scan shuru karne ke liye button dabayein.",
265
- elem_classes="log-box"
266
- )
267
- gr.Markdown("### Matches")
268
- matches_output = gr.Markdown(
269
- value="Matches yahan dikhenge.",
270
- elem_classes="log-box"
271
- )
272
 
273
  run_btn.click(
274
- fn=run_scan_sync,
275
  inputs=[my_phrase, num_phrases, addresses_file, phrase_mode,
276
  start_index, end_index, passphrase],
277
  outputs=[log_output, matches_output],
 
129
  yield " ".join(combo)
130
 
131
  # ============================================================
132
+ # Scan Function (No Generators, No Yields)
133
  # ============================================================
134
 
135
+ def run_scan(my_phrase, num_phrases, addresses_file, phrase_mode,
136
+ start_index, end_index, passphrase):
137
 
138
  if not os.path.exists(addresses_file):
139
  return f"❌ File nahi mili: {addresses_file}", ""
 
160
  for _ in range(num_phrases):
161
  phrases.append(mnemo.generate(strength=128))
162
 
163
+ log_text = f"βœ… Loaded {len(known):,} addresses\n"
164
+ log_text += f"πŸ”§ Mode: {phrase_mode} | πŸ”‘ Index: {start_index}-{end_index}\n"
165
+ log_text += f"πŸ“ Total phrases: {len(phrases)}\n\n"
 
 
 
 
 
 
 
 
166
 
167
+ log_text += "Phrases:\n"
168
+ for i, p in enumerate(phrases, 1):
169
+ tag = " (AAPKI)" if i == 1 and len(my_words) == 12 else ""
170
+ log_text += f" {i}. {p}{tag}\n"
171
+ log_text += "\n--- Scanning ---\n"
172
 
173
  matches = []
174
  start = time.time()
175
  total_phrases = len(phrases)
176
 
177
  for p_idx, phrase in enumerate(phrases, 1):
178
+ log_text += f"\nπŸ” [{p_idx}/{total_phrases}] Checking: {phrase}\n"
179
  words = phrase.strip().split()
180
 
181
  if len(words) != 12:
182
+ log_text += " ⚠️ Skipped (not 12 words)\n"
183
  continue
184
 
185
  for idx in range(start_index, end_index + 1):
186
+ log_text += f" - Index {idx}...\n"
187
  for phrase_str in generate_phrases_for_words(words, phrase_mode):
188
  if not is_valid_bip39(phrase_str):
189
  continue
 
196
  continue
197
 
198
  if normalize(addr) in known:
199
+ match_line = f"πŸŽ‰ MATCH!\nPhrase: {phrase_str}\nIndex: {idx}\nKey: {priv.hex()}\nAddr: {addr}\n"
200
+ log_text += match_line
201
+ matches.append(match_line)
 
 
 
 
 
 
202
 
203
  elapsed = time.time() - start
204
+ log_text += f"\n=== DONE ===\nTotal time: {elapsed:.1f}s\nTotal matches: {len(matches)}\n"
 
 
 
205
 
206
+ matches_text = "\n".join(matches) if matches else "Koi match nahi mila"
 
 
 
207
 
208
+ return log_text, matches_text
 
209
 
210
  # ============================================================
211
+ # Simple, Flat UI (No Columns, No Layout Bugs)
212
  # ============================================================
213
+ with gr.Blocks(title="Phrase Scanner") as demo:
214
  gr.Markdown("# πŸ” Phrase Scanner")
215
+
 
216
  with gr.Row():
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
+ with gr.Row():
224
+ num_phrases = gr.Number(label="Kitni Random Phrases Check Karein?", value=10, precision=0, minimum=0)
225
+ addresses_file = gr.Textbox(label="Addresses File", value="12730802_addresses.csv")
226
+
227
+ with gr.Row():
228
+ phrase_mode = gr.Radio(choices=["replace", "order", "subset"], value="replace", label="Phrase Mode")
229
+ start_index = gr.Number(label="Start Index", value=0, precision=0, minimum=0)
230
+ end_index = gr.Number(label="End Index", value=20, precision=0, minimum=0)
231
+
232
+ with gr.Row():
233
+ passphrase = gr.Textbox(label="BIP39 Passphrase (khali chhod dein)", value="", type="password")
234
+
235
+ run_btn = gr.Button("πŸš€ Scan Shuru Karein", variant="primary")
236
+
237
+ gr.Markdown("### Output")
238
+ log_output = gr.Textbox(lines=15, interactive=False, show_label=False)
239
+
240
+ gr.Markdown("### Matches")
241
+ matches_output = gr.Textbox(lines=8, interactive=False, show_label=False)
 
 
 
 
 
 
 
 
 
 
 
 
 
242
 
243
  run_btn.click(
244
+ fn=run_scan,
245
  inputs=[my_phrase, num_phrases, addresses_file, phrase_mode,
246
  start_index, end_index, passphrase],
247
  outputs=[log_output, matches_output],