legaltextai commited on
Commit
8f06d53
·
verified ·
1 Parent(s): 31b135f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -44
app.py CHANGED
@@ -2,15 +2,8 @@ import streamlit as st
2
  from bs4 import BeautifulSoup
3
  import requests
4
  import os
5
- import anthropic
6
- from anthropic import Anthropic, HUMAN_PROMPT, AI_PROMPT
7
- from io import StringIO, BytesIO
8
  import time
9
-
10
-
11
- client = anthropic.Anthropic(
12
- api_key="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",
13
- )
14
 
15
 
16
  headers = {
@@ -20,6 +13,7 @@ headers = {
20
  proxies = {"http": os.getenv("HTTP_PROXY")}
21
 
22
 
 
23
  @st.cache_data(ttl=3600)
24
  def search_legal_cases(query, num_results=10):
25
  url = "https://scholar.google.com/scholar?hl=en&as_sdt=6"
@@ -62,33 +56,28 @@ def extract_text_from_link(url):
62
 
63
  @st.cache_data(ttl=3600)
64
  def get_summary(text):
65
- message = client.messages.create(
66
- model="claude-3-opus-20240229",
67
- max_tokens_to_sample=2000,
68
- messages=[
69
- {
70
- "role": "user",
71
- "content": f'''
72
- You are a law professor specialized in legal writing and legal research.
73
- Summarize the case in {text} in json format according to the following requirements:
74
- Facts (name of the case and its parties, what happened factually).
75
- Procedural history (what happened in the past procedurally, what were prior judgements).
76
- Issues (what is in dispute).
77
- Holding (the applied rule of law).
78
- Rationale (reasons for the holding).
79
- Decision (what did the court decide, e.g. affirmed, overruled).
80
- Other opinions (if there are any dissenting or concurring opinions, summarize majority opinion, dissenting opinion and concurring opinion).
81
- Cases cited (which cases the court cited and how it treated them):
82
- - 'red flag' means some negative treatment — such as a cited case is being overruled, superseded, or not followed by this court for some reason.
83
- - 'yellow flag' means the case has some negative treatment by this court but has not been reversed or overruled. For example, the reasoning of the decision was criticized or its holding was limited to a specific set of facts.
84
- - 'blue flag' means the case has been appealed to the U.S. Court of Appeals or the U.S. Supreme Court (excluding appeals originating from agencies).
85
-
86
- Present the summary in json format.
87
- '''
88
- }
89
- ]
90
- )
91
- return message.content
92
 
93
  st.write("\n")
94
  st.write("\n")
@@ -102,15 +91,12 @@ if search_query:
102
  st.write("Title:\n", title)
103
  #st.write("Link:\n", link)
104
  st.write("Citation:\n", citation)
105
- with st.spinner("Extracting text from case..."):
106
- text = extract_text_from_link(link)
107
- st.write(text) # Optionally display the extracted text
108
- with st.spinner("Generating summary..."):
109
- summary = get_summary(text)
110
  st.write(summary)
111
 
112
- # Convert the response to a file-like object for download
113
- download_bytes = BytesIO(summary.encode())
114
- st.download_button("Download the results", download_bytes, "summary.txt", "text/plain")
115
  else:
116
- st.write("No results found.")
 
2
  from bs4 import BeautifulSoup
3
  import requests
4
  import os
 
 
 
5
  import time
6
+ from openai import OpenAI
 
 
 
 
7
 
8
 
9
  headers = {
 
13
  proxies = {"http": os.getenv("HTTP_PROXY")}
14
 
15
 
16
+
17
  @st.cache_data(ttl=3600)
18
  def search_legal_cases(query, num_results=10):
19
  url = "https://scholar.google.com/scholar?hl=en&as_sdt=6"
 
56
 
57
  @st.cache_data(ttl=3600)
58
  def get_summary(text):
59
+ client = OpenAI(api_key='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')
60
+
61
+ completion = client.chat.completions.create(
62
+ model="gpt-4o",
63
+ messages=[
64
+ {"role": "system", "content": f'''You are a law professor specialized in legal writing and legal research.
65
+ When presented with a case by a user please summarize it according to the following requirements:
66
+ Name of the court.
67
+ Facts (name of the parties, what happened factually).
68
+ Procedural history (what happened in the past procedurally, what were prior judgements).
69
+ Issues (what is in dispute).
70
+ Holding (the applied rule of law).
71
+ Rationale (reasons for the holding).
72
+ Decision (what did the court decide, e.g. affirmed, overruled).
73
+ Other opinions (if there are any dissenting or concurring opinions, summarize majority opinion, dissenting opinion and concurring opinion).
74
+ Cases cited (which cases the court cited and how it treated them)'''},
75
+ {"role": "user", "content": f"Summarize this case: {text}!"}
76
+ ]
77
+ )
78
+
79
+ return completion.choices[0].message.content
80
+
 
 
 
 
 
81
 
82
  st.write("\n")
83
  st.write("\n")
 
91
  st.write("Title:\n", title)
92
  #st.write("Link:\n", link)
93
  st.write("Citation:\n", citation)
94
+ #with st.spinner("Extracting text from case / Generating summary"):
95
+ text = extract_text_from_link(link)
96
+ #st.write(text) # Optionally display the extracted text
97
+
98
+ summary = get_summary(text)
99
  st.write(summary)
100
 
 
 
 
101
  else:
102
+ st.write("No results found.")