Nikhil Singh commited on
Commit
c447545
·
1 Parent(s): a6daf3c

email upload

Browse files
Files changed (1) hide show
  1. app.py +8 -9
app.py CHANGED
@@ -1,6 +1,6 @@
1
  import gradio as gr
2
 
3
- from mailparser import parse_from_string
4
  from bs4 import BeautifulSoup
5
  from gliner import GLiNER
6
  from typing import Dict, Union, List
@@ -11,12 +11,11 @@ import os
11
  import en_core_web_sm
12
  nlp = en_core_web_sm.load()
13
 
14
- # nlp = spacy.load("en_core_web_sm")
15
  _MODEL = {}
16
  _CACHE_DIR = os.environ.get("CACHE_DIR", None)
17
 
18
- def accept_mail(email_content):
19
- email = parse_from_string(email_content)
20
  return email
21
 
22
  def clean_email(email):
@@ -64,8 +63,8 @@ def parse_query(sentences: List[str], labels: List[str], threshold: float = 0.3,
64
 
65
  return results
66
 
67
- def present(email_content, labels, multilingual=False):
68
- email = accept_mail(email_content)
69
  cleaned_text = clean_email(email)
70
  further_cleaned_text = remove_special_characters(cleaned_text)
71
  sentence_list = get_sentences(further_cleaned_text)
@@ -87,7 +86,7 @@ labels = ["PERSON", "PRODUCT", "DEAL", "ORDER", "ORDER PAYMENT METHOD", "STORE",
87
  demo = gr.Interface(
88
  fn=present,
89
  inputs=[
90
- gr.components.Textbox(label="Email Content"),
91
  gr.components.CheckboxGroup(
92
  choices=labels,
93
  label="Labels to Detect",
@@ -103,7 +102,7 @@ demo = gr.Interface(
103
  gr.components.Textbox(label="Cleaned Body"),
104
  gr.components.JSON(label="Extracted Entities")
105
  ],
106
- title="Email Info",
107
- description="Enter the email content below to view its details and detected entities."
108
  )
109
  demo.launch(share=True)
 
1
  import gradio as gr
2
 
3
+ from mailparser import parse_from_file
4
  from bs4 import BeautifulSoup
5
  from gliner import GLiNER
6
  from typing import Dict, Union, List
 
11
  import en_core_web_sm
12
  nlp = en_core_web_sm.load()
13
 
 
14
  _MODEL = {}
15
  _CACHE_DIR = os.environ.get("CACHE_DIR", None)
16
 
17
+ def accept_mail(file_path):
18
+ email = parse_from_file(file_path)
19
  return email
20
 
21
  def clean_email(email):
 
63
 
64
  return results
65
 
66
+ def present(email_file, labels, multilingual=False):
67
+ email = accept_mail(email_file)
68
  cleaned_text = clean_email(email)
69
  further_cleaned_text = remove_special_characters(cleaned_text)
70
  sentence_list = get_sentences(further_cleaned_text)
 
86
  demo = gr.Interface(
87
  fn=present,
88
  inputs=[
89
+ gr.components.File(label="Upload Email (.eml file)"),
90
  gr.components.CheckboxGroup(
91
  choices=labels,
92
  label="Labels to Detect",
 
102
  gr.components.Textbox(label="Cleaned Body"),
103
  gr.components.JSON(label="Extracted Entities")
104
  ],
105
+ title="Email Info Extractor",
106
+ description="Upload an email file (.eml) to extract its details and detected entities."
107
  )
108
  demo.launch(share=True)