rehanafzal commited on
Commit
6fa9bc0
·
verified ·
1 Parent(s): 390829c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +1 -95
app.py CHANGED
@@ -1,98 +1,4 @@
1
- # import os
2
- # from groq import Groq
3
- # from langchain_community.embeddings import HuggingFaceEmbeddings
4
- # from langchain_community.vectorstores import FAISS
5
- # from langchain.text_splitter import RecursiveCharacterTextSplitter
6
- # from PyPDF2 import PdfReader
7
- # import streamlit as st
8
- # from tempfile import NamedTemporaryFile
9
-
10
- # # Initialize Groq client
11
- # client = Groq(api_key=os.getenv("Groq_api_key"))
12
- # # client = Groq(api_key=os.environ.get("GROQ_API_KEY"))
13
-
14
- # # Function to extract text from a PDF
15
- # def extract_text_from_pdf(pdf_file_path):
16
- # pdf_reader = PdfReader(pdf_file_path)
17
- # text = ""
18
- # for page in pdf_reader.pages:
19
- # text += page.extract_text()
20
- # return text
21
-
22
- # # Function to split text into chunks
23
- # def chunk_text(text, chunk_size=500, chunk_overlap=50):
24
- # text_splitter = RecursiveCharacterTextSplitter(
25
- # chunk_size=chunk_size, chunk_overlap=chunk_overlap
26
- # )
27
- # return text_splitter.split_text(text)
28
-
29
- # # Function to create embeddings and store them in FAISS
30
- # def create_embeddings_and_store(chunks):
31
- # embeddings = HuggingFaceEmbeddings(model_name="sentence-transformers/all-MiniLM-L6-v2")
32
- # vector_db = FAISS.from_texts(chunks, embedding=embeddings)
33
- # return vector_db
34
-
35
- # # Function to query the vector database and interact with Groq
36
- # def query_vector_db(query, vector_db):
37
- # # Retrieve relevant documents
38
- # docs = vector_db.similarity_search(query, k=3)
39
- # context = "\n".join([doc.page_content for doc in docs])
40
-
41
- # # Interact with Groq API
42
- # chat_completion = client.chat.completions.create(
43
- # messages=[
44
- # {"role": "system", "content": f"Use the following context:\n{context}"},
45
- # {"role": "user", "content": query},
46
- # ],
47
- # model="llama3-8b-8192",
48
- # )
49
- # return chat_completion.choices[0].message.content
50
-
51
- # # Streamlit app
52
- # st.title("Interactive PDF Reader and Chat")
53
-
54
- # # Upload PDF
55
- # uploaded_file = st.file_uploader("Upload a PDF document", type=["pdf"])
56
-
57
- # if uploaded_file:
58
- # with NamedTemporaryFile(delete=False, suffix=".pdf") as temp_file:
59
- # temp_file.write(uploaded_file.read())
60
- # pdf_path = temp_file.name
61
-
62
- # # Extract text, chunk it, and create embeddings
63
- # text = extract_text_from_pdf(pdf_path)
64
- # chunks = chunk_text(text)
65
- # vector_db = create_embeddings_and_store(chunks)
66
-
67
- # # State management for the chat
68
- # if "chat_history" not in st.session_state:
69
- # st.session_state.chat_history = []
70
-
71
- # # Display chat history
72
- # for i, chat in enumerate(st.session_state.chat_history):
73
- # st.write(f"**Query {i+1}:** {chat['query']}")
74
- # st.write(f"**Response:** {chat['response']}")
75
- # st.write("---")
76
-
77
- # # Add new query input dynamically
78
- # if "query_count" not in st.session_state:
79
- # st.session_state.query_count = 1
80
-
81
- # query_key = f"query_{st.session_state.query_count}"
82
- # user_query = st.text_input(f"Enter Query {st.session_state.query_count}:", key=query_key)
83
-
84
- # if user_query:
85
- # # Generate response
86
- # response = query_vector_db(user_query, vector_db)
87
-
88
- # # Append query and response to the chat history
89
- # st.session_state.chat_history.append({"query": user_query, "response": response})
90
-
91
- # # Increment query count for the next input box
92
- # st.session_state.query_count += 1
93
-
94
- # # Rerun to show the updated UI
95
- # st.experimental_rerun()
96
 
97
  import os
98
  from groq import Groq
 
1
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
 
3
  import os
4
  from groq import Groq