Spaces:
Sleeping
Sleeping
Rename .gitattributes to app.py
Browse files- .gitattributes +0 -35
- app.py +345 -0
.gitattributes
DELETED
|
@@ -1,35 +0,0 @@
|
|
| 1 |
-
*.7z filter=lfs diff=lfs merge=lfs -text
|
| 2 |
-
*.arrow filter=lfs diff=lfs merge=lfs -text
|
| 3 |
-
*.bin filter=lfs diff=lfs merge=lfs -text
|
| 4 |
-
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
| 5 |
-
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
| 6 |
-
*.ftz filter=lfs diff=lfs merge=lfs -text
|
| 7 |
-
*.gz filter=lfs diff=lfs merge=lfs -text
|
| 8 |
-
*.h5 filter=lfs diff=lfs merge=lfs -text
|
| 9 |
-
*.joblib filter=lfs diff=lfs merge=lfs -text
|
| 10 |
-
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
| 11 |
-
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
| 12 |
-
*.model filter=lfs diff=lfs merge=lfs -text
|
| 13 |
-
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
| 14 |
-
*.npy filter=lfs diff=lfs merge=lfs -text
|
| 15 |
-
*.npz filter=lfs diff=lfs merge=lfs -text
|
| 16 |
-
*.onnx filter=lfs diff=lfs merge=lfs -text
|
| 17 |
-
*.ot filter=lfs diff=lfs merge=lfs -text
|
| 18 |
-
*.parquet filter=lfs diff=lfs merge=lfs -text
|
| 19 |
-
*.pb filter=lfs diff=lfs merge=lfs -text
|
| 20 |
-
*.pickle filter=lfs diff=lfs merge=lfs -text
|
| 21 |
-
*.pkl filter=lfs diff=lfs merge=lfs -text
|
| 22 |
-
*.pt filter=lfs diff=lfs merge=lfs -text
|
| 23 |
-
*.pth filter=lfs diff=lfs merge=lfs -text
|
| 24 |
-
*.rar filter=lfs diff=lfs merge=lfs -text
|
| 25 |
-
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
| 26 |
-
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
| 27 |
-
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
| 28 |
-
*.tar filter=lfs diff=lfs merge=lfs -text
|
| 29 |
-
*.tflite filter=lfs diff=lfs merge=lfs -text
|
| 30 |
-
*.tgz filter=lfs diff=lfs merge=lfs -text
|
| 31 |
-
*.wasm filter=lfs diff=lfs merge=lfs -text
|
| 32 |
-
*.xz filter=lfs diff=lfs merge=lfs -text
|
| 33 |
-
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
-
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
-
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app.py
ADDED
|
@@ -0,0 +1,345 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
|
| 3 |
+
SYSTEM_PROMPT = """You are a professional coding teacher explaining code to a complete beginner.
|
| 4 |
+
|
| 5 |
+
When given code, respond ONLY in this exact HTML structure (no markdown, no backticks):
|
| 6 |
+
|
| 7 |
+
<div class="section" id="simple">
|
| 8 |
+
<h2>🧠 Simple Explanation</h2>
|
| 9 |
+
<ul>
|
| 10 |
+
[3-5 bullet points explaining what the code does in simple words]
|
| 11 |
+
</ul>
|
| 12 |
+
</div>
|
| 13 |
+
|
| 14 |
+
<div class="section" id="steps">
|
| 15 |
+
<h2>👣 Step-by-Step Working</h2>
|
| 16 |
+
<ol>
|
| 17 |
+
[numbered steps of how the code runs]
|
| 18 |
+
</ol>
|
| 19 |
+
</div>
|
| 20 |
+
|
| 21 |
+
<div class="section" id="variables">
|
| 22 |
+
<h2>📦 Variables & Functions</h2>
|
| 23 |
+
<ul>
|
| 24 |
+
[explain each variable and function simply]
|
| 25 |
+
</ul>
|
| 26 |
+
</div>
|
| 27 |
+
|
| 28 |
+
<div class="section" id="logic">
|
| 29 |
+
<h2>🔄 Logic (Loops & Conditions)</h2>
|
| 30 |
+
<p>[explain any loops, if/else, conditions in very simple words]</p>
|
| 31 |
+
</div>
|
| 32 |
+
|
| 33 |
+
<div class="section" id="analogy">
|
| 34 |
+
<h2>🌍 Real-Life Analogy</h2>
|
| 35 |
+
<p>[a simple real-world comparison that a child could understand]</p>
|
| 36 |
+
</div>
|
| 37 |
+
|
| 38 |
+
<div class="section" id="output">
|
| 39 |
+
<h2>🖥️ Output</h2>
|
| 40 |
+
<div class="output-box">[what the code prints/returns]</div>
|
| 41 |
+
</div>
|
| 42 |
+
|
| 43 |
+
<div class="section" id="errors">
|
| 44 |
+
<h2>🐛 Errors Found & Fixed</h2>
|
| 45 |
+
<p>[mention any bugs or if code is correct]</p>
|
| 46 |
+
</div>
|
| 47 |
+
|
| 48 |
+
<div class="section" id="improvements">
|
| 49 |
+
<h2>✨ Suggested Improvements</h2>
|
| 50 |
+
<ul>
|
| 51 |
+
[2-3 improvement tips]
|
| 52 |
+
</ul>
|
| 53 |
+
</div>
|
| 54 |
+
|
| 55 |
+
<div class="section" id="complexity">
|
| 56 |
+
<h2>⏱️ Time Complexity</h2>
|
| 57 |
+
<p>[explain time complexity in very simple words like "this runs once" or "this loops N times"]</p>
|
| 58 |
+
</div>
|
| 59 |
+
|
| 60 |
+
<div class="section" id="summary">
|
| 61 |
+
<h2>📝 Short Summary</h2>
|
| 62 |
+
<p>[1-2 sentence summary of what the code does]</p>
|
| 63 |
+
</div>
|
| 64 |
+
|
| 65 |
+
Use very easy English. No technical jargon. Keep it short but clear."""
|
| 66 |
+
|
| 67 |
+
CSS = """
|
| 68 |
+
@import url('https://fonts.googleapis.com/css2?family=Syne:wght@400;600;700;800&family=DM+Mono:wght@400;500&family=DM+Sans:wght@300;400;500&display=swap');
|
| 69 |
+
|
| 70 |
+
:root {
|
| 71 |
+
--bg: #0a0a0f;
|
| 72 |
+
--surface: #12121a;
|
| 73 |
+
--surface2: #1a1a26;
|
| 74 |
+
--border: #2a2a3d;
|
| 75 |
+
--accent: #7c6aff;
|
| 76 |
+
--accent2: #ff6a9e;
|
| 77 |
+
--accent3: #6affb8;
|
| 78 |
+
--text: #e8e8f0;
|
| 79 |
+
--text-muted: #8888aa;
|
| 80 |
+
--glow: 0 0 30px rgba(124, 106, 255, 0.15);
|
| 81 |
+
}
|
| 82 |
+
|
| 83 |
+
* { box-sizing: border-box; margin: 0; padding: 0; }
|
| 84 |
+
|
| 85 |
+
body, .gradio-container {
|
| 86 |
+
background: var(--bg) !important;
|
| 87 |
+
font-family: 'DM Sans', sans-serif !important;
|
| 88 |
+
color: var(--text) !important;
|
| 89 |
+
min-height: 100vh;
|
| 90 |
+
}
|
| 91 |
+
|
| 92 |
+
.gradio-container {
|
| 93 |
+
max-width: 1100px !important;
|
| 94 |
+
margin: 0 auto !important;
|
| 95 |
+
padding: 2rem !important;
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
/* Header */
|
| 99 |
+
.header-block {
|
| 100 |
+
text-align: center;
|
| 101 |
+
padding: 3rem 0 2rem;
|
| 102 |
+
position: relative;
|
| 103 |
+
}
|
| 104 |
+
|
| 105 |
+
.header-block::before {
|
| 106 |
+
content: '';
|
| 107 |
+
position: absolute;
|
| 108 |
+
top: 0; left: 50%;
|
| 109 |
+
transform: translateX(-50%);
|
| 110 |
+
width: 300px; height: 300px;
|
| 111 |
+
background: radial-gradient(circle, rgba(124,106,255,0.12) 0%, transparent 70%);
|
| 112 |
+
pointer-events: none;
|
| 113 |
+
}
|
| 114 |
+
|
| 115 |
+
.app-title {
|
| 116 |
+
font-family: 'Syne', sans-serif !important;
|
| 117 |
+
font-size: 3rem !important;
|
| 118 |
+
font-weight: 800 !important;
|
| 119 |
+
background: linear-gradient(135deg, #7c6aff, #ff6a9e, #6affb8) !important;
|
| 120 |
+
-webkit-background-clip: text !important;
|
| 121 |
+
-webkit-text-fill-color: transparent !important;
|
| 122 |
+
background-clip: text !important;
|
| 123 |
+
line-height: 1.1 !important;
|
| 124 |
+
letter-spacing: -1px !important;
|
| 125 |
+
}
|
| 126 |
+
|
| 127 |
+
.app-subtitle {
|
| 128 |
+
color: var(--text-muted) !important;
|
| 129 |
+
font-size: 1.05rem !important;
|
| 130 |
+
margin-top: 0.6rem !important;
|
| 131 |
+
font-weight: 300 !important;
|
| 132 |
+
}
|
| 133 |
+
|
| 134 |
+
/* Input area */
|
| 135 |
+
.code-input textarea {
|
| 136 |
+
background: var(--surface) !important;
|
| 137 |
+
border: 1.5px solid var(--border) !important;
|
| 138 |
+
border-radius: 16px !important;
|
| 139 |
+
color: var(--text) !important;
|
| 140 |
+
font-family: 'DM Mono', monospace !important;
|
| 141 |
+
font-size: 0.9rem !important;
|
| 142 |
+
padding: 1.2rem !important;
|
| 143 |
+
transition: border-color 0.2s, box-shadow 0.2s !important;
|
| 144 |
+
resize: vertical !important;
|
| 145 |
+
}
|
| 146 |
+
|
| 147 |
+
.code-input textarea:focus {
|
| 148 |
+
border-color: var(--accent) !important;
|
| 149 |
+
box-shadow: var(--glow) !important;
|
| 150 |
+
outline: none !important;
|
| 151 |
+
}
|
| 152 |
+
|
| 153 |
+
.code-input label {
|
| 154 |
+
font-family: 'Syne', sans-serif !important;
|
| 155 |
+
font-weight: 600 !important;
|
| 156 |
+
color: var(--text) !important;
|
| 157 |
+
font-size: 0.95rem !important;
|
| 158 |
+
letter-spacing: 0.5px !important;
|
| 159 |
+
}
|
| 160 |
+
|
| 161 |
+
/* Button */
|
| 162 |
+
button.primary {
|
| 163 |
+
background: linear-gradient(135deg, var(--accent), var(--accent2)) !important;
|
| 164 |
+
border: none !important;
|
| 165 |
+
border-radius: 12px !important;
|
| 166 |
+
color: white !important;
|
| 167 |
+
font-family: 'Syne', sans-serif !important;
|
| 168 |
+
font-size: 1rem !important;
|
| 169 |
+
font-weight: 700 !important;
|
| 170 |
+
padding: 0.85rem 2.5rem !important;
|
| 171 |
+
cursor: pointer !important;
|
| 172 |
+
transition: transform 0.15s, box-shadow 0.15s !important;
|
| 173 |
+
letter-spacing: 0.5px !important;
|
| 174 |
+
}
|
| 175 |
+
|
| 176 |
+
button.primary:hover {
|
| 177 |
+
transform: translateY(-2px) !important;
|
| 178 |
+
box-shadow: 0 8px 25px rgba(124,106,255,0.35) !important;
|
| 179 |
+
}
|
| 180 |
+
|
| 181 |
+
/* Output HTML */
|
| 182 |
+
.output-html {
|
| 183 |
+
background: var(--surface) !important;
|
| 184 |
+
border: 1.5px solid var(--border) !important;
|
| 185 |
+
border-radius: 16px !important;
|
| 186 |
+
padding: 1.5rem !important;
|
| 187 |
+
}
|
| 188 |
+
|
| 189 |
+
/* Section cards rendered inside HTML output */
|
| 190 |
+
.section {
|
| 191 |
+
background: var(--surface2);
|
| 192 |
+
border: 1px solid var(--border);
|
| 193 |
+
border-radius: 14px;
|
| 194 |
+
padding: 1.4rem 1.6rem;
|
| 195 |
+
margin-bottom: 1rem;
|
| 196 |
+
transition: border-color 0.2s;
|
| 197 |
+
}
|
| 198 |
+
|
| 199 |
+
.section:hover { border-color: var(--accent); }
|
| 200 |
+
|
| 201 |
+
.section h2 {
|
| 202 |
+
font-family: 'Syne', sans-serif;
|
| 203 |
+
font-size: 1rem;
|
| 204 |
+
font-weight: 700;
|
| 205 |
+
color: var(--accent);
|
| 206 |
+
margin-bottom: 0.8rem;
|
| 207 |
+
letter-spacing: 0.3px;
|
| 208 |
+
}
|
| 209 |
+
|
| 210 |
+
.section ul, .section ol {
|
| 211 |
+
padding-left: 1.4rem;
|
| 212 |
+
color: var(--text);
|
| 213 |
+
line-height: 1.8;
|
| 214 |
+
font-size: 0.93rem;
|
| 215 |
+
}
|
| 216 |
+
|
| 217 |
+
.section p {
|
| 218 |
+
color: var(--text);
|
| 219 |
+
line-height: 1.7;
|
| 220 |
+
font-size: 0.93rem;
|
| 221 |
+
}
|
| 222 |
+
|
| 223 |
+
.output-box {
|
| 224 |
+
background: #0d0d15;
|
| 225 |
+
border: 1px solid var(--border);
|
| 226 |
+
border-left: 3px solid var(--accent3);
|
| 227 |
+
border-radius: 8px;
|
| 228 |
+
padding: 0.8rem 1rem;
|
| 229 |
+
font-family: 'DM Mono', monospace;
|
| 230 |
+
font-size: 0.88rem;
|
| 231 |
+
color: var(--accent3);
|
| 232 |
+
white-space: pre-wrap;
|
| 233 |
+
}
|
| 234 |
+
|
| 235 |
+
#analogy h2 { color: var(--accent3) !important; }
|
| 236 |
+
#output h2 { color: var(--accent3) !important; }
|
| 237 |
+
#summary h2 { color: var(--accent2) !important; }
|
| 238 |
+
#errors h2 { color: #ff9966 !important; }
|
| 239 |
+
|
| 240 |
+
/* Loading */
|
| 241 |
+
.generating {
|
| 242 |
+
text-align: center;
|
| 243 |
+
color: var(--text-muted);
|
| 244 |
+
padding: 2rem;
|
| 245 |
+
font-family: 'Syne', sans-serif;
|
| 246 |
+
}
|
| 247 |
+
|
| 248 |
+
/* Footer */
|
| 249 |
+
footer { display: none !important; }
|
| 250 |
+
"""
|
| 251 |
+
|
| 252 |
+
PLACEHOLDER = '''# Paste your code here! Example:
|
| 253 |
+
|
| 254 |
+
def greet(name):
|
| 255 |
+
for i in range(3):
|
| 256 |
+
print("Hello, " + name + "!")
|
| 257 |
+
|
| 258 |
+
greet("Alice")'''
|
| 259 |
+
|
| 260 |
+
def explain_code(code):
|
| 261 |
+
if not code.strip():
|
| 262 |
+
return "<p style='color:#8888aa; padding:1rem;'>⚠️ Please paste some code first!</p>"
|
| 263 |
+
|
| 264 |
+
try:
|
| 265 |
+
import anthropic
|
| 266 |
+
client = anthropic.Anthropic()
|
| 267 |
+
|
| 268 |
+
message = client.messages.create(
|
| 269 |
+
model="claude-sonnet-4-20250514",
|
| 270 |
+
max_tokens=2000,
|
| 271 |
+
system=SYSTEM_PROMPT,
|
| 272 |
+
messages=[{"role": "user", "content": f"Explain this code:\n\n{code}"}]
|
| 273 |
+
)
|
| 274 |
+
|
| 275 |
+
result = message.content[0].text
|
| 276 |
+
|
| 277 |
+
# Wrap in styled container
|
| 278 |
+
return f"""
|
| 279 |
+
<style>
|
| 280 |
+
:root {{
|
| 281 |
+
--bg:#0a0a0f;--surface:#12121a;--surface2:#1a1a26;
|
| 282 |
+
--border:#2a2a3d;--accent:#7c6aff;--accent2:#ff6a9e;
|
| 283 |
+
--accent3:#6affb8;--text:#e8e8f0;--text-muted:#8888aa;
|
| 284 |
+
}}
|
| 285 |
+
@import url('https://fonts.googleapis.com/css2?family=Syne:wght@700&family=DM+Mono&family=DM+Sans:wght@300;400&display=swap');
|
| 286 |
+
.section{{background:var(--surface2);border:1px solid var(--border);border-radius:14px;padding:1.4rem 1.6rem;margin-bottom:1rem;}}
|
| 287 |
+
.section:hover{{border-color:var(--accent);}}
|
| 288 |
+
.section h2{{font-family:'Syne',sans-serif;font-size:1rem;font-weight:700;color:var(--accent);margin-bottom:0.8rem;}}
|
| 289 |
+
.section ul,.section ol{{padding-left:1.4rem;color:var(--text);line-height:1.8;font-size:0.93rem;}}
|
| 290 |
+
.section p{{color:var(--text);line-height:1.7;font-size:0.93rem;}}
|
| 291 |
+
.output-box{{background:#0d0d15;border:1px solid var(--border);border-left:3px solid var(--accent3);border-radius:8px;padding:0.8rem 1rem;font-family:'DM Mono',monospace;font-size:0.88rem;color:var(--accent3);white-space:pre-wrap;}}
|
| 292 |
+
#analogy h2,#output h2{{color:var(--accent3)!important;}}
|
| 293 |
+
#summary h2{{color:var(--accent2)!important;}}
|
| 294 |
+
#errors h2{{color:#ff9966!important;}}
|
| 295 |
+
</style>
|
| 296 |
+
{result}
|
| 297 |
+
"""
|
| 298 |
+
except Exception as e:
|
| 299 |
+
return f"<p style='color:#ff6a6a;padding:1rem;'>❌ Error: {str(e)}</p>"
|
| 300 |
+
|
| 301 |
+
|
| 302 |
+
with gr.Blocks(css=CSS, title="CodeLens — AI Code Explainer") as demo:
|
| 303 |
+
|
| 304 |
+
gr.HTML("""
|
| 305 |
+
<div class="header-block">
|
| 306 |
+
<h1 class="app-title">CodeLens</h1>
|
| 307 |
+
<p class="app-subtitle">Paste any code → Get a beginner-friendly explanation instantly ✨</p>
|
| 308 |
+
</div>
|
| 309 |
+
""")
|
| 310 |
+
|
| 311 |
+
with gr.Row():
|
| 312 |
+
with gr.Column(scale=1):
|
| 313 |
+
code_input = gr.Code(
|
| 314 |
+
label="📋 Paste Your Code Here",
|
| 315 |
+
language="python",
|
| 316 |
+
lines=14,
|
| 317 |
+
elem_classes=["code-input"],
|
| 318 |
+
placeholder=PLACEHOLDER
|
| 319 |
+
)
|
| 320 |
+
|
| 321 |
+
explain_btn = gr.Button(
|
| 322 |
+
"🔍 Explain This Code",
|
| 323 |
+
variant="primary",
|
| 324 |
+
size="lg"
|
| 325 |
+
)
|
| 326 |
+
|
| 327 |
+
output = gr.HTML(
|
| 328 |
+
label="",
|
| 329 |
+
elem_classes=["output-html"]
|
| 330 |
+
)
|
| 331 |
+
|
| 332 |
+
explain_btn.click(
|
| 333 |
+
fn=explain_code,
|
| 334 |
+
inputs=[code_input],
|
| 335 |
+
outputs=[output]
|
| 336 |
+
)
|
| 337 |
+
|
| 338 |
+
gr.HTML("""
|
| 339 |
+
<div style="text-align:center; padding:1.5rem 0 0.5rem; color:#8888aa; font-size:0.82rem; font-family:'DM Sans',sans-serif;">
|
| 340 |
+
Built with ❤️ using Claude AI · CodeLens for Beginners
|
| 341 |
+
</div>
|
| 342 |
+
""")
|
| 343 |
+
|
| 344 |
+
if __name__ == "__main__":
|
| 345 |
+
demo.launch()
|