Update app2.py
Browse files
app2.py
CHANGED
@@ -1556,6 +1556,222 @@ def automated_legal_brief_generation_ui():
|
|
1556 |
file_name="legal_brief.txt",
|
1557 |
mime="text/plain"
|
1558 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1559 |
# --- Streamlit App ---
|
1560 |
st.markdown("""
|
1561 |
<style>
|
@@ -1608,7 +1824,7 @@ with st.sidebar:
|
|
1608 |
|
1609 |
feature = st.selectbox(
|
1610 |
"Select a feature",
|
1611 |
-
["Legal Chatbot", "Document Analysis", "Case Precedent Finder", "Legal Cost Estimator", "Contract Analysis", "Case Trend Visualizer", "Case Information Retrieval", "Automated Legal Brief Generation"]
|
1612 |
)
|
1613 |
if feature == "Legal Chatbot":
|
1614 |
st.subheader("Legal Chatbot")
|
@@ -1770,6 +1986,9 @@ elif feature == "Case Information Retrieval":
|
|
1770 |
elif feature == "Automated Legal Brief Generation":
|
1771 |
automated_legal_brief_generation_ui()
|
1772 |
|
|
|
|
|
|
|
1773 |
st.markdown("---")
|
1774 |
st.markdown(
|
1775 |
"""
|
|
|
1556 |
file_name="legal_brief.txt",
|
1557 |
mime="text/plain"
|
1558 |
)
|
1559 |
+
|
1560 |
+
STATES = [
|
1561 |
+
"Alabama", "Alaska", "Arizona", "Arkansas", "California", "Colorado", "Connecticut", "Delaware", "Florida", "Georgia",
|
1562 |
+
"Hawaii", "Idaho", "Illinois", "Indiana", "Iowa", "Kansas", "Kentucky", "Louisiana", "Maine", "Maryland",
|
1563 |
+
"Massachusetts", "Michigan", "Minnesota", "Mississippi", "Missouri", "Montana", "Nebraska", "Nevada", "New Hampshire", "New Jersey",
|
1564 |
+
"New Mexico", "New York", "North Carolina", "North Dakota", "Ohio", "Oklahoma", "Oregon", "Pennsylvania", "Rhode Island", "South Carolina",
|
1565 |
+
"South Dakota", "Tennessee", "Texas", "Utah", "Vermont", "Virginia", "Washington", "West Virginia", "Wisconsin", "Wyoming"
|
1566 |
+
]
|
1567 |
+
|
1568 |
+
CITIES_BY_STATE = {
|
1569 |
+
"Alabama": ["Birmingham", "Montgomery", "Mobile", "Huntsville"],
|
1570 |
+
"Alaska": ["Anchorage", "Fairbanks", "Juneau"],
|
1571 |
+
"Arizona": ["Phoenix", "Tucson", "Mesa", "Chandler"],
|
1572 |
+
"Arkansas": ["Little Rock", "Fort Smith", "Fayetteville"],
|
1573 |
+
"California": ["Los Angeles", "San Francisco", "San Diego", "San Jose"],
|
1574 |
+
"Colorado": ["Denver", "Colorado Springs", "Aurora", "Fort Collins"],
|
1575 |
+
"Connecticut": ["Bridgeport", "New Haven", "Hartford", "Stamford"],
|
1576 |
+
"Delaware": ["Wilmington", "Dover", "Newark"],
|
1577 |
+
"Florida": ["Miami", "Orlando", "Jacksonville", "Tampa"],
|
1578 |
+
"Georgia": ["Atlanta", "Augusta", "Columbus", "Savannah"],
|
1579 |
+
"Hawaii": ["Honolulu", "Hilo", "Kailua"],
|
1580 |
+
"Idaho": ["Boise", "Nampa", "Meridian"],
|
1581 |
+
"Illinois": ["Chicago", "Aurora", "Rockford", "Joliet"],
|
1582 |
+
"Indiana": ["Indianapolis", "Fort Wayne", "Evansville"],
|
1583 |
+
"Iowa": ["Des Moines", "Cedar Rapids", "Davenport"],
|
1584 |
+
"Kansas": ["Wichita", "Overland Park", "Kansas City"],
|
1585 |
+
"Kentucky": ["Louisville", "Lexington", "Bowling Green"],
|
1586 |
+
"Louisiana": ["New Orleans", "Baton Rouge", "Shreveport"],
|
1587 |
+
"Maine": ["Portland", "Lewiston", "Bangor"],
|
1588 |
+
"Maryland": ["Baltimore", "Columbia", "Annapolis"],
|
1589 |
+
"Massachusetts": ["Boston", "Worcester", "Springfield"],
|
1590 |
+
"Michigan": ["Detroit", "Grand Rapids", "Ann Arbor"],
|
1591 |
+
"Minnesota": ["Minneapolis", "St. Paul", "Rochester"],
|
1592 |
+
"Mississippi": ["Jackson", "Gulfport", "Southaven"],
|
1593 |
+
"Missouri": ["Kansas City", "St. Louis", "Springfield"],
|
1594 |
+
"Montana": ["Billings", "Missoula", "Great Falls"],
|
1595 |
+
"Nebraska": ["Omaha", "Lincoln", "Bellevue"],
|
1596 |
+
"Nevada": ["Las Vegas", "Reno", "Henderson"],
|
1597 |
+
"New Hampshire": ["Manchester", "Nashua", "Concord"],
|
1598 |
+
"New Jersey": ["Newark", "Jersey City", "Paterson"],
|
1599 |
+
"New Mexico": ["Albuquerque", "Las Cruces", "Santa Fe"],
|
1600 |
+
"New York": ["New York City", "Buffalo", "Rochester", "Syracuse"],
|
1601 |
+
"North Carolina": ["Charlotte", "Raleigh", "Greensboro"],
|
1602 |
+
"North Dakota": ["Fargo", "Bismarck", "Grand Forks"],
|
1603 |
+
"Ohio": ["Columbus", "Cleveland", "Cincinnati"],
|
1604 |
+
"Oklahoma": ["Oklahoma City", "Tulsa", "Norman"],
|
1605 |
+
"Oregon": ["Portland", "Eugene", "Salem"],
|
1606 |
+
"Pennsylvania": ["Philadelphia", "Pittsburgh", "Allentown"],
|
1607 |
+
"Rhode Island": ["Providence", "Warwick", "Cranston"],
|
1608 |
+
"South Carolina": ["Charleston", "Columbia", "North Charleston"],
|
1609 |
+
"South Dakota": ["Sioux Falls", "Rapid City", "Aberdeen"],
|
1610 |
+
"Tennessee": ["Nashville", "Memphis", "Knoxville"],
|
1611 |
+
"Texas": ["Houston", "Dallas", "Austin", "San Antonio"],
|
1612 |
+
"Utah": ["Salt Lake City", "West Valley City", "Provo"],
|
1613 |
+
"Vermont": ["Burlington", "South Burlington", "Rutland"],
|
1614 |
+
"Virginia": ["Virginia Beach", "Norfolk", "Chesapeake"],
|
1615 |
+
"Washington": ["Seattle", "Spokane", "Tacoma"],
|
1616 |
+
"West Virginia": ["Charleston", "Huntington", "Morgantown"],
|
1617 |
+
"Wisconsin": ["Milwaukee", "Madison", "Green Bay"],
|
1618 |
+
"Wyoming": ["Cheyenne", "Casper", "Laramie"]
|
1619 |
+
}
|
1620 |
+
|
1621 |
+
def find_lawyers(state, city, pages=1):
|
1622 |
+
base_url = "https://www.justia.com/lawyers/"
|
1623 |
+
url = f"{base_url}{state.lower()}/{city.lower().replace(' ', '-')}"
|
1624 |
+
|
1625 |
+
headers = {
|
1626 |
+
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36'
|
1627 |
+
}
|
1628 |
+
|
1629 |
+
names = []
|
1630 |
+
short_bios = []
|
1631 |
+
specializations = []
|
1632 |
+
universities = []
|
1633 |
+
addresses = []
|
1634 |
+
phones = []
|
1635 |
+
email_links = []
|
1636 |
+
site_links = []
|
1637 |
+
|
1638 |
+
try:
|
1639 |
+
for page in range(1, pages + 1):
|
1640 |
+
page_url = f"{url}?page={page}"
|
1641 |
+
response = requests.get(page_url, headers=headers)
|
1642 |
+
response.raise_for_status()
|
1643 |
+
|
1644 |
+
soup = BeautifulSoup(response.content, 'html.parser')
|
1645 |
+
results = soup.find_all('div', {'data-vars-action': 'OrganicListing'})
|
1646 |
+
|
1647 |
+
for result in results:
|
1648 |
+
# Name
|
1649 |
+
try:
|
1650 |
+
names.append(result.find('strong', {'class': 'lawyer-name'}).get_text().strip())
|
1651 |
+
except:
|
1652 |
+
names.append('')
|
1653 |
+
|
1654 |
+
# Short Bio
|
1655 |
+
try:
|
1656 |
+
short_bios.append(result.find('div', {'class': 'lawyer-expl'}).get_text().strip())
|
1657 |
+
except:
|
1658 |
+
short_bios.append('')
|
1659 |
+
|
1660 |
+
# Specialization
|
1661 |
+
try:
|
1662 |
+
specializations.append(result.find('span', {'class': '-practices'}).get_text().strip())
|
1663 |
+
except:
|
1664 |
+
specializations.append('')
|
1665 |
+
|
1666 |
+
# University
|
1667 |
+
try:
|
1668 |
+
universities.append(result.find('span', {'class': '-law-schools'}).get_text().strip())
|
1669 |
+
except:
|
1670 |
+
universities.append('')
|
1671 |
+
|
1672 |
+
# Address
|
1673 |
+
try:
|
1674 |
+
addresses.append(result.find('span', {'class': '-address'}).get_text().strip().replace("\t", '').replace('\n', ', '))
|
1675 |
+
except:
|
1676 |
+
addresses.append('')
|
1677 |
+
|
1678 |
+
# Phone
|
1679 |
+
try:
|
1680 |
+
phones.append(result.find('strong', {'class': '-phone'}).get_text().strip())
|
1681 |
+
except:
|
1682 |
+
phones.append('')
|
1683 |
+
|
1684 |
+
# Email Link
|
1685 |
+
try:
|
1686 |
+
email_links.append(result.find('a', {'class': '-email'}).get('href'))
|
1687 |
+
except:
|
1688 |
+
email_links.append('')
|
1689 |
+
|
1690 |
+
# Site Link
|
1691 |
+
try:
|
1692 |
+
site_links.append(result.find('a', {'class': '-website'}).get('href'))
|
1693 |
+
except:
|
1694 |
+
site_links.append('')
|
1695 |
+
|
1696 |
+
df_lawyers = pd.DataFrame({
|
1697 |
+
'lawyer_name': names,
|
1698 |
+
'short_bio': short_bios,
|
1699 |
+
'specialization': specializations,
|
1700 |
+
'university': universities,
|
1701 |
+
'address': addresses,
|
1702 |
+
'phone': phones,
|
1703 |
+
'email_link': email_links,
|
1704 |
+
'site_link': site_links
|
1705 |
+
})
|
1706 |
+
|
1707 |
+
return df_lawyers
|
1708 |
+
|
1709 |
+
except requests.RequestException as e:
|
1710 |
+
st.error(f"An error occurred while fetching lawyer information: {str(e)}")
|
1711 |
+
return pd.DataFrame()
|
1712 |
+
|
1713 |
+
def lawyer_finder_ui():
|
1714 |
+
st.title("Find Lawyers in Your Area")
|
1715 |
+
|
1716 |
+
col1, col2 = st.columns(2)
|
1717 |
+
with col1:
|
1718 |
+
state = st.selectbox("Select a State:", STATES)
|
1719 |
+
|
1720 |
+
with col2:
|
1721 |
+
cities = CITIES_BY_STATE.get(state, [])
|
1722 |
+
city = st.selectbox("Select a City:", cities)
|
1723 |
+
|
1724 |
+
if not city:
|
1725 |
+
st.warning("Please select a city to continue.")
|
1726 |
+
return
|
1727 |
+
|
1728 |
+
pages = st.slider("Number of pages to scrape", 1, 20, 1)
|
1729 |
+
|
1730 |
+
if st.button("Find Lawyers", type="primary"):
|
1731 |
+
with st.spinner("Searching for lawyers in your area..."):
|
1732 |
+
df_lawyers = find_lawyers(state, city, pages)
|
1733 |
+
|
1734 |
+
if not df_lawyers.empty:
|
1735 |
+
st.success(f"Found {len(df_lawyers)} lawyers in {city}, {state}.")
|
1736 |
+
|
1737 |
+
# Display results in a more visually appealing way
|
1738 |
+
st.subheader("Lawyer Directory")
|
1739 |
+
for i in range(0, len(df_lawyers), 3):
|
1740 |
+
cols = st.columns(3)
|
1741 |
+
for j in range(3):
|
1742 |
+
if i + j < len(df_lawyers):
|
1743 |
+
lawyer = df_lawyers.iloc[i + j]
|
1744 |
+
with cols[j]:
|
1745 |
+
st.markdown(f"**{lawyer['lawyer_name']}**")
|
1746 |
+
st.markdown(f"*{lawyer['specialization']}*")
|
1747 |
+
if lawyer['phone']:
|
1748 |
+
st.markdown(f"📞 {lawyer['phone']}")
|
1749 |
+
if lawyer['email_link']:
|
1750 |
+
st.markdown(f"📧 [Email]({lawyer['email_link']})")
|
1751 |
+
if lawyer['site_link']:
|
1752 |
+
st.markdown(f"🌐 [Website]({lawyer['site_link']})")
|
1753 |
+
st.markdown("---")
|
1754 |
+
|
1755 |
+
# Show CSV preview with vertical and horizontal scrolling
|
1756 |
+
st.subheader("Data Preview")
|
1757 |
+
st.dataframe(
|
1758 |
+
df_lawyers,
|
1759 |
+
height=400,
|
1760 |
+
width=600,
|
1761 |
+
use_container_width=True,
|
1762 |
+
)
|
1763 |
+
|
1764 |
+
# Provide CSV download option
|
1765 |
+
csv = df_lawyers.to_csv(index=False)
|
1766 |
+
st.download_button(
|
1767 |
+
label="Download complete data as CSV",
|
1768 |
+
data=csv,
|
1769 |
+
file_name="lawyers_data.csv",
|
1770 |
+
mime="text/csv",
|
1771 |
+
)
|
1772 |
+
else:
|
1773 |
+
st.warning(f"No lawyers found in {city}, {state}. Try selecting a different city or state.")
|
1774 |
+
|
1775 |
# --- Streamlit App ---
|
1776 |
st.markdown("""
|
1777 |
<style>
|
|
|
1824 |
|
1825 |
feature = st.selectbox(
|
1826 |
"Select a feature",
|
1827 |
+
["Legal Chatbot", "Document Analysis", "Case Precedent Finder", "Legal Cost Estimator", "Contract Analysis", "Case Trend Visualizer", "Case Information Retrieval", "Automated Legal Brief Generation", "Find the Lawyers"]
|
1828 |
)
|
1829 |
if feature == "Legal Chatbot":
|
1830 |
st.subheader("Legal Chatbot")
|
|
|
1986 |
elif feature == "Automated Legal Brief Generation":
|
1987 |
automated_legal_brief_generation_ui()
|
1988 |
|
1989 |
+
elif feature == "Find the Lawyers":
|
1990 |
+
lawyer_finder_ui()
|
1991 |
+
|
1992 |
st.markdown("---")
|
1993 |
st.markdown(
|
1994 |
"""
|