File size: 1,163 Bytes
8efe659
2fe2a42
13ac7c2
2fe2a42
13ac7c2
2fe2a42
13ac7c2
 
 
 
 
 
 
 
 
 
 
 
 
56c79b1
 
 
 
 
 
 
 
13ac7c2
 
 
 
 
 
 
 
 
2fe2a42
13ac7c2
 
 
 
 
 
 
56c79b1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import gradio as gr
from mailparser import parse_from_string
from bs4 import BeautifulSoup

def accept_mail(name):
    email = parse_from_string(name)
    return email

def clean_email(email):
    soup = BeautifulSoup(email.body, 'html.parser')

    for tag in soup.find_all(['style', 'link']):
        tag.decompose()

    cleaned_text = ' '.join(soup.get_text(separator=' ').split())
    return cleaned_text

def present(email):
    email_info = {
        "Subject": email.subject,
        "From": email.from_,
        "To": email.to,
        "Date": email.date,
        "Message ID": email.message_id,
        "Headers": email.headers,
        "Attachments": email.attachments
    }
    return [
        email_info["Subject"], 
        email_info["From"], 
        email_info["To"], 
        email_info["Date"], 
        email_info["Message ID"], 
        email_info["Headers"], 
        email_info["Attachments"]
    ]

demo = gr.Interface(
    fn=present, 
    inputs="text", 
    outputs=["text", "text", "text", "text", "text", "text", "text"], 
    title="Email Info", 
    description="Enter the email content below to view its details."
)
demo.launch()