Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -45,15 +45,21 @@ def create_vector_store(chunks):
|
|
| 45 |
embeddings = HuggingFaceEmbeddings(model_name="all-MiniLM-L6-v2")
|
| 46 |
return FAISS.from_documents(documents, embeddings)
|
| 47 |
|
| 48 |
-
def
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
|
| 58 |
def ask_question(vectorstore, question):
|
| 59 |
docs = vectorstore.similarity_search(question, k=3)
|
|
@@ -98,7 +104,7 @@ if uploaded_files:
|
|
| 98 |
vectorstore = create_vector_store(chunks)
|
| 99 |
|
| 100 |
st.write("📄 Generating summary...")
|
| 101 |
-
summary =
|
| 102 |
st.success(summary)
|
| 103 |
make_download_button(summary)
|
| 104 |
|
|
|
|
| 45 |
embeddings = HuggingFaceEmbeddings(model_name="all-MiniLM-L6-v2")
|
| 46 |
return FAISS.from_documents(documents, embeddings)
|
| 47 |
|
| 48 |
+
def summarize_chunks(chunks):
|
| 49 |
+
chunk_summaries = []
|
| 50 |
+
for i, chunk in enumerate(chunks):
|
| 51 |
+
try:
|
| 52 |
+
response = client.chat.completions.create(
|
| 53 |
+
model=GROQ_MODEL,
|
| 54 |
+
messages=[
|
| 55 |
+
{"role": "system", "content": "You are an AI that summarizes documents."},
|
| 56 |
+
{"role": "user", "content": f"Summarize this chunk:\n{chunk}"}
|
| 57 |
+
]
|
| 58 |
+
)
|
| 59 |
+
chunk_summaries.append(response.choices[0].message.content)
|
| 60 |
+
except Exception as e:
|
| 61 |
+
chunk_summaries.append(f"[Error summarizing chunk {i}]: {str(e)}")
|
| 62 |
+
return "\n".join(chunk_summaries)
|
| 63 |
|
| 64 |
def ask_question(vectorstore, question):
|
| 65 |
docs = vectorstore.similarity_search(question, k=3)
|
|
|
|
| 104 |
vectorstore = create_vector_store(chunks)
|
| 105 |
|
| 106 |
st.write("📄 Generating summary...")
|
| 107 |
+
summary = summarize_chunks(chunks)
|
| 108 |
st.success(summary)
|
| 109 |
make_download_button(summary)
|
| 110 |
|