Nikhil Singh commited on
Commit
13ac7c2
·
1 Parent(s): 227804c

further updates

Browse files
Files changed (2) hide show
  1. app.py +31 -23
  2. requirements.txt +2 -1
app.py CHANGED
@@ -1,9 +1,22 @@
1
  import gradio as gr
2
  from mailparser import parse_from_string
 
3
 
4
- def receive_mail(name):
5
  email = parse_from_string(name)
6
- return {
 
 
 
 
 
 
 
 
 
 
 
 
7
  "Subject": email.subject,
8
  "From": email.from_,
9
  "To": email.to,
@@ -12,26 +25,21 @@ def receive_mail(name):
12
  "Headers": email.headers,
13
  "Attachments": email.attachments
14
  }
 
 
 
 
 
 
 
 
 
15
 
16
- def greet(name):
17
- email_info = receive_mail(name)
18
- return ([email_info["Subject"],
19
- email_info["From"],
20
- email_info["To"],
21
- email_info["Date"],
22
- email_info["Message ID"],
23
- email_info["Headers"],
24
- email_info["Attachments"]])
25
-
26
- demo = gr.Interface(fn=greet,
27
- inputs="text",
28
- outputs=["text",
29
- "text",
30
- "text",
31
- "text",
32
- "text",
33
- "text",
34
- "text"],
35
- title="Email Info",
36
- description="Enter the email content below to view its details.")
37
  demo.launch()
 
1
  import gradio as gr
2
  from mailparser import parse_from_string
3
+ from bs4 import BeautifulSoup
4
 
5
+ def accept_mail(name):
6
  email = parse_from_string(name)
7
+ return email
8
+
9
+ def clean_email(email):
10
+ soup = BeautifulSoup(email.body, 'html.parser')
11
+
12
+ for tag in soup.find_all(['style', 'link']):
13
+ tag.decompose()
14
+
15
+ cleaned_text = ' '.join(soup.get_text(separator=' ').split())
16
+ return cleaned_text
17
+
18
+ def present(email):
19
+ email_info = {
20
  "Subject": email.subject,
21
  "From": email.from_,
22
  "To": email.to,
 
25
  "Headers": email.headers,
26
  "Attachments": email.attachments
27
  }
28
+ return [
29
+ email_info["Subject"],
30
+ email_info["From"],
31
+ email_info["To"],
32
+ email_info["Date"],
33
+ email_info["Message ID"],
34
+ email_info["Headers"],
35
+ email_info["Attachments"]
36
+ ]
37
 
38
+ demo = gr.Interface(
39
+ fn=present,
40
+ inputs="text",
41
+ outputs=["text", "text", "text", "text", "text", "text", "text"],
42
+ title="Email Info",
43
+ description="Enter the email content below to view its details."
44
+ )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
45
  demo.launch()
requirements.txt CHANGED
@@ -2,4 +2,5 @@ gliner
2
  mail-parser
3
  scipy==1.12
4
  gradio
5
- typing
 
 
2
  mail-parser
3
  scipy==1.12
4
  gradio
5
+ typing
6
+ bs4