Spaces:
Sleeping
Sleeping
File size: 5,636 Bytes
28868c1 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 | """
Diagnostic App - Find out why the full model isn't working
"""
import streamlit as st
import os
import sys
st.set_page_config(
page_title="Model Diagnostic",
page_icon="π",
layout="wide"
)
st.title("π Model Diagnostic Tool")
st.markdown("### Let's find out why your full model isn't working!")
# Diagnostic section
st.header("π System Diagnostics")
# Check 1: Python environment
st.subheader("1. Python Environment")
st.write(f"**Python Version:** {sys.version}")
st.write(f"**Working Directory:** {os.getcwd()}")
# Check 2: Required packages
st.subheader("2. Required Packages")
try:
import streamlit
st.success(f"β
Streamlit: {streamlit.__version__}")
except ImportError as e:
st.error(f"β Streamlit: {e}")
try:
import torch
st.success(f"β
PyTorch: {torch.__version__}")
except ImportError as e:
st.error(f"β PyTorch: {e}")
try:
import transformers
st.success(f"β
Transformers: {transformers.__version__}")
except ImportError as e:
st.error(f"β Transformers: {e}")
try:
import accelerate
st.success(f"β
Accelerate: {accelerate.__version__}")
except ImportError as e:
st.error(f"β Accelerate: {e}")
# Check 3: Fine-tuned model components
st.subheader("3. Fine-tuned Model Components")
try:
from fine import ProgrammingEducationAI, ComprehensiveFeedback
st.success("β
Fine-tuned model components imported successfully")
MODEL_AVAILABLE = True
except Exception as e:
st.error(f"β Fine-tuned model components failed: {e}")
MODEL_AVAILABLE = False
# Check 4: Environment variables
st.subheader("4. Environment Variables")
HF_TOKEN = None # Using public model
st.success("β
Using public model - no HF_TOKEN required")
st.info("π‘ Public models don't need authentication tokens")
# Check 5: Model path
st.subheader("5. Model Path Configuration")
model_path = "FaroukTomori/codellama-7b-programming-education"
st.write(f"**Current model path:** {model_path}")
st.info("π‘ Make sure this matches your actual model name on Hugging Face")
# Check 6: File structure
st.subheader("6. File Structure")
current_dir = os.getcwd()
st.write(f"**Current directory:** {current_dir}")
files = os.listdir(current_dir)
st.write("**Files in current directory:**")
for file in files:
if file.endswith('.py'):
st.write(f" π {file}")
# Check 7: Fine.py file
st.subheader("7. Fine.py File Analysis")
fine_path = os.path.join(current_dir, "fine.py")
if os.path.exists(fine_path):
st.success("β
fine.py exists")
file_size = os.path.getsize(fine_path)
st.write(f"**File size:** {file_size:,} bytes")
# Check if it has the required classes
try:
with open(fine_path, 'r', encoding='utf-8') as f:
content = f.read()
if "class ProgrammingEducationAI" in content:
st.success("β
ProgrammingEducationAI class found")
else:
st.error("β ProgrammingEducationAI class not found")
if "class ComprehensiveFeedback" in content:
st.success("β
ComprehensiveFeedback class found")
else:
st.error("β ComprehensiveFeedback class not found")
except Exception as e:
st.error(f"β Error reading fine.py: {e}")
else:
st.error("β fine.py not found")
# Check 8: Model files
st.subheader("8. Model Files")
models_dir = os.path.join(current_dir, "models")
if os.path.exists(models_dir):
st.success("β
models directory exists")
model_files = os.listdir(models_dir)
st.write("**Model files:**")
for file in model_files:
st.write(f" π {file}")
else:
st.warning("β οΈ models directory not found")
# Summary and recommendations
st.header("π― Summary & Recommendations")
if MODEL_AVAILABLE:
st.success("π Everything looks good! Your public model should work.")
st.info("π‘ Try using the full app now.")
else:
st.error("β Fine-tuned model components are not available")
st.markdown("""
**Possible causes:**
1. `fine.py` file is missing or corrupted
2. Required dependencies are not installed
3. Import error in `fine.py`
**Solutions:**
1. Make sure `fine.py` exists and is complete
2. Install missing dependencies: `pip install torch transformers accelerate`
3. Check for syntax errors in `fine.py`
""")
# Test model loading
st.header("π§ͺ Test Model Loading")
if st.button("π Test Model Loading"):
if MODEL_AVAILABLE:
with st.spinner("Testing model loading..."):
try:
model_path = "FaroukTomori/codellama-7b-programming-education"
ai_tutor = ProgrammingEducationAI(model_path)
st.success("β
Model class instantiated successfully")
# Try to load the model
try:
ai_tutor.load_model()
st.success("β
Model loaded successfully!")
except Exception as e:
st.error(f"β Model loading failed: {e}")
st.info(
"π‘ This usually means the model isn't uploaded to HF Model Hub yet")
except Exception as e:
st.error(f"β Model instantiation failed: {e}")
else:
st.error("β Cannot test - model components not available")
st.markdown("---")
st.info("π‘ **Next Steps:** Fix the issues above, then try the main app again!")
|