Spaces:
Sleeping
Sleeping
Upload app.py
Browse files
app.py
CHANGED
|
@@ -77,105 +77,29 @@ def generate_text(prompt, max_length=50, temperature=0.8):
|
|
| 77 |
traceback.print_exc()
|
| 78 |
return f"Error during generation: {str(e)}"
|
| 79 |
|
| 80 |
-
# Gradio Interface
|
| 81 |
-
|
| 82 |
-
#
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
border-radius: 10px;
|
| 86 |
-
margin-bottom: 1.5rem;
|
| 87 |
-
color: white;
|
| 88 |
-
}
|
| 89 |
-
|
| 90 |
-
#header h1 {
|
| 91 |
-
color: white !important;
|
| 92 |
-
font-size: 2.5rem !important;
|
| 93 |
-
margin-bottom: 0.5rem !important;
|
| 94 |
-
}
|
| 95 |
-
|
| 96 |
-
#header p {
|
| 97 |
-
color: rgba(255, 255, 255, 0.95) !important;
|
| 98 |
-
font-size: 1.1rem !important;
|
| 99 |
-
}
|
| 100 |
-
|
| 101 |
-
.generate-btn {
|
| 102 |
-
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
|
| 103 |
-
border: none !important;
|
| 104 |
-
color: white !important;
|
| 105 |
-
font-weight: 600 !important;
|
| 106 |
-
padding: 0.75rem 2rem !important;
|
| 107 |
-
border-radius: 8px !important;
|
| 108 |
-
transition: transform 0.2s !important;
|
| 109 |
-
}
|
| 110 |
-
|
| 111 |
-
.generate-btn:hover {
|
| 112 |
-
transform: translateY(-2px) !important;
|
| 113 |
-
box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4) !important;
|
| 114 |
-
}
|
| 115 |
-
|
| 116 |
-
#output-box {
|
| 117 |
-
border: 2px solid #667eea !important;
|
| 118 |
-
border-radius: 8px !important;
|
| 119 |
-
background: #f8f9ff !important;
|
| 120 |
-
}
|
| 121 |
-
|
| 122 |
-
.footer-text {
|
| 123 |
-
text-align: center;
|
| 124 |
-
color: #666;
|
| 125 |
-
margin-top: 2rem;
|
| 126 |
-
padding: 1rem;
|
| 127 |
-
font-size: 0.9rem;
|
| 128 |
-
}
|
| 129 |
-
"""
|
| 130 |
-
|
| 131 |
-
with gr.Blocks(title="SmolLM2-135M Dissecting Demo", css=css) as demo:
|
| 132 |
-
with gr.Column(elem_id="header"):
|
| 133 |
-
gr.Markdown("# π¬ SmolLM2-135M Dissecting Demo")
|
| 134 |
-
gr.Markdown("A custom implementation of SmolLM2-135M trained from scratch with 147.8M parameters. Explore the power of transformer architecture!")
|
| 135 |
-
|
| 136 |
with gr.Row():
|
| 137 |
-
with gr.Column(
|
| 138 |
-
prompt_input = gr.Textbox(
|
| 139 |
-
lines=3,
|
| 140 |
-
placeholder="Start typing your prompt... (e.g., 'In a distant galaxy')",
|
| 141 |
-
label="π Your Prompt",
|
| 142 |
-
show_label=True
|
| 143 |
-
)
|
| 144 |
with gr.Row():
|
| 145 |
-
max_len_input = gr.Slider(
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
)
|
| 153 |
-
temp_input = gr.Slider(
|
| 154 |
-
minimum=0.1,
|
| 155 |
-
maximum=2.0,
|
| 156 |
-
value=0.8,
|
| 157 |
-
step=0.1,
|
| 158 |
-
label="π‘οΈ Temperature",
|
| 159 |
-
info="Higher = more creative, Lower = more focused"
|
| 160 |
-
)
|
| 161 |
-
generate_btn = gr.Button("β¨ Generate Text", variant="primary", elem_classes="generate-btn", size="lg")
|
| 162 |
-
|
| 163 |
-
with gr.Column(scale=1):
|
| 164 |
-
output_text = gr.Textbox(
|
| 165 |
-
label="π― Generated Output",
|
| 166 |
-
lines=12,
|
| 167 |
-
elem_id="output-box",
|
| 168 |
-
show_copy_button=True
|
| 169 |
-
)
|
| 170 |
-
|
| 171 |
generate_btn.click(
|
| 172 |
fn=generate_text,
|
| 173 |
inputs=[prompt_input, max_len_input, temp_input],
|
| 174 |
outputs=output_text
|
| 175 |
)
|
| 176 |
-
|
| 177 |
-
# Add examples
|
| 178 |
-
gr.Markdown("### π‘ Try these examples:")
|
| 179 |
gr.Examples(
|
| 180 |
examples=[
|
| 181 |
["Once upon a time in a kingdom far away"],
|
|
@@ -185,19 +109,7 @@ with gr.Blocks(title="SmolLM2-135M Dissecting Demo", css=css) as demo:
|
|
| 185 |
["The old wizard looked at me and said"],
|
| 186 |
["A long time ago, in a galaxy"]
|
| 187 |
],
|
| 188 |
-
inputs=prompt_input
|
| 189 |
-
label="Click any example to try it out"
|
| 190 |
-
)
|
| 191 |
-
|
| 192 |
-
# Footer
|
| 193 |
-
gr.Markdown(
|
| 194 |
-
"""
|
| 195 |
-
<div class="footer-text">
|
| 196 |
-
<p>π Educational Model | π 5,000 Training Steps | π§ 30 Transformer Layers</p>
|
| 197 |
-
<p>Built with PyTorch β’ Rotary Position Embeddings β’ SwiGLU Activation</p>
|
| 198 |
-
</div>
|
| 199 |
-
""",
|
| 200 |
-
elem_classes="footer-text"
|
| 201 |
)
|
| 202 |
|
| 203 |
if __name__ == "__main__":
|
|
|
|
| 77 |
traceback.print_exc()
|
| 78 |
return f"Error during generation: {str(e)}"
|
| 79 |
|
| 80 |
+
# Gradio Interface
|
| 81 |
+
with gr.Blocks(title="SmolLM2-135M Dissecting Demo") as demo:
|
| 82 |
+
gr.Markdown("# SmolLM2-135M Dissecting Demo")
|
| 83 |
+
gr.Markdown("A custom implementation of SmolLM2-135M trained from scratch. Enter a prompt to see what it generates!")
|
| 84 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 85 |
with gr.Row():
|
| 86 |
+
with gr.Column():
|
| 87 |
+
prompt_input = gr.Textbox(lines=2, placeholder="Enter your prompt here...", label="Prompt")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 88 |
with gr.Row():
|
| 89 |
+
max_len_input = gr.Slider(minimum=10, maximum=200, value=50, step=10, label="Max Length")
|
| 90 |
+
temp_input = gr.Slider(minimum=0.1, maximum=2.0, value=0.8, step=0.1, label="Temperature")
|
| 91 |
+
generate_btn = gr.Button("Generate", variant="primary")
|
| 92 |
+
|
| 93 |
+
with gr.Column():
|
| 94 |
+
output_text = gr.Textbox(label="Generated Text", lines=10)
|
| 95 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 96 |
generate_btn.click(
|
| 97 |
fn=generate_text,
|
| 98 |
inputs=[prompt_input, max_len_input, temp_input],
|
| 99 |
outputs=output_text
|
| 100 |
)
|
| 101 |
+
|
| 102 |
+
# Add examples
|
|
|
|
| 103 |
gr.Examples(
|
| 104 |
examples=[
|
| 105 |
["Once upon a time in a kingdom far away"],
|
|
|
|
| 109 |
["The old wizard looked at me and said"],
|
| 110 |
["A long time ago, in a galaxy"]
|
| 111 |
],
|
| 112 |
+
inputs=prompt_input
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 113 |
)
|
| 114 |
|
| 115 |
if __name__ == "__main__":
|