Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,84 +1,61 @@
|
|
1 |
import streamlit as st
|
2 |
-
from bs4 import BeautifulSoup
|
3 |
import requests
|
4 |
import os
|
5 |
-
import time
|
6 |
import google.generativeai as genai
|
7 |
|
8 |
-
genai.configure(api_key='
|
9 |
|
10 |
generation_config = {
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
}
|
17 |
|
18 |
-
@st.cache_data(ttl=3600)
|
19 |
-
def extract_text_from_api(query):
|
20 |
-
url = os.getenv('API_URL')
|
21 |
-
headers = {
|
22 |
-
"accept": "application/json"
|
23 |
-
}
|
24 |
-
|
25 |
-
params = {
|
26 |
-
"query": query,
|
27 |
-
"num_results": 1
|
28 |
|
29 |
-
|
30 |
-
|
31 |
-
|
|
|
32 |
|
33 |
-
|
34 |
-
|
|
|
35 |
return response.json().get("text", "")
|
36 |
-
|
|
|
37 |
return ""
|
38 |
-
|
39 |
-
|
40 |
-
#@st.cache_data(ttl=3600)
|
41 |
def get_summary(text):
|
42 |
model = genai.GenerativeModel('gemini-1.5-flash', generation_config=generation_config)
|
43 |
-
response = model.generate_content(f'''You are a law professor specialized in legal writing and legal research.
|
44 |
-
When presented with a case by a user please summarize it according to the following requirements:
|
45 |
-
Name of the court.
|
46 |
-
Facts (name of the parties, what happened factually).
|
47 |
-
Procedural history (what happened in the past procedurally, what were prior judgements).
|
48 |
-
Issues (what is in dispute).
|
49 |
-
Holding (the applied rule of law).
|
50 |
-
Rationale (reasons for the holding).
|
51 |
-
Decision (what did the court decide, e.g. affirmed, overruled).
|
52 |
-
Other opinions (if there are any dissenting or concurring opinions, summarize majority opinion, dissenting opinion and concurring opinion).
|
53 |
-
Cases cited (which cases the court cited and how it treated them).
|
54 |
-
Here is the text of the court decision: {text}''',
|
55 |
-
stream=False)
|
56 |
-
return response
|
57 |
|
58 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
59 |
|
|
|
60 |
|
61 |
with tab1:
|
62 |
-
st.write("\n")
|
63 |
-
st.
|
64 |
-
search_query = st.text_input("case name, e.g. brown v board supreme, 372 US 335, google v oracle appeal")
|
65 |
|
66 |
if search_query:
|
67 |
with st.spinner("Searching for cases..."):
|
68 |
text = extract_text_from_api(search_query)
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
# print("_"*80)
|
77 |
-
# #st.write(summary)
|
78 |
-
# #for chunk in summary:
|
79 |
-
# #st.write(chunk.text)
|
80 |
-
# #st.write("_"*80)
|
81 |
-
|
82 |
-
|
83 |
else:
|
84 |
-
st.write("
|
|
|
1 |
import streamlit as st
|
|
|
2 |
import requests
|
3 |
import os
|
|
|
4 |
import google.generativeai as genai
|
5 |
|
6 |
+
genai.configure(api_key=os.getenv('GOOGLE_API_KEY'))
|
7 |
|
8 |
generation_config = {
|
9 |
+
"temperature": 0,
|
10 |
+
"top_p": 0.95,
|
11 |
+
"top_k": 64,
|
12 |
+
"max_output_tokens": 8192,
|
13 |
+
"response_mime_type": "text/plain",
|
14 |
}
|
15 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
|
17 |
+
@st.cache_data(ttl=3600)
|
18 |
+
def extract_text_from_api(query):
|
19 |
+
api_url = "https://urchin-app-c3zop.ondigitalocean.app/extract_text"
|
20 |
+
params = {"query": query, "num_results": 1}
|
21 |
|
22 |
+
try:
|
23 |
+
response = requests.get(api_url, params=params)
|
24 |
+
response.raise_for_status()
|
25 |
return response.json().get("text", "")
|
26 |
+
except requests.exceptions.RequestException as e:
|
27 |
+
st.error(f"Error fetching case data: {e}")
|
28 |
return ""
|
29 |
+
|
30 |
+
@st.cache_data(ttl=3600)
|
|
|
31 |
def get_summary(text):
|
32 |
model = genai.GenerativeModel('gemini-1.5-flash', generation_config=generation_config)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
|
34 |
+
try:
|
35 |
+
response = model.generate_content(
|
36 |
+
f"""You are a law professor... Here is the text of the court decision: {text}""",
|
37 |
+
stream=False
|
38 |
+
)
|
39 |
+
return response
|
40 |
+
except Exception as e:
|
41 |
+
st.error(f"Error generating summary: {e}")
|
42 |
+
return ""
|
43 |
|
44 |
+
tab1, tab2, tab3 = st.tabs(["Summarize a case", "Find a case by facts", "Analyze a court brief"])
|
45 |
|
46 |
with tab1:
|
47 |
+
st.write("\n\n")
|
48 |
+
search_query = st.text_input("Case name, e.g., brown v board supreme, 372 US 335, google v oracle appeal")
|
|
|
49 |
|
50 |
if search_query:
|
51 |
with st.spinner("Searching for cases..."):
|
52 |
text = extract_text_from_api(search_query)
|
53 |
+
if text:
|
54 |
+
st.write(text)
|
55 |
+
summary = get_summary(text)
|
56 |
+
if summary:
|
57 |
+
st.write(summary.text)
|
58 |
+
else:
|
59 |
+
st.write("No case text found.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
60 |
else:
|
61 |
+
st.write("Enter a case name to begin.")
|