Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,57 @@
|
|
1 |
import gradio as gr
|
|
|
|
|
|
|
2 |
|
3 |
-
|
4 |
-
|
|
|
5 |
|
6 |
-
|
7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
from bs4 import BeautifulSoup
|
3 |
+
import requests
|
4 |
+
import os
|
5 |
|
6 |
+
headers = {
|
7 |
+
"User-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36 Edge/18.19582"
|
8 |
+
}
|
9 |
|
10 |
+
proxies = {"http": os.getenv("HTTP_PROXY")}
|
11 |
+
|
12 |
+
def search_legal_cases(query, num_results=10):
|
13 |
+
url = "https://scholar.google.com/scholar?hl=en&as_sdt=6"
|
14 |
+
headers = {
|
15 |
+
"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"
|
16 |
+
}
|
17 |
+
|
18 |
+
params = {
|
19 |
+
"q": query,
|
20 |
+
"hl": "en",
|
21 |
+
"num": num_results,
|
22 |
+
"as_sdt": "4", # This parameter filters the search results to legal cases
|
23 |
+
}
|
24 |
+
|
25 |
+
response = requests.get(url, proxies=proxies, headers=headers, params=params)
|
26 |
+
soup = BeautifulSoup(response.text, "html.parser")
|
27 |
+
|
28 |
+
results = []
|
29 |
+
for result in soup.find_all("div", class_="gs_ri"):
|
30 |
+
title = result.find("h3", class_="gs_rt").text
|
31 |
+
base_url = "https://scholar.google.com"
|
32 |
+
link = base_url + result.find("a")["href"]
|
33 |
+
citation = result.find("div", class_="gs_a").text.replace(" - Google Scholar", "")
|
34 |
+
results.append((title, link, citation))
|
35 |
+
|
36 |
+
return results
|
37 |
+
|
38 |
+
def main(search_query):
|
39 |
+
results = search_legal_cases(search_query)
|
40 |
+
if results:
|
41 |
+
title, link, citation = results[0]
|
42 |
+
return title, citation, link
|
43 |
+
else:
|
44 |
+
return "No results found."
|
45 |
+
|
46 |
+
def display_results(search_query):
|
47 |
+
title, citation, link = main(search_query)
|
48 |
+
return f"Title:\n{title}\n\nCitation:\n{citation}\n\nLink:\n{link}"
|
49 |
+
|
50 |
+
iface = gr.Interface(
|
51 |
+
fn=display_results,
|
52 |
+
inputs=gr.inputs.Textbox(lines=1, placeholder="Enter case name, e.g. brown v board supreme, 372 US 335, google v oracle appeal"),
|
53 |
+
outputs=gr.outputs.Textbox(label="Results"),
|
54 |
+
live=True
|
55 |
+
)
|
56 |
+
|
57 |
+
iface.launch()
|