Delete app.py
Browse files
app.py
DELETED
@@ -1,45 +0,0 @@
|
|
1 |
-
#!/usr/bin/env python
|
2 |
-
# coding: utf-8
|
3 |
-
|
4 |
-
import spacy
|
5 |
-
from urllib.request import urlopen, Request
|
6 |
-
from bs4 import BeautifulSoup
|
7 |
-
import gradio as gr
|
8 |
-
|
9 |
-
# For text-processing
|
10 |
-
nlp = spacy.load("en_core_web_sm")
|
11 |
-
|
12 |
-
|
13 |
-
def extract_text(url):
|
14 |
-
req = Request(url, headers={'User-Agent': 'Mozilla/5.0'})
|
15 |
-
html = urlopen(req).read()
|
16 |
-
text = ' '.join(BeautifulSoup(html, "html.parser").stripped_strings)
|
17 |
-
return text
|
18 |
-
|
19 |
-
def extract_details(text):
|
20 |
-
doc = nlp(text)
|
21 |
-
|
22 |
-
names = [ent.text for ent in doc.ents if ent.label_ == "PERSON"]
|
23 |
-
dates = [ent.text for ent in doc.ents if ent.label_ == "DATE"]
|
24 |
-
|
25 |
-
husband_name = next((name for name in names if "husband" in text.lower()), "Not Found")
|
26 |
-
children = [name for name in names if "child" in text.lower() or "children" in text.lower()]
|
27 |
-
marriage_date = next((date for date in dates if "marriage" in text.lower()), "Not Found")
|
28 |
-
grandchildren = [name for name in names if "grandchild" in text.lower() or "grandchildren" in text.lower()]
|
29 |
-
greatgrandchildren = [name for name in names if "great-grandchild" in text.lower() or "great-grandchildren" in text.lower()]
|
30 |
-
|
31 |
-
table = f"""
|
32 |
-
| Name | Birthday | Husband Name | Children | Marriage Date | Grandchildren | Great-grandchildren |
|
33 |
-
|-----------------|---------------|----------------|------------------|-----------------|-----------------------|-----------------------|
|
34 |
-
| {', '.join(names[:1])} | {', '.join(dates[:1])} | {husband_name} | {', '.join(children)} | {marriage_date} | {', '.join(grandchildren)} | {', '.join(greatgrandchildren)} |
|
35 |
-
"""
|
36 |
-
return table
|
37 |
-
|
38 |
-
def create_table(url):
|
39 |
-
text = extract_text(url)
|
40 |
-
return extract_details(text)
|
41 |
-
|
42 |
-
demo = gr.Interface(fn=create_table, inputs="text", outputs="text")
|
43 |
-
|
44 |
-
if __name__ == "__main__":
|
45 |
-
demo.launch(show_api=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|