File size: 3,123 Bytes
ae8ef07
 
 
ebc5123
f11b181
ebc5123
f843a8b
ebc5123
 
f843a8b
 
 
 
 
ebc5123
 
f843a8b
 
 
 
5a1598d
f843a8b
 
 
5a1598d
f843a8b
 
5a1598d
f843a8b
 
ae8ef07
8266583
75b899e
 
 
 
 
 
5a1598d
f843a8b
1f2bb4b
 
a4bb912
1f2bb4b
 
 
 
 
 
 
 
 
 
75b899e
f843a8b
 
 
 
 
8f06d53
f843a8b
5a1598d
 
f843a8b
 
5a1598d
 
 
788e804
fe92007
f843a8b
400a1da
f843a8b
8266583
f843a8b
 
 
7fb0d7c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import streamlit as st
import requests
import os
import google.generativeai as genai
from google.generativeai.types import HarmCategory, HarmBlockThreshold

genai.configure(api_key=os.getenv('GOOGLE_API_KEY'))  

generation_config = {
    "temperature": 0,
    "top_p": 0.95,
    "top_k": 64,
    "max_output_tokens": 8192, 
    "response_mime_type": "text/plain", 
}

@st.cache_data(ttl=3600) 
def extract_text_from_api(query):
    api_url = "https://urchin-app-c3zop.ondigitalocean.app/extract_text" 
    params = {"query": query, "num_results": 1}

    try:
        response = requests.get(api_url, params=params)
        response.raise_for_status()  
        return response.json().get("text", "")
    except requests.exceptions.RequestException as e:
        st.error(f"Error fetching case data: {e}")  
        return ""
        
@st.cache_data(ttl=3600) 
def get_summary(text):
    model = genai.GenerativeModel('gemini-1.5-flash', generation_config=generation_config, 
                                  safety_settings = {
        'HATE': 'BLOCK_NONE',
        'HARASSMENT': 'BLOCK_NONE',
        'SEXUAL' : 'BLOCK_NONE',
        'DANGEROUS' : 'BLOCK_NONE'
            })
    
    try:
        response = model.generate_content(f'''You are a law professor specialized in legal writing and legal research. 
                   When presented with a case by a user please summarize it according to the following requirements:
                   Name of the case and its proper citation.
                   Name of the court.
                   Facts (name of the parties, what happened factually).
                   Procedural history (what happened in the past procedurally, what were prior judgements). 
                   Issues (what is in dispute).
                   Holding (the applied rule of law). 
                   Rationale (reasons for the holding).
                   Decision (what did the court decide, e.g. affirmed, overruled).
                   Other opinions (if there are any dissenting or concurring opinions, summarize majority opinion, dissenting opinion and concurring opinion).
                   Cases cited (which cases the court cited and how it treated them).
                   Here is the text of the case to be summarized: {text}''',
            stream=False
        )
        return response 
    except Exception as e:
        st.error(f"Error generating summary: {e}")  
        return ""

tab1, tab2, tab3 = st.tabs(["Summarize a case", "Find a case by facts", "Analyze a court brief"])

with tab1:
    st.write("\n\n")  
    search_query = st.text_input("Case name, e.g., brown v board supreme, 372 US 335, google v oracle appeal")
    
    if search_query:
        with st.spinner("Searching for cases..."):
            text = extract_text_from_api(search_query)
            
            if text: 
                #st.write(text) 
                summary = get_summary(text)
                st.write(summary.candidates[0].safety_ratings)
                if summary:
                    st.write(summary.text) 
            else:
                st.write("No case text found.")