Spaces:
Sleeping
Sleeping
0x11c11e
commited on
Commit
•
d29611d
1
Parent(s):
619a788
Add application file
Browse files
app.py
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import spacy
|
3 |
+
import requests
|
4 |
+
from bs4 import BeautifulSoup
|
5 |
+
|
6 |
+
# Load the pre-trained model
|
7 |
+
nlp = spacy.load("en_core_web_sm")
|
8 |
+
|
9 |
+
def extract_entities(url):
|
10 |
+
# Step 1: Web scraping
|
11 |
+
response = requests.get(url)
|
12 |
+
soup = BeautifulSoup(response.text, 'html.parser')
|
13 |
+
page_text = soup.get_text()
|
14 |
+
|
15 |
+
# Apply the model to the text
|
16 |
+
doc = nlp(page_text)
|
17 |
+
|
18 |
+
# Extract entities and return as a formatted string
|
19 |
+
results = "\n".join([f"{entity.text} ({entity.label_})" for entity in doc.ents])
|
20 |
+
return results
|
21 |
+
|
22 |
+
iface = gr.Interface(fn=extract_entities,
|
23 |
+
inputs="textbox",
|
24 |
+
outputs="text",
|
25 |
+
interpretation="default")
|
26 |
+
|
27 |
+
iface.launch()
|