fehmikaya commited on
Commit
9b8317e
·
verified ·
1 Parent(s): 3a15bf5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -15
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
- if 'initiated' not in st.session_state:
22
- HF_TOKEN = os.getenv("HF_TOKEN")
23
- if HF_TOKEN is None:
24
- st.error("API key not found. Please set the HF_TOKEN secret in your Hugging Face Space.")
25
- st.stop()
26
- icons = {"assistant": "robot.png", "user": "man-kddi.png"}
27
- DATA_DIR = "data"
28
- remote_llm = CustomLlama3(bearer_token = HF_TOKEN)
29
- # Ensure data directory exists
30
- os.makedirs(DATA_DIR, exist_ok=True)
31
- retriever=None
32
- st.session_state.initiated="true"
 
 
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