Spaces:
Runtime error
Runtime error
Update app1.py
Browse files
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 |
-
|
| 7 |
-
|
| 8 |
-
try:
|
| 9 |
local_dir = snapshot_download(
|
| 10 |
-
repo_id=
|
| 11 |
-
|
| 12 |
-
|
| 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 |
-
|
| 30 |
-
|
| 31 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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.")
|