Spaces:
Sleeping
Sleeping
File size: 1,423 Bytes
8d5bd60 83d25b7 5763b22 83d25b7 5763b22 83d25b7 9be4834 83d25b7 9be4834 5763b22 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
import gradio as gr
import requests
from bs4 import BeautifulSoup
def search_legal_cases(query, num_results=10):
url = "https://scholar.google.com/scholar?hl=en&as_sdt=6"
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.63 Safari/537.3"
}
params = {
"q": query,
"hl": "en",
"num": num_results,
"as_sdt": "4", # This parameter filters the search results to legal cases
}
response = requests.get(url, headers=headers, params=params)
soup = BeautifulSoup(response.text, "html.parser")
results = []
for result in soup.find_all("div", class_="gs_ri"):
title = result.find("h3", class_="gs_rt").text
base_url = "https://scholar.google.com"
link = base_url + result.find("a")["href"]
citation = result.find("div", class_="gs_a").text.replace(" - Google Scholar", "")
results.append((title, link, citation))
return results
def get_legal_cases(query):
results = search_legal_cases(query)
if results:
response = ""
for title, link, citation in results:
response += f"**Title:** {title}\n**Link:** {link}\n**Citation:** {citation}\n\n"
return response
else:
return "No results found."
demo = gr.Interface(fn=get_legal_cases, inputs="text", outputs="markdown")
demo.launch()
|