Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,24 +1,20 @@
|
|
1 |
-
|
2 |
import os
|
3 |
from PyPDF2 import PdfReader
|
4 |
from langchain.text_splitter import RecursiveCharacterTextSplitter
|
5 |
-
from
|
6 |
-
from transformers import pipeline
|
7 |
import streamlit as st
|
8 |
import requests
|
9 |
from io import BytesIO
|
|
|
10 |
|
11 |
-
#
|
12 |
-
|
13 |
-
|
14 |
-
# Replace `HF_TOKEN` in the pipeline instantiation directly with your token string (for testing purposes only).
|
15 |
-
pipe = pipeline("text-generation", model="meta-llama/Llama-Guard-3-8B-INT8", use_auth_token="HF_TOKEN")
|
16 |
-
|
17 |
|
18 |
# List of GitHub PDF URLs
|
19 |
PDF_URLS = [
|
20 |
-
"https://github.com/TahirSher/GenAI_Lawyers_Guide/blob/main/bi%20pat%20graphs.pdf",
|
21 |
"https://github.com/TahirSher/GenAI_Lawyers_Guide/blob/main/bi-partite.pdf",
|
|
|
22 |
# Add more document links as needed
|
23 |
]
|
24 |
|
@@ -49,19 +45,20 @@ def load_or_create_vector_store(text_chunks):
|
|
49 |
vector_store = FAISS.from_texts(text_chunks, embedding=embeddings)
|
50 |
return vector_store
|
51 |
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
|
|
60 |
|
61 |
def user_input(user_question, vector_store):
|
62 |
docs = vector_store.similarity_search(user_question)
|
63 |
context_text = " ".join([doc.page_content for doc in docs])
|
64 |
-
return
|
65 |
|
66 |
def main():
|
67 |
st.set_page_config(page_title="RAG-based PDF Chat", layout="centered", page_icon="π")
|
|
|
|
|
1 |
import os
|
2 |
from PyPDF2 import PdfReader
|
3 |
from langchain.text_splitter import RecursiveCharacterTextSplitter
|
4 |
+
from langchain_community.vectorstores import FAISS
|
|
|
5 |
import streamlit as st
|
6 |
import requests
|
7 |
from io import BytesIO
|
8 |
+
import groq.client as client # Ensure Groq client is properly installed
|
9 |
|
10 |
+
# Set up Groq API key
|
11 |
+
GROQ_API_KEY = os.getenv("Groq_Api_Key")
|
12 |
+
client.configure(api_key=GROQ_API_KEY)
|
|
|
|
|
|
|
13 |
|
14 |
# List of GitHub PDF URLs
|
15 |
PDF_URLS = [
|
|
|
16 |
"https://github.com/TahirSher/GenAI_Lawyers_Guide/blob/main/bi-partite.pdf",
|
17 |
+
"https://github.com/TahirSher/GenAI_Lawyers_Guide/blob/main/bi%20pat%20graphs.pdf",
|
18 |
# Add more document links as needed
|
19 |
]
|
20 |
|
|
|
45 |
vector_store = FAISS.from_texts(text_chunks, embedding=embeddings)
|
46 |
return vector_store
|
47 |
|
48 |
+
# Call Groq API for generating summary based on the query and retrieved text
|
49 |
+
def generate_summary_with_groq(query, retrieved_text):
|
50 |
+
chat_completion = client.chat.completions.create(
|
51 |
+
messages=[
|
52 |
+
{"role": "user", "content": f"{query}\n\nRelated information:\n{retrieved_text}"}
|
53 |
+
],
|
54 |
+
model="llama3-8b-8192",
|
55 |
+
)
|
56 |
+
return chat_completion.choices[0].message.content
|
57 |
|
58 |
def user_input(user_question, vector_store):
|
59 |
docs = vector_store.similarity_search(user_question)
|
60 |
context_text = " ".join([doc.page_content for doc in docs])
|
61 |
+
return generate_summary_with_groq(user_question, context_text)
|
62 |
|
63 |
def main():
|
64 |
st.set_page_config(page_title="RAG-based PDF Chat", layout="centered", page_icon="π")
|