KrishanRao commited on
Commit
f6a3a56
·
verified ·
1 Parent(s): 90bfb01

Delete app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -77
app.py DELETED
@@ -1,77 +0,0 @@
1
- import gradio as gr
2
- from urllib.request import urlopen, Request
3
- from bs4 import BeautifulSoup
4
- from transformers import pipeline
5
- import os
6
-
7
- # Function to extract text from the URL
8
- def extract_text(url):
9
- req = Request(url, headers={'User-Agent': 'Mozilla/5.0'})
10
- html = urlopen(req).read()
11
- text = ' '.join(BeautifulSoup(html, "html.parser").stripped_strings)
12
- return text
13
-
14
- # Load Hugging Face model (for extracting named entities or QA)
15
- ner_model = pipeline("ner", model="dbmdz/bert-large-cased-finetuned-conll03-english")
16
-
17
- # Function to extract information using Hugging Face model
18
- def extract_info_with_model(text):
19
- # Apply named entity recognition (NER) to extract entities from the text
20
- ner_results = ner_model(text)
21
-
22
- # Initialize variables
23
- keytags = []
24
- seller_name = ""
25
- location_details = ""
26
- amenities = ""
27
- facilities = ""
28
-
29
- # Search for relevant named entities
30
- for entity in ner_results:
31
- if entity['label'] == 'ORG':
32
- keytags.append(entity['word']) # Example: Company or key term (this can be changed)
33
- elif entity['label'] == 'PERSON':
34
- seller_name = entity['word'] # If a person is mentioned, consider it the seller name
35
- elif entity['label'] == 'GPE':
36
- location_details = entity['word'] # Geopolitical entity as location
37
-
38
- # For amenities and facilities, you can modify the logic or use additional models (e.g., question-answering models)
39
- amenities = "No amenities found" # Placeholder for the amenities
40
- facilities = "No facilities found" # Placeholder for the facilities
41
-
42
- return {
43
- "Keytags": ", ".join(keytags) if keytags else "No keytags found",
44
- "Amenities": amenities,
45
- "Facilities": facilities,
46
- "Seller Name": seller_name if seller_name else "No seller name found",
47
- "Location Details": location_details if location_details else "No location details found"
48
- }
49
-
50
- # Function to combine the extraction process (from URL + model processing)
51
- def get_info(url):
52
- text = extract_text(url)
53
- extracted_info = extract_info_with_model(text)
54
-
55
- # Print debug to understand what's being returned
56
- print(extracted_info)
57
-
58
- # Ensure the information is returned in the expected format
59
- return (
60
- extracted_info["Keytags"],
61
- extracted_info["Amenities"],
62
- extracted_info["Facilities"],
63
- extracted_info["Seller Name"],
64
- extracted_info["Location Details"]
65
- )
66
-
67
- # Gradio Interface to allow user input and display output
68
- demo = gr.Interface(
69
- fn=get_info,
70
- inputs="text", # Input is a URL
71
- outputs=["text", "text", "text", "text", "text"], # Outputs for each field (Keytags, Amenities, etc.)
72
- title="Real Estate Info Extractor",
73
- description="Extract Keytags, Amenities, Facilities, Seller Name, and Location Details from a real estate article URL."
74
- )
75
-
76
- if __name__ == "__main__":
77
- demo.launch(show_api=False)