Nikhil Singh commited on
Commit
3fd92e9
·
1 Parent(s): 1efe83d
Files changed (1) hide show
  1. app.py +20 -30
app.py CHANGED
@@ -2,8 +2,8 @@ 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):
@@ -22,36 +22,26 @@ def present(email_content):
22
  "To": email.to,
23
  "Date": email.date,
24
  "Message ID": email.message_id,
25
- "Headers": email.headers,
26
- "Attachments": email.attachments,
27
  "Cleaned Body": cleaned_text
28
  }
29
  return [email_info[key] for key in email_info]
30
 
31
- with gr.Blocks() as demo:
32
- gr.Markdown("## Email Info")
33
- gr.Markdown("Enter the email content below to view its details.")
34
- with gr.Row():
35
- with gr.Column():
36
- input_text = gr.Textbox(label="Email Content")
37
- output_texts = [
38
- gr.Textbox(label="Subject"),
39
- gr.Textbox(label="From"),
40
- gr.Textbox(label="To"),
41
- gr.Textbox(label="Date"),
42
- gr.Textbox(label="Message ID"),
43
- gr.Textbox(label="Headers"),
44
- gr.Textbox(label="Attachments"),
45
- gr.Textbox(label="Cleaned Body", visible=False) # Initially hidden
46
- ]
47
- button = gr.Button("Process Email")
48
- with gr.Column():
49
- output_cleaned_text = gr.Textbox(label="Cleaned Email Body")
50
-
51
- button.click(
52
- present,
53
- inputs=input_text,
54
- outputs=output_texts + [output_cleaned_text]
55
- )
56
-
57
  demo.launch()
 
2
  from mailparser import parse_from_string
3
  from bs4 import BeautifulSoup
4
 
5
+ def accept_mail(email_content):
6
+ email = parse_from_string(email_content)
7
  return email
8
 
9
  def clean_email(email):
 
22
  "To": email.to,
23
  "Date": email.date,
24
  "Message ID": email.message_id,
25
+ "Headers": str(email.headers), # Convert dictionary to string for display
26
+ "Attachments": str(email.attachments), # Convert list to string for display
27
  "Cleaned Body": cleaned_text
28
  }
29
  return [email_info[key] for key in email_info]
30
 
31
+ demo = gr.Interface(
32
+ fn=present,
33
+ inputs="text",
34
+ outputs=[
35
+ gr.components.Textbox(label="Subject"),
36
+ gr.components.Textbox(label="From"),
37
+ gr.components.Textbox(label="To"),
38
+ gr.components.Textbox(label="Date"),
39
+ gr.components.Textbox(label="Message ID"),
40
+ gr.components.Textbox(label="Headers"),
41
+ gr.components.Textbox(label="Attachments"),
42
+ gr.components.Textbox(label="Cleaned Body")
43
+ ],
44
+ title="Email Info",
45
+ description="Enter the email content below to view its details."
46
+ )
 
 
 
 
 
 
 
 
 
 
47
  demo.launch()