jerpint commited on
Commit
0f33bb1
·
1 Parent(s): cb5add7

check if outputs already available, unzip them if yes

Browse files
Files changed (1) hide show
  1. app.py +29 -22
app.py CHANGED
@@ -17,37 +17,44 @@ ChatHistory = list[list[Optional[str], Optional[str]]]
17
 
18
  # Because this is a one-click deploy app, we will be relying on env. variables being set
19
  openai_api_key = os.getenv("OPENAI_API_KEY") # Mandatory for app to work
20
- readthedocs_url = os.getenv("READTHEDOCS_URL") # Mandatory for app to work as intended
21
- readthedocs_version = os.getenv("READTHEDOCS_VERSION")
22
 
23
- if openai_api_key is None:
24
- print(
25
- "Warning: No OPENAI_API_KEY detected. Set it with 'export OPENAI_API_KEY=sk-...'."
26
- )
27
 
28
- if readthedocs_url is None:
29
- raise ValueError(
30
- "No READTHEDOCS_URL detected. Set it with e.g. 'export READTHEDOCS_URL=https://orion.readthedocs.io/'"
31
- )
 
 
 
32
 
33
- if readthedocs_version is None:
34
- print(
 
 
 
 
 
 
 
 
 
 
 
 
 
35
  """
36
- Warning: No READTHEDOCS_VERSION detected. If multiple versions of the docs exist, they will all be scraped.
37
- Set it with e.g. 'export READTHEDOCS_VERSION=en/stable'
38
- """
39
- )
40
 
41
 
42
  # Override to put it anywhere
43
  save_directory = "outputs/"
44
 
45
- # scrape and embed content from readthedocs website
46
- embed_documents(
47
- homepage_url=readthedocs_url,
48
- save_directory=save_directory,
49
- target_version=readthedocs_version,
50
- )
51
 
52
  # Setup RAG agent
53
  buster = setup_buster(cfg.buster_cfg)
 
17
 
18
  # Because this is a one-click deploy app, we will be relying on env. variables being set
19
  openai_api_key = os.getenv("OPENAI_API_KEY") # Mandatory for app to work
 
 
20
 
 
 
 
 
21
 
22
+ if os.path.exists("outputs.zip"):
23
+ print("Found outputs.zip, Skipping crawl and embed.")
24
+ extract_zip("outputs.zip", output_path="outputs")
25
+
26
+ else:
27
+ readthedocs_url = os.getenv("READTHEDOCS_URL") # Mandatory for app to work as intended
28
+ readthedocs_version = os.getenv("READTHEDOCS_VERSION")
29
 
30
+ if openai_api_key is None:
31
+ print(
32
+ "Warning: No OPENAI_API_KEY detected. Set it with 'export OPENAI_API_KEY=sk-...'."
33
+ )
34
+
35
+ if readthedocs_url is None:
36
+ raise ValueError(
37
+ "No READTHEDOCS_URL detected. Set it with e.g. 'export READTHEDOCS_URL=https://orion.readthedocs.io/'"
38
+ )
39
+
40
+ if readthedocs_version is None:
41
+ print(
42
+ """
43
+ Warning: No READTHEDOCS_VERSION detected. If multiple versions of the docs exist, they will all be scraped.
44
+ Set it with e.g. 'export READTHEDOCS_VERSION=en/stable'
45
  """
46
+ )
 
 
 
47
 
48
 
49
  # Override to put it anywhere
50
  save_directory = "outputs/"
51
 
52
+ # scrape and embed content from readthedocs website
53
+ crawl_and_embed_docs(
54
+ homepage_url=readthedocs_url,
55
+ save_directory="outputs", # Expected to be in outputs/ by buster cfg
56
+ target_version=readthedocs_version,
57
+ )
58
 
59
  # Setup RAG agent
60
  buster = setup_buster(cfg.buster_cfg)