Spaces:
Build error
Build error
Update app.py
Browse files
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 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
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 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
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.")
|