Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -18,18 +18,20 @@ from langchain_text_splitters import RecursiveCharacterTextSplitter
|
|
18 |
|
19 |
# Get the API key from the environment variable
|
20 |
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
|
|
|
|
33 |
|
34 |
def data_ingestion():
|
35 |
|
@@ -89,10 +91,10 @@ def retrieval_grader(question):
|
|
89 |
)
|
90 |
|
91 |
# Chain
|
92 |
-
rag_chain = prompt | remote_llm | StrOutputParser()
|
93 |
|
94 |
# Run
|
95 |
-
docs = retriever.invoke(question)
|
96 |
generation = rag_chain.invoke({"context": "\n\n".join(doc.page_content for doc in docs), "question": question})
|
97 |
return generation
|
98 |
|
@@ -134,7 +136,7 @@ with st.sidebar:
|
|
134 |
with open(DATA_DIR+"/saved_link.txt", "w") as file:
|
135 |
file.write(web_url)
|
136 |
st.session_state["console_out"] += "Link saved: " + web_url + "\n"
|
137 |
-
retriever = data_ingestion()
|
138 |
st.success("Done")
|
139 |
st.text_area("Console", st.session_state["console_out"])
|
140 |
|
|
|
18 |
|
19 |
# Get the API key from the environment variable
|
20 |
|
21 |
+
HF_TOKEN = os.getenv("HF_TOKEN")
|
22 |
+
if HF_TOKEN is None:
|
23 |
+
st.error("API key not found. Please set the HF_TOKEN secret in your Hugging Face Space.")
|
24 |
+
st.stop()
|
25 |
+
icons = {"assistant": "robot.png", "user": "man-kddi.png"}
|
26 |
+
DATA_DIR = "data"
|
27 |
+
# Ensure data directory exists
|
28 |
+
os.makedirs(DATA_DIR, exist_ok=True)
|
29 |
+
|
30 |
+
if not hasattr(st, 'remote_llm'):
|
31 |
+
st.remote_llm = CustomLlama3(bearer_token = HF_TOKEN)
|
32 |
+
|
33 |
+
if not hasattr(st, 'retriever'):
|
34 |
+
st.retriever = "None"
|
35 |
|
36 |
def data_ingestion():
|
37 |
|
|
|
91 |
)
|
92 |
|
93 |
# Chain
|
94 |
+
rag_chain = prompt | st.remote_llm | StrOutputParser()
|
95 |
|
96 |
# Run
|
97 |
+
docs = st.retriever.invoke(question)
|
98 |
generation = rag_chain.invoke({"context": "\n\n".join(doc.page_content for doc in docs), "question": question})
|
99 |
return generation
|
100 |
|
|
|
136 |
with open(DATA_DIR+"/saved_link.txt", "w") as file:
|
137 |
file.write(web_url)
|
138 |
st.session_state["console_out"] += "Link saved: " + web_url + "\n"
|
139 |
+
st.retriever = data_ingestion()
|
140 |
st.success("Done")
|
141 |
st.text_area("Console", st.session_state["console_out"])
|
142 |
|