File size: 3,350 Bytes
0332334
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import os
from groq import Groq
import streamlit as st
import pandas as pd

# Set your Groq API key
os.environ["GROQ_API_KEY"] = "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"
client = Groq(api_key=os.environ.get("GROQ_API_KEY"))

# Create a mock dataset with more relevant cases
mock_data = [
    {
        "case_title": "Smith v. Jones",
        "summary": "A landmark case that established the principle of duty of care.",
    },
    {
        "case_title": "Doe v. United States",
        "summary": "This case addressed issues related to search and seizure under the Fourth Amendment.",
    },
    {
        "case_title": "Roe v. Wade",
        "summary": "A pivotal Supreme Court case that legalized abortion in the United States.",
    },
    {
        "case_title": "Brown v. Board of Education",
        "summary": "A landmark decision that declared racial segregation in public schools unconstitutional.",
    },
    {
        "case_title": "Loving v. Virginia",
        "summary": "This case struck down laws banning interracial marriage, addressing civil rights.",
    },
    {
        "case_title": "Miranda v. Arizona",
        "summary": "This case established Miranda rights and protections under the Fifth Amendment.",
    },
    {
        "case_title": "Griswold v. Connecticut",
        "summary": "A case that recognized the right to privacy in marital relations and contraceptive use.",
    },
    {
        "case_title": "Tinker v. Des Moines",
        "summary": "A case that affirmed students' rights to free speech in public schools.",
    },
    {
        "case_title": "Furman v. Georgia",
        "summary": "A significant case regarding the death penalty and its application, addressing criminal law.",
    },
    {
        "case_title": "Obergefell v. Hodges",
        "summary": "This case legalized same-sex marriage across the United States, highlighting equal protection.",
    },
]

# Convert mock data to DataFrame for easy querying
mock_df = pd.DataFrame(mock_data)

def get_case_summary(user_query):
    # Search for relevant cases in the mock dataset
    relevant_cases = mock_df[mock_df['case_title'].str.contains(user_query, case=False) | 
                              mock_df['summary'].str.contains(user_query, case=False)]
    
    if not relevant_cases.empty:
        # Take the first relevant case for simplicity
        case_info = relevant_cases.iloc[0]
        case_title = case_info['case_title']
        case_summary = case_info['summary']
        
        # Generate a response using the Groq API
        chat_completion = client.chat.completions.create(
            messages=[
                {
                    "role": "user",
                    "content": f"Provide a detailed summary of the following case: {case_title}. Summary: {case_summary}",
                }
            ],
            model="llama3-8b-8192",
        )
        
        return chat_completion.choices[0].message.content
    else:
        return "No relevant cases found."

# Streamlit application
st.title("Legal Research Assistant")

# User input
user_query = st.text_input("Enter a case title or keyword:")

if st.button("Get Case Summary"):
    if user_query:
        summary = get_case_summary(user_query)
        st.write(summary)
    else:
        st.write("Please enter a case title or keyword.")