MekkCyber commited on
Commit
ca0db66
Β·
1 Parent(s): 80c526e
Files changed (1) hide show
  1. app.py +46 -4
app.py CHANGED
@@ -190,11 +190,52 @@ def save_model(
190
 
191
  # Format it for display in markdown with proper styling
192
  model_architecture_info = f"""
193
- <div class="model-architecture" style="max-height: 500px; overflow-y: auto; overflow-x: auto; background-color: #f5f5f5; padding: 5px; border-radius: 8px; font-family: monospace; white-space: pre-wrap;">
 
 
194
  <div style="line-height: 1.2; font-size: 0.75em;">{model_architecture_str_html}</div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
195
  </div>
196
  """
197
- return f'πŸŽ‰ Quantized Model <br/><h1> πŸš€ DONE</h1><br/>Find your repo here: <a href="https://huggingface.co/{repo_name}" target="_blank" style="text-decoration:underline">{repo_name}</a><br/><br/>πŸ“‹ Model Architecture<br/>{model_architecture_info}<br/><br/>πŸ“¦ Model Size <br/><br/> Original (bf16)β‰ˆ {original_size_gb} GB β†’ Quantized β‰ˆ {get_model_size(model)} GB'
 
 
 
 
 
 
 
198
 
199
 
200
  def quantize_and_save(
@@ -508,7 +549,8 @@ with gr.Blocks(theme=gr.themes.Ocean(), css=css) as demo:
508
  # πŸ€— BitsAndBytes Quantizer : Create your own BNB Quants ! ✨
509
 
510
 
511
-
 
512
  """
513
  )
514
 
@@ -597,7 +639,7 @@ with gr.Blocks(theme=gr.themes.Ocean(), css=css) as demo:
597
  "πŸš€ Quantize and Push to the Hub", variant="primary"
598
  )
599
  output_link = gr.Markdown(
600
- "πŸ”— Quantized Model", container=True, min_height=100
601
  )
602
 
603
  quantize_button.click(
 
190
 
191
  # Format it for display in markdown with proper styling
192
  model_architecture_info = f"""
193
+ <div class="model-architecture-container" style="margin-top: 20px; margin-bottom: 20px; background-color: #f8f9fa; padding: 15px; border-radius: 8px; border-left: 4px solid #4CAF50;">
194
+ <h3 style="margin-top: 0; color: #2E7D32;">πŸ“‹ Model Architecture</h3>
195
+ <div class="model-architecture" style="max-height: 500px; overflow-y: auto; overflow-x: auto; background-color: #f5f5f5; padding: 5px; border-radius: 8px; font-family: monospace; white-space: pre-wrap;">
196
  <div style="line-height: 1.2; font-size: 0.75em;">{model_architecture_str_html}</div>
197
+ </div>
198
+ </div>
199
+ """
200
+
201
+ code = f"""
202
+ from transformers import AutoModelForCausalLM, AutoTokenizer
203
+ import torch
204
+
205
+ model = AutoModelForCausalLM.from_pretrained(
206
+ "{repo_name}",
207
+ device_map="auto"
208
+ )
209
+
210
+ tokenizer = AutoTokenizer.from_pretrained("{model_name}")
211
+
212
+ inputs = tokenizer("Hello, my name is", return_tensors="pt").to(model.device)
213
+ outputs = model.generate(inputs.input_ids, max_length=50)
214
+ print(tokenizer.decode(outputs[0], skip_special_tokens=True))
215
+ """
216
+ # First replace newlines in the code
217
+ code_html = code.replace("\n", "<br/>")
218
+
219
+ usage_example = f"""
220
+ <div class="usage-example" style="margin-top: 20px; margin-bottom: 20px; background-color: #f8f9fa; padding: 15px; border-radius: 8px; border-left: 4px solid #4CAF50;">
221
+ <h3 style="margin-top: 0; color: #2E7D32;">πŸ“ How to use this model</h3>
222
+ <div class="model-architecture" style="max-height: 500px; overflow-y: auto; overflow-x: auto; background-color: #f5f5f5; padding: 5px; border-radius: 8px; font-family: monospace; font-size: 0.75em; white-space: pre-wrap;">{code_html}</div>
223
+ </div>
224
+ """
225
+ model_size_info = f"""
226
+ <div class="model-size-info" style="margin-top: 20px; margin-bottom: 20px; background-color: #f8f9fa; padding: 15px; border-radius: 8px; border-left: 4px solid #4CAF50;">
227
+ <h3 style="margin-top: 0; color: #2E7D32;">πŸ“¦ Model Size</h3>
228
+ <p>Original (bf16)β‰ˆ {original_size_gb} GB β†’ Quantized β‰ˆ {get_model_size(model)} GB</p>
229
  </div>
230
  """
231
+
232
+ repo_link = f"""
233
+ <div class="repo-link" style="margin-top: 20px; margin-bottom: 20px; background-color: #f8f9fa; padding: 15px; border-radius: 8px; border-left: 4px solid #4CAF50;">
234
+ <h3 style="margin-top: 0; color: #2E7D32;">πŸ”— Repository Link</h3>
235
+ <p>Find your repo here: <a href="https://huggingface.co/{repo_name}" target="_blank" style="text-decoration:underline">{repo_name}</a></p>
236
+ </div>
237
+ """
238
+ return f'<h1>πŸŽ‰ Quantization Completed</h1><br/>{repo_link}{model_architecture_info}{model_size_info}{usage_example}'
239
 
240
 
241
  def quantize_and_save(
 
549
  # πŸ€— BitsAndBytes Quantizer : Create your own BNB Quants ! ✨
550
 
551
 
552
+ <br/>
553
+ <br/>
554
  """
555
  )
556
 
 
639
  "πŸš€ Quantize and Push to the Hub", variant="primary"
640
  )
641
  output_link = gr.Markdown(
642
+ "πŸ”— Quantized Model Info", container=True, min_height=200
643
  )
644
 
645
  quantize_button.click(