import streamlit as st from bs4 import BeautifulSoup import requests import os import time import google.generativeai as genai genai.configure(api_key='AIzaSyBE9XAwJiAs6xY2UukvGYsy0ghtxA1F2q8') 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): url = os.getenv('API_URL') headers = { "accept": "application/json" } params = { "query": query, "num_results": 1 } response = requests.get(url, params=params) if response.status_code == 200: return response.json().get("text", "") else: return "" @st.cache_data(ttl=3600) def get_summary(text): model = genai.GenerativeModel('gemini-1.5-flash', generation_config=generation_config) 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 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 court decision: {text}''', stream=False) return response tab1, tab2, tab3 = st.tabs(["Summarize a case", "Find a case by facts", "Analyze a court brief"]) with tab1: st.write("\n") st.write("\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) summary = get_summary(text) #st.write(response) st.write(summary.text) #for chunk in summary: #st.write(chunk.text) #st.write("_"*80) else: st.write("No results found.")