zanegraper commited on
Commit
5ecd59e
Β·
1 Parent(s): a5f3e3d
Files changed (1) hide show
  1. app.py +24 -53
app.py CHANGED
@@ -2,65 +2,36 @@
2
 
3
  import gradio as gr
4
  import pandas as pd
5
- import time
6
  from combined_email_finder import get_combined_emails
7
 
8
- def extract_emails_with_feedback(domain):
9
- """Yields progress messages during extraction and returns email list + downloadable CSV."""
10
- yield "🟑 Step 1: Starting email extraction..."
11
-
12
- time.sleep(0.5)
13
- yield "🟠 Step 2: Crawling the homepage and common subpages..."
14
-
15
- time.sleep(0.5)
16
- yield "πŸ”΅ Step 3: Searching engines like Google and Bing..."
17
-
18
- time.sleep(0.5)
19
  emails = get_combined_emails(domain)
20
-
21
  if emails:
22
- yield "🟒 Step 4: Emails found!\n" + "\n".join(emails)
23
- else:
24
- yield "⚠️ No valid emails found for this domain."
25
 
26
- def get_results_csv(domain):
27
- """Returns CSV file for download based on extracted emails."""
28
  emails = get_combined_emails(domain)
29
  if not emails:
30
  return None
31
  df = pd.DataFrame({"Email": emails})
32
- csv_path = "extracted_emails.csv"
33
- df.to_csv(csv_path, index=False)
34
- return csv_path
35
-
36
- # --- GRADIO UI ---
37
-
38
- with gr.Blocks(title="AI-Powered Email Extractor", theme=gr.themes.Default()) as demo:
39
- gr.Markdown("# πŸ“§ AI-Powered EmailFinder")
40
- gr.Markdown("This adaptive interface finds emails from a domain using both live scraping and search engines.")
41
-
42
- with gr.Row():
43
- domain_input = gr.Textbox(label="🌐 Enter a Domain (e.g. example.com)", elem_id="domain_input", info="Required for email extraction")
44
-
45
- with gr.Row():
46
- submit_button = gr.Button("πŸ” Extract Emails")
47
- csv_button = gr.Button("πŸ“₯ Download Emails as CSV")
48
-
49
- feedback_output = gr.Textbox(label="πŸ“ Progress & Results", lines=10)
50
- download_output = gr.File(label="Download CSV File", file_types=[".csv"])
51
-
52
- # Event: When 'Extract Emails' is clicked
53
- submit_button.click(
54
- extract_emails_with_feedback,
55
- inputs=domain_input,
56
- outputs=feedback_output
57
- )
58
-
59
- # Event: When 'Download CSV' is clicked
60
- csv_button.click(
61
- get_results_csv,
62
- inputs=domain_input,
63
- outputs=download_output
64
- )
65
-
66
- demo.launch(share=True)
 
2
 
3
  import gradio as gr
4
  import pandas as pd
5
+ import tempfile
6
  from combined_email_finder import get_combined_emails
7
 
8
+ def extract_emails(domain):
 
 
 
 
 
 
 
 
 
 
9
  emails = get_combined_emails(domain)
 
10
  if emails:
11
+ return "\n".join(emails)
12
+ return "⚠️ No valid emails found."
 
13
 
14
+ def export_csv(domain):
 
15
  emails = get_combined_emails(domain)
16
  if not emails:
17
  return None
18
  df = pd.DataFrame({"Email": emails})
19
+ with tempfile.NamedTemporaryFile(delete=False, suffix=".csv", mode='w', encoding='utf-8') as tmp:
20
+ df.to_csv(tmp.name, index=False)
21
+ return tmp.name
22
+
23
+ iface = gr.Interface(
24
+ fn=extract_emails,
25
+ inputs=gr.Textbox(label="🌐 Enter Domain (e.g. example.com)", placeholder="example.com"),
26
+ outputs=[
27
+ gr.Textbox(label="πŸ“§ Extracted Emails", lines=10),
28
+ gr.File(label="πŸ“₯ Download CSV")
29
+ ],
30
+ title="AI-Powered EmailFinder",
31
+ description="Finds emails using webpage crawling and search engines via EmailFinder."
32
+ )
33
+
34
+ # Add a second function call for the CSV generator
35
+ iface.add_component("πŸ“₯ Download Emails as CSV", export_csv)
36
+
37
+ iface.launch()