File size: 1,111 Bytes
8d5bd60
83d25b7
5763b22
83d25b7
 
 
 
 
 
 
 
 
 
 
 
 
 
5763b22
83d25b7
 
 
 
 
 
 
 
 
 
 
 
 
c3b68a5
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
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


demo = gr.Interface(fn=search_legal_cases, inputs="text", outputs="markdown")
demo.launch()