Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,15 +5,14 @@ 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 |
|
| 13 |
# List of GitHub PDF URLs
|
| 14 |
PDF_URLS = [
|
| 15 |
-
"https://github.com/TahirSher/GenAI_Lawyers_Guide/blob/main/bi-partite.pdf",
|
| 16 |
"https://github.com/TahirSher/GenAI_Lawyers_Guide/blob/main/bi%20pat%20graphs.pdf",
|
|
|
|
| 17 |
# Add more document links as needed
|
| 18 |
]
|
| 19 |
|
|
@@ -46,13 +45,23 @@ def load_or_create_vector_store(text_chunks):
|
|
| 46 |
|
| 47 |
# Call Groq API for generating summary based on the query and retrieved text
|
| 48 |
def generate_summary_with_groq(query, retrieved_text):
|
| 49 |
-
|
| 50 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
{"role": "user", "content": f"{query}\n\nRelated information:\n{retrieved_text}"}
|
| 52 |
],
|
| 53 |
-
model
|
| 54 |
-
|
| 55 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
|
| 57 |
def user_input(user_question, vector_store):
|
| 58 |
docs = vector_store.similarity_search(user_question)
|
|
|
|
| 5 |
import streamlit as st
|
| 6 |
import requests
|
| 7 |
from io import BytesIO
|
|
|
|
| 8 |
|
| 9 |
# Set up Groq API key
|
| 10 |
GROQ_API_KEY = os.getenv("GROQ_Api_Key")
|
| 11 |
|
| 12 |
# List of GitHub PDF URLs
|
| 13 |
PDF_URLS = [
|
|
|
|
| 14 |
"https://github.com/TahirSher/GenAI_Lawyers_Guide/blob/main/bi%20pat%20graphs.pdf",
|
| 15 |
+
"https://github.com/TahirSher/GenAI_Lawyers_Guide/blob/main/bi-partite.pdf",
|
| 16 |
# Add more document links as needed
|
| 17 |
]
|
| 18 |
|
|
|
|
| 45 |
|
| 46 |
# Call Groq API for generating summary based on the query and retrieved text
|
| 47 |
def generate_summary_with_groq(query, retrieved_text):
|
| 48 |
+
url = "https://api.groq.com/v1/chat/completions" # Update with actual Groq API endpoint
|
| 49 |
+
headers = {
|
| 50 |
+
"Authorization": f"Bearer {GROQ_API_KEY}",
|
| 51 |
+
"Content-Type": "application/json"
|
| 52 |
+
}
|
| 53 |
+
payload = {
|
| 54 |
+
"messages": [
|
| 55 |
{"role": "user", "content": f"{query}\n\nRelated information:\n{retrieved_text}"}
|
| 56 |
],
|
| 57 |
+
"model": "llama3-8b-8192",
|
| 58 |
+
}
|
| 59 |
+
response = requests.post(url, headers=headers, json=payload)
|
| 60 |
+
if response.status_code == 200:
|
| 61 |
+
return response.json()["choices"][0]["message"]["content"]
|
| 62 |
+
else:
|
| 63 |
+
st.error("Failed to generate summary with Groq API")
|
| 64 |
+
return "Error in Groq API response"
|
| 65 |
|
| 66 |
def user_input(user_question, vector_store):
|
| 67 |
docs = vector_store.similarity_search(user_question)
|