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!")