Spaces:
Running
Running
Dan Flower
commited on
Commit
Β·
1295432
1
Parent(s):
7880051
troubleshooting model path issue
Browse files- model/download_model.py +11 -1
- streamlit_app.py +28 -2
model/download_model.py
CHANGED
|
@@ -19,17 +19,27 @@ def main():
|
|
| 19 |
local_dir_use_symlinks=False,
|
| 20 |
token=os.getenv("HF_TOKEN") or None,
|
| 21 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
print(f"[download] hf_hub_download saved: {downloaded}", file=sys.stderr, flush=True)
|
| 23 |
|
| 24 |
# Copy to expected flat path if different
|
| 25 |
if pathlib.Path(downloaded).resolve() != MODEL_PATH.resolve():
|
| 26 |
shutil.copy2(downloaded, MODEL_PATH)
|
| 27 |
-
print(f"[download] copied to: {MODEL_PATH}", file=sys.stderr, flush=True)
|
| 28 |
|
| 29 |
# Write debug marker
|
| 30 |
with open(MODEL_DIR / "MODEL_PATH.txt", "w") as f:
|
| 31 |
f.write(str(MODEL_PATH) + "\n")
|
| 32 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
except Exception as e:
|
| 34 |
print(f"!!! Exception in download_model.py: {e}", file=sys.stderr, flush=True)
|
| 35 |
import traceback
|
|
|
|
| 19 |
local_dir_use_symlinks=False,
|
| 20 |
token=os.getenv("HF_TOKEN") or None,
|
| 21 |
)
|
| 22 |
+
#temporary logging
|
| 23 |
+
print(f"[MARKER] Downloaded to: {downloaded}", file=sys.stderr, flush=True)
|
| 24 |
+
print(f"[MARKER] Model path expected: {MODEL_PATH}", file=sys.stderr, flush=True)
|
| 25 |
+
print(f"[MARKER] /tmp/models after copy: {os.listdir(MODEL_DIR)}", file=sys.stderr, flush=True)
|
| 26 |
+
|
| 27 |
print(f"[download] hf_hub_download saved: {downloaded}", file=sys.stderr, flush=True)
|
| 28 |
|
| 29 |
# Copy to expected flat path if different
|
| 30 |
if pathlib.Path(downloaded).resolve() != MODEL_PATH.resolve():
|
| 31 |
shutil.copy2(downloaded, MODEL_PATH)
|
| 32 |
+
print(f"[MARKER] [download] copied to: {MODEL_PATH}", file=sys.stderr, flush=True)
|
| 33 |
|
| 34 |
# Write debug marker
|
| 35 |
with open(MODEL_DIR / "MODEL_PATH.txt", "w") as f:
|
| 36 |
f.write(str(MODEL_PATH) + "\n")
|
| 37 |
|
| 38 |
+
print(f"[MARKER] Final /tmp/models contents: {os.listdir(MODEL_DIR)}", file=sys.stderr, flush=True)
|
| 39 |
+
#temporary symlink info
|
| 40 |
+
print(f"[MARKER] Symlink? {os.path.islink(downloaded)}", file=sys.stderr, flush=True)
|
| 41 |
+
|
| 42 |
+
|
| 43 |
except Exception as e:
|
| 44 |
print(f"!!! Exception in download_model.py: {e}", file=sys.stderr, flush=True)
|
| 45 |
import traceback
|
streamlit_app.py
CHANGED
|
@@ -22,7 +22,33 @@ os.makedirs("/tmp/models", exist_ok=True)
|
|
| 22 |
# Runtime model download if needed
|
| 23 |
|
| 24 |
MODEL_PATH = "/tmp/models/TinyLlama-1.1B-Chat-v1.0.Q4_K_M.gguf"
|
| 25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
st.warning("Model not found. Downloading...")
|
| 27 |
try:
|
| 28 |
subprocess.run(["python3", "model/download_model.py"], check=True, capture_output=True)
|
|
@@ -32,7 +58,7 @@ if not os.path.exists(MODEL_PATH):
|
|
| 32 |
st.text(f"Exit code: {e.returncode}")
|
| 33 |
st.text(f"Command: {e.cmd}")
|
| 34 |
st.text(f"Output: {e.output if hasattr(e, 'output') else 'N/A'}")
|
| 35 |
-
st.stop()
|
| 36 |
|
| 37 |
st.markdown("## π /tmp/models content:")
|
| 38 |
st.text('\n'.join(os.listdir("/tmp/models")))
|
|
|
|
| 22 |
# Runtime model download if needed
|
| 23 |
|
| 24 |
MODEL_PATH = "/tmp/models/TinyLlama-1.1B-Chat-v1.0.Q4_K_M.gguf"
|
| 25 |
+
# Always run download_model.py for troubleshooting
|
| 26 |
+
st.warning("Running model download step...")
|
| 27 |
+
|
| 28 |
+
try:
|
| 29 |
+
result = subprocess.run(
|
| 30 |
+
["python3", "model/download_model.py"],
|
| 31 |
+
check=True,
|
| 32 |
+
capture_output=True,
|
| 33 |
+
text=True # ensures stdout/stderr are strings
|
| 34 |
+
)
|
| 35 |
+
st.success("Model download attempted.")
|
| 36 |
+
st.text("STDOUT:")
|
| 37 |
+
st.text(result.stdout)
|
| 38 |
+
st.text("STDERR:")
|
| 39 |
+
st.text(result.stderr)
|
| 40 |
+
except subprocess.CalledProcessError as e:
|
| 41 |
+
st.error("Model download failed. Check HF_TOKEN or permissions.")
|
| 42 |
+
st.text(f"Exit code: {e.returncode}")
|
| 43 |
+
st.text(f"Command: {e.cmd}")
|
| 44 |
+
st.text("STDOUT:")
|
| 45 |
+
st.text(e.stdout or "No stdout")
|
| 46 |
+
st.text("STDERR:")
|
| 47 |
+
st.text(e.stderr or "No stderr")
|
| 48 |
+
st.stop()
|
| 49 |
+
|
| 50 |
+
#end of temp code
|
| 51 |
+
'''if not os.path.exists(MODEL_PATH):
|
| 52 |
st.warning("Model not found. Downloading...")
|
| 53 |
try:
|
| 54 |
subprocess.run(["python3", "model/download_model.py"], check=True, capture_output=True)
|
|
|
|
| 58 |
st.text(f"Exit code: {e.returncode}")
|
| 59 |
st.text(f"Command: {e.cmd}")
|
| 60 |
st.text(f"Output: {e.output if hasattr(e, 'output') else 'N/A'}")
|
| 61 |
+
st.stop()'''
|
| 62 |
|
| 63 |
st.markdown("## π /tmp/models content:")
|
| 64 |
st.text('\n'.join(os.listdir("/tmp/models")))
|