Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,16 +1,15 @@
|
|
1 |
-
import os
|
2 |
import streamlit as st
|
3 |
from sentence_transformers import SentenceTransformer
|
4 |
-
from
|
5 |
from langchain.vectorstores import FAISS
|
6 |
from transformers import pipeline
|
7 |
from datasets import load_dataset
|
8 |
import torch
|
9 |
|
10 |
-
# Set up the page configuration
|
11 |
-
st.set_page_config(page_title="
|
12 |
|
13 |
-
# Load
|
14 |
@st.cache_resource
|
15 |
def load_summarization_pipeline():
|
16 |
summarizer = pipeline("summarization", model="facebook/bart-large-cnn") # Use a summarization model
|
@@ -33,14 +32,18 @@ def get_text_chunks(text):
|
|
33 |
return chunks
|
34 |
|
35 |
# Initialize embedding model
|
36 |
-
|
|
|
|
|
|
|
|
|
|
|
37 |
|
38 |
# Create a FAISS vector store with embeddings
|
39 |
@st.cache_resource
|
40 |
def load_or_create_vector_store(text_chunks):
|
41 |
-
|
42 |
-
|
43 |
-
vector_store = FAISS.from_texts(text_chunks, embedding=embedding_function)
|
44 |
return vector_store
|
45 |
|
46 |
# Generate summary based on the retrieved text
|
|
|
|
|
1 |
import streamlit as st
|
2 |
from sentence_transformers import SentenceTransformer
|
3 |
+
from langchain.text_splitters import RecursiveCharacterTextSplitter
|
4 |
from langchain.vectorstores import FAISS
|
5 |
from transformers import pipeline
|
6 |
from datasets import load_dataset
|
7 |
import torch
|
8 |
|
9 |
+
# Set up the Streamlit page configuration
|
10 |
+
st.set_page_config(page_title="Gen AI Lawyers Guide", layout="centered", page_icon="π")
|
11 |
|
12 |
+
# Load summarization pipeline model
|
13 |
@st.cache_resource
|
14 |
def load_summarization_pipeline():
|
15 |
summarizer = pipeline("summarization", model="facebook/bart-large-cnn") # Use a summarization model
|
|
|
32 |
return chunks
|
33 |
|
34 |
# Initialize embedding model
|
35 |
+
@st.cache_resource
|
36 |
+
def load_embedding_model():
|
37 |
+
model = SentenceTransformer("sentence-transformers/all-MiniLM-L6-v2")
|
38 |
+
return model
|
39 |
+
|
40 |
+
embedding_model = load_embedding_model()
|
41 |
|
42 |
# Create a FAISS vector store with embeddings
|
43 |
@st.cache_resource
|
44 |
def load_or_create_vector_store(text_chunks):
|
45 |
+
embeddings = [embedding_model.encode(text) for text in text_chunks]
|
46 |
+
vector_store = FAISS.from_embeddings(embeddings, text_chunks) # FAISS setup with embeddings
|
|
|
47 |
return vector_store
|
48 |
|
49 |
# Generate summary based on the retrieved text
|