raguv commited on
Commit
cabf856
·
verified ·
1 Parent(s): 2b92959

Update app1.py

Browse files
Files changed (1) hide show
  1. app1.py +15 -22
app1.py CHANGED
@@ -1,31 +1,24 @@
1
  import os
2
  import sys
 
3
  import streamlit as st
4
  from huggingface_hub import snapshot_download
5
 
6
- # 1. Download the private repository
7
- # This happens every time the Space starts up
8
- try:
9
  local_dir = snapshot_download(
10
- repo_id="raguv/CR-R1.0-access-test",
11
- repo_type="space",
12
- token=os.environ.get("HF_TOKEN")
13
  )
14
-
15
- # 2. Point Python to your private folder
16
- sys.path.append(local_dir)
17
- os.environ["PYTHONPATH"] = local_dir
18
-
19
- # 3. Read and execute your private file directly
20
- # This bypasses the "Port 7860" conflict entirely
21
- real_app_path = os.path.join(local_dir, "app.py")
22
-
23
- with open(real_app_path, "r", encoding="utf-8") as f:
24
  code = f.read()
25
-
26
- # This executes your private code as if it were written right here
27
- exec(code, globals())
28
 
29
- except Exception as e:
30
- st.error(f"❌ Critical Error: {e}")
31
- st.info("Check your HF_TOKEN and private repository name.")
 
 
 
 
 
1
  import os
2
  import sys
3
+ import subprocess
4
  import streamlit as st
5
  from huggingface_hub import snapshot_download
6
 
7
+ @st.cache_resource(show_spinner=False)
8
+ def get_private_code():
 
9
  local_dir = snapshot_download(
10
+ repo_id=os.environ.get("HF_REPO"),
11
+ token=os.environ.get("HF_TOKEN"),
12
+ repo_type="space"
13
  )
14
+ with open(os.path.join(local_dir, "app.py"), "r", encoding="utf-8") as f:
 
 
 
 
 
 
 
 
 
15
  code = f.read()
16
+ return code, local_dir
 
 
17
 
18
+ try:
19
+ code_content, private_dir = get_private_code()
20
+ sys.path.append(private_dir)
21
+ os.environ["PYTHONPATH"] = private_dir
22
+ exec(compile(code_content, "internal_logic", "exec"), globals())
23
+ except Exception:
24
+ st.error("Error! Check Repo and Token details.")