francismurray commited on
Commit
12c8918
·
1 Parent(s): d85e33e

display models cards

Browse files
Files changed (1) hide show
  1. app.py +58 -1
app.py CHANGED
@@ -2,7 +2,7 @@ import os
2
  import gradio as gr
3
  import asyncio
4
  from dotenv import load_dotenv
5
- from huggingface_hub import InferenceClient
6
  from functools import partial
7
 
8
  # Load environment variables
@@ -24,6 +24,29 @@ AVAILABLE_MODELS = [
24
  # Initialize inference client
25
  inference_client = InferenceClient(token=HF_TOKEN)
26
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27
  async def get_model_response(prompt, model_name, temperature_value, do_sample, max_tokens):
28
  """Get response from a Hugging Face model."""
29
  try:
@@ -133,6 +156,18 @@ def update_slider_state(enabled):
133
  # Create the Gradio interface
134
  with gr.Blocks(css="""
135
  .disabled-slider { opacity: 0.5; pointer-events: none; }
 
 
 
 
 
 
 
 
 
 
 
 
136
  """) as demo:
137
  gr.Markdown("# LLM Comparison Tool")
138
  gr.Markdown("Using HuggingFace's Inference API, compare outputs from different `text-generation` models side by side.")
@@ -154,6 +189,10 @@ with gr.Blocks(css="""
154
  value=AVAILABLE_MODELS[0],
155
  label="Select Model 1"
156
  )
 
 
 
 
157
  do_sample1 = gr.Checkbox(
158
  label="Enable sampling (random outputs)",
159
  value=False
@@ -187,6 +226,10 @@ with gr.Blocks(css="""
187
  value=AVAILABLE_MODELS[1],
188
  label="Select Model 2"
189
  )
 
 
 
 
190
  do_sample2 = gr.Checkbox(
191
  label="Enable sampling (random outputs)",
192
  value=False
@@ -230,6 +273,20 @@ with gr.Blocks(css="""
230
  queue=True # Enable queuing for streaming updates
231
  )
232
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
233
  do_sample1.change(
234
  fn=update_slider_state,
235
  inputs=[do_sample1],
 
2
  import gradio as gr
3
  import asyncio
4
  from dotenv import load_dotenv
5
+ from huggingface_hub import InferenceClient, hf_hub_download, model_info
6
  from functools import partial
7
 
8
  # Load environment variables
 
24
  # Initialize inference client
25
  inference_client = InferenceClient(token=HF_TOKEN)
26
 
27
+ def get_model_card_html(model_name, title):
28
+ """Fetch and format model card information."""
29
+ try:
30
+ info = model_info(model_name, token=HF_TOKEN)
31
+
32
+ return f"""
33
+ <div class="model-card-container">
34
+ <h3>{info.modelId}</h3>
35
+ <p><strong>Pipeline Tag:</strong> {info.pipeline_tag or 'Not specified'}</p>
36
+ <p><strong>Downloads:</strong> {info.downloads:,}</p>
37
+ <p><strong>Likes:</strong> {info.likes:,}</p>
38
+ <p><a href="https://huggingface.co/{model_name}" target="_blank">View on Hugging Face</a></p>
39
+ </div>
40
+ """
41
+ except Exception as e:
42
+ return f"""
43
+ <div class="model-card-container">
44
+ <h3>{model_name}</h3>
45
+ <p>Unable to load full model card information.</p>
46
+ <p><a href="https://huggingface.co/{model_name}" target="_blank">View on Hugging Face</a></p>
47
+ </div>
48
+ """
49
+
50
  async def get_model_response(prompt, model_name, temperature_value, do_sample, max_tokens):
51
  """Get response from a Hugging Face model."""
52
  try:
 
156
  # Create the Gradio interface
157
  with gr.Blocks(css="""
158
  .disabled-slider { opacity: 0.5; pointer-events: none; }
159
+ .model-card-container {
160
+ background-color: #f8f9fa;
161
+ font-size: 14px;
162
+ color: #666;
163
+ }
164
+ .model-card-container h3 {
165
+ margin: 0;
166
+ color: black;
167
+ }
168
+ .model-card-container p {
169
+ margin: 5px 0;
170
+ }
171
  """) as demo:
172
  gr.Markdown("# LLM Comparison Tool")
173
  gr.Markdown("Using HuggingFace's Inference API, compare outputs from different `text-generation` models side by side.")
 
189
  value=AVAILABLE_MODELS[0],
190
  label="Select Model 1"
191
  )
192
+ model1_card = gr.HTML(
193
+ value=get_model_card_html(AVAILABLE_MODELS[0], "Model 1 Information"),
194
+ elem_classes=["model-card-container"]
195
+ )
196
  do_sample1 = gr.Checkbox(
197
  label="Enable sampling (random outputs)",
198
  value=False
 
226
  value=AVAILABLE_MODELS[1],
227
  label="Select Model 2"
228
  )
229
+ model2_card = gr.HTML(
230
+ value=get_model_card_html(AVAILABLE_MODELS[1], "Model 2 Information"),
231
+ elem_classes=["model-card-container"]
232
+ )
233
  do_sample2 = gr.Checkbox(
234
  label="Enable sampling (random outputs)",
235
  value=False
 
273
  queue=True # Enable queuing for streaming updates
274
  )
275
 
276
+ # Update model cards when models are changed
277
+ model1_dropdown.change(
278
+ fn=lambda x: get_model_card_html(x, "Model 1 Information"),
279
+ inputs=[model1_dropdown],
280
+ outputs=[model1_card]
281
+ )
282
+
283
+ model2_dropdown.change(
284
+ fn=lambda x: get_model_card_html(x, "Model 2 Information"),
285
+ inputs=[model2_dropdown],
286
+ outputs=[model2_card]
287
+ )
288
+
289
+ # Existing event handlers
290
  do_sample1.change(
291
  fn=update_slider_state,
292
  inputs=[do_sample1],