Update app.py
Browse files
app.py
CHANGED
|
@@ -14,27 +14,11 @@ import time
|
|
| 14 |
huggingfacehub_api_token = os.getenv("HUGGINGFACEHUB_API_TOKEN")
|
| 15 |
groq_api_key = os.getenv("GROQ_API_KEY")
|
| 16 |
|
| 17 |
-
# Debugging: Print the API keys to ensure they are being retrieved (remove these prints in production)
|
| 18 |
-
st.write("Hugging Face Hub API Token:", huggingfacehub_api_token)
|
| 19 |
-
st.write("GROQ API Key:", groq_api_key)
|
| 20 |
-
|
| 21 |
-
# Check if the keys are retrieved correctly
|
| 22 |
-
if not huggingfacehub_api_token:
|
| 23 |
-
st.error("HUGGINGFACEHUB_API_TOKEN environment variable is not set")
|
| 24 |
-
st.stop()
|
| 25 |
-
if not groq_api_key:
|
| 26 |
-
st.error("GROQ_API_KEY environment variable is not set")
|
| 27 |
-
st.stop()
|
| 28 |
-
|
| 29 |
# Set environment variables for Hugging Face
|
| 30 |
os.environ['HUGGINGFACEHUB_API_TOKEN'] = huggingfacehub_api_token
|
| 31 |
|
| 32 |
# Initialize the ChatGroq LLM with the retrieved API key
|
| 33 |
-
|
| 34 |
-
llm = ChatGroq(api_key=groq_api_key, model_name="Llama3-8b-8192")
|
| 35 |
-
except Exception as e:
|
| 36 |
-
st.error(f"Failed to initialize ChatGroq LLM: {e}")
|
| 37 |
-
st.stop()
|
| 38 |
|
| 39 |
st.title("DataScience Chatgroq With Llama3")
|
| 40 |
|
|
@@ -68,15 +52,12 @@ if prompt1:
|
|
| 68 |
document_chain = create_stuff_documents_chain(llm, prompt)
|
| 69 |
retriever = st.session_state.vectors.as_retriever()
|
| 70 |
retrieval_chain = create_retrieval_chain(retriever, document_chain)
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
st.write("--------------------------------")
|
| 81 |
-
except Exception as e:
|
| 82 |
-
st.error(f"Failed to retrieve the answer: {e}")
|
|
|
|
| 14 |
huggingfacehub_api_token = os.getenv("HUGGINGFACEHUB_API_TOKEN")
|
| 15 |
groq_api_key = os.getenv("GROQ_API_KEY")
|
| 16 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
# Set environment variables for Hugging Face
|
| 18 |
os.environ['HUGGINGFACEHUB_API_TOKEN'] = huggingfacehub_api_token
|
| 19 |
|
| 20 |
# Initialize the ChatGroq LLM with the retrieved API key
|
| 21 |
+
llm = ChatGroq(api_key=groq_api_key, model_name="Llama3-8b-8192")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
st.title("DataScience Chatgroq With Llama3")
|
| 24 |
|
|
|
|
| 52 |
document_chain = create_stuff_documents_chain(llm, prompt)
|
| 53 |
retriever = st.session_state.vectors.as_retriever()
|
| 54 |
retrieval_chain = create_retrieval_chain(retriever, document_chain)
|
| 55 |
+
start = time.process_time()
|
| 56 |
+
response = retrieval_chain.invoke({'input': prompt1})
|
| 57 |
+
st.write("Response time: ", time.process_time() - start)
|
| 58 |
+
st.write(response['answer'])
|
| 59 |
+
|
| 60 |
+
with st.expander("Document Similarity Search"):
|
| 61 |
+
for i, doc in enumerate(response["context"]):
|
| 62 |
+
st.write(doc.page_content)
|
| 63 |
+
st.write("--------------------------------")
|
|
|
|
|
|
|
|
|