legaltextai commited on
Commit
5763b22
1 Parent(s): 36dca75

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -25
app.py CHANGED
@@ -1,13 +1,6 @@
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"
@@ -22,7 +15,7 @@ def search_legal_cases(query, num_results=10):
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 = []
@@ -35,23 +28,15 @@ def search_legal_cases(query, num_results=10):
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()
 
1
  import gradio as gr
 
2
  import requests
3
+ from bs4 import BeautifulSoup
 
 
 
 
 
 
4
 
5
  def search_legal_cases(query, num_results=10):
6
  url = "https://scholar.google.com/scholar?hl=en&as_sdt=6"
 
15
  "as_sdt": "4", # This parameter filters the search results to legal cases
16
  }
17
 
18
+ response = requests.get(url, headers=headers, params=params)
19
  soup = BeautifulSoup(response.text, "html.parser")
20
 
21
  results = []
 
28
 
29
  return results
30
 
31
+ def get_legal_cases(query):
32
+ results = search_legal_cases(query)
33
  if results:
34
+ response = ""
35
+ for title, link, citation in results:
36
+ response += f"**Title:** {title}\n**Link:** {link}\n**Citation:** {citation}\n\n"
37
+ return response
38
  else:
39
  return "No results found."
40
 
41
+ demo = gr.Interface(fn=get_legal_cases, inputs="text", outputs="markdown")
42
+ demo.launch()