Spaces:
Sleeping
Sleeping
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() | |