boryasbora commited on
Commit
6e6cf97
·
verified ·
1 Parent(s): ee03791

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +65 -0
app.py CHANGED
@@ -1,5 +1,8 @@
1
  import streamlit as st
2
  import os
 
 
 
3
  import pickle
4
  from langchain.prompts import ChatPromptTemplate
5
  from langchain.text_splitter import RecursiveCharacterTextSplitter
@@ -14,6 +17,7 @@ from langchain_core.output_parsers import StrOutputParser
14
  from langchain_core.runnables import RunnableLambda
15
  from datetime import date
16
  import time
 
17
  llm_list = ['Mistral-7B-Instruct-v0.2','Mixtral-8x7B-Instruct-v0.1']
18
  blablador_base = "https://helmholtz-blablador.fz-juelich.de:8000/v1"
19
  # Environment variables
@@ -21,6 +25,67 @@ os.environ['LANGCHAIN_TRACING_V2'] = 'true'
21
  os.environ['LANGCHAIN_ENDPOINT'] = 'https://api.smith.langchain.com'
22
  os.environ['LANGCHAIN_API_KEY'] = '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'
23
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
  def load_from_pickle(filename):
25
  with open(filename, "rb") as file:
26
  return pickle.load(file)
 
1
  import streamlit as st
2
  import os
3
+ import shutil
4
+ import schedule
5
+ import time
6
  import pickle
7
  from langchain.prompts import ChatPromptTemplate
8
  from langchain.text_splitter import RecursiveCharacterTextSplitter
 
17
  from langchain_core.runnables import RunnableLambda
18
  from datetime import date
19
  import time
20
+ import subprocess
21
  llm_list = ['Mistral-7B-Instruct-v0.2','Mixtral-8x7B-Instruct-v0.1']
22
  blablador_base = "https://helmholtz-blablador.fz-juelich.de:8000/v1"
23
  # Environment variables
 
25
  os.environ['LANGCHAIN_ENDPOINT'] = 'https://api.smith.langchain.com'
26
  os.environ['LANGCHAIN_API_KEY'] = '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'
27
 
28
+ # Function to update your retriever
29
+ # Function to update your retriever
30
+ def update_retriever():
31
+ # Define the directory and file paths
32
+ directory_path = "ohw_proj_chorma_db"
33
+ file_path = "ohw_proj_chorma_db.pcl"
34
+
35
+ # Remove the directory and its contents if it exists
36
+ if os.path.exists(directory_path):
37
+ shutil.rmtree(directory_path)
38
+ st.write(f"Directory '{directory_path}' and its contents were removed successfully.")
39
+
40
+ # Remove the file if it exists
41
+ if os.path.exists(file_path):
42
+ os.remove(file_path)
43
+ st.write(f"File '{file_path}' was removed successfully.")
44
+
45
+ # Run the first Python script
46
+ try:
47
+ subprocess.run(["python", "scrape_github.py"], check=True)
48
+ st.write("GitHub repos downloaded")
49
+ except subprocess.CalledProcessError as e:
50
+ st.error(f"Error running scrape_github.py: {e}")
51
+
52
+ # Run the second Python script
53
+ try:
54
+ subprocess.run(["python", "create_retriever.py"], check=True)
55
+ st.write("Retriever updated")
56
+ except subprocess.CalledProcessError as e:
57
+ st.error(f"Error running create_retriever.py: {e}")
58
+
59
+ # Additional logic to update your retriever after running the scripts
60
+ st.write("Retriever updated!")
61
+
62
+ # Function to run the scheduler
63
+ def run_scheduler():
64
+ while True:
65
+ schedule.run_pending()
66
+ time.sleep(1) # Check every second
67
+
68
+ # Schedule the retriever update every 24 hours
69
+ schedule.every(24).hours.do(update_retriever)
70
+
71
+ # Run the scheduler in a separate thread to not block the main thread
72
+ scheduler_thread = threading.Thread(target=run_scheduler)
73
+ scheduler_thread.start()
74
+ if os.path.exists(directory_path):
75
+ st.write('retriever loaded')
76
+ else:
77
+ try:
78
+ subprocess.run(["python", "scrape_github.py"], check=True)
79
+ st.write("GitHub repos downloaded")
80
+ except subprocess.CalledProcessError as e:
81
+ st.error(f"Error running scrape_github.py: {e}")
82
+
83
+ # Run the second Python script
84
+ try:
85
+ subprocess.run(["python", "create_retriever.py"], check=True)
86
+ st.write("Retriever updated")
87
+ except subprocess.CalledProcessError as e:
88
+ st.error(f"Error running create_retriever.py: {e}")
89
  def load_from_pickle(filename):
90
  with open(filename, "rb") as file:
91
  return pickle.load(file)