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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +42 -60
app.py CHANGED
@@ -129,30 +129,26 @@ def generate_phrases_for_words(wordlist, mode):
129
  yield " ".join(combo)
130
 
131
  # ============================================================
132
- # Gradio Scan Function
133
  # ============================================================
134
 
135
- def run_multi_phrase_scan(my_phrase, num_phrases, addresses_file, phrase_mode,
136
- start_index, end_index, passphrase):
 
137
  if not os.path.exists(addresses_file):
138
- yield f"❌ File nahi mili: {addresses_file}", ""
139
- return
140
 
141
  num_phrases = int(num_phrases)
142
  start_index = int(start_index)
143
  end_index = int(end_index)
144
 
145
- yield "Addresses load ho rahe hain...", ""
146
-
147
  try:
148
  known = load_addresses_cached(addresses_file)
149
  except Exception as e:
150
- yield f"❌ Addresses load fail: {e}", ""
151
- return
152
 
153
  if not known:
154
- yield "❌ Koi valid address file mein nahi mila", ""
155
- return
156
 
157
  mnemo = _get_mnemonic()
158
  phrases = []
@@ -170,40 +166,27 @@ def run_multi_phrase_scan(my_phrase, num_phrases, addresses_file, phrase_mode,
170
  f"πŸ”‘ Index range: {start_index}–{end_index}",
171
  f"πŸ“ Total phrases: {len(phrases)}",
172
  "",
173
- "Phrases:",
174
  ]
175
  for i, p in enumerate(phrases, 1):
176
- tag = " (AAPKI)" if i == 1 and len(my_words) == 12 else ""
177
- log_lines.append(f" {i}. {p}{tag}")
178
- log_lines.append("")
179
-
180
- yield "\n".join(log_lines), "Scan shuru ho raha hai..."
181
 
182
  matches = []
183
  start = time.time()
184
  total_phrases = len(phrases)
185
 
186
  for p_idx, phrase in enumerate(phrases, 1):
187
- log_lines.append(f"---")
188
- log_lines.append(f"πŸ” [{p_idx}/{total_phrases}] Checking: {phrase}")
189
- yield "\n".join(log_lines), (
190
- "\n".join(f"Phrase: {p}\nIndex: {i}\nKey: {k}\nAddr: {a}\n" for p, i, k, a in matches)
191
- if matches else "Abhi tak koi match nahi"
192
- )
193
-
194
  words = phrase.strip().split()
 
195
  if len(words) != 12:
196
- log_lines.append(f"⚠️ Skipped (not 12 words)")
197
- yield "\n".join(log_lines), "Abhi tak koi match nahi"
198
  continue
199
 
200
  for idx in range(start_index, end_index + 1):
201
- log_lines.append(f" - Index {idx}...")
202
- yield "\n".join(log_lines), (
203
- "\n".join(f"Phrase: {p}\nIndex: {i}\nKey: {k}\nAddr: {a}\n" for p, i, k, a in matches)
204
- if matches else "Abhi tak koi match nahi"
205
- )
206
-
207
  for phrase_str in generate_phrases_for_words(words, phrase_mode):
208
  if not is_valid_bip39(phrase_str):
209
  continue
@@ -214,37 +197,36 @@ def run_multi_phrase_scan(my_phrase, num_phrases, addresses_file, phrase_mode,
214
  addr = to_checksum_address(keccak(pub)[-20:])
215
  except Exception:
216
  continue
 
217
  if normalize(addr) in known:
218
  match_line = (
219
- f"πŸŽ‰ MATCH!\n"
220
- f"Phrase: {phrase_str}\n"
221
- f"Index: {idx}\n"
222
- f"Key: {priv.hex()}\n"
223
- f"Addr: {addr}\n"
224
  )
225
  log_lines.append(match_line)
226
  matches.append((phrase_str, idx, priv.hex(), addr))
227
- yield "\n".join(log_lines), "\n".join(
228
- f"Phrase: {p}\nIndex: {i}\nKey: {k}\nAddr: {a}\n" for p, i, k, a in matches
229
- )
230
 
231
  elapsed = time.time() - start
232
- log_lines.append(f"---")
233
- log_lines.append(f"=== DONE ===")
234
- log_lines.append(f"Total time: {elapsed:.1f}s")
235
- log_lines.append(f"Total matches: {len(matches)}")
236
-
237
- matches_text = "\n".join(
238
- f"Phrase: {p}\nIndex: {i}\nKey: {k}\nAddr: {a}\n" for p, i, k, a in matches
 
239
  ) if matches else "Koi match nahi mila"
240
 
241
- yield "\n".join(log_lines), matches_text
242
-
243
 
244
  # ============================================================
245
- # Clean, Standard UI (No fancy CSS that breaks Gradio 6)
246
  # ============================================================
247
- with gr.Blocks(title="Phrase Scanner") as demo:
248
  gr.Markdown("# πŸ” Phrase Scanner")
249
  gr.Markdown("Apni phrase ya random phrases check karein, index range ke saath.")
250
 
@@ -277,19 +259,19 @@ with gr.Blocks(title="Phrase Scanner") as demo:
277
 
278
  with gr.Column(scale=2):
279
  gr.Markdown("### Output")
280
- log_output = gr.Textbox(
281
- label="Scan Log",
282
- lines=25,
283
- interactive=False,
284
  )
285
- matches_output = gr.Textbox(
286
- label="Matches",
287
- lines=10,
288
- interactive=False,
289
  )
290
 
291
  run_btn.click(
292
- fn=run_multi_phrase_scan,
293
  inputs=[my_phrase, num_phrases, addresses_file, phrase_mode,
294
  start_index, end_index, passphrase],
295
  outputs=[log_output, matches_output],
 
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}", ""
 
140
 
141
  num_phrases = int(num_phrases)
142
  start_index = int(start_index)
143
  end_index = int(end_index)
144
 
 
 
145
  try:
146
  known = load_addresses_cached(addresses_file)
147
  except Exception as e:
148
+ return f"❌ Addresses load fail: {e}", ""
 
149
 
150
  if not known:
151
+ return "❌ Koi valid address file mein nahi mila", ""
 
152
 
153
  mnemo = _get_mnemonic()
154
  phrases = []
 
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
 
197
  addr = to_checksum_address(keccak(pub)[-20:])
198
  except Exception:
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
 
 
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],