CultriX commited on
Commit
548eda9
1 Parent(s): 5f8cec7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -21
app.py CHANGED
@@ -1,4 +1,3 @@
1
- # Import necessary libraries
2
  import gradio as gr
3
  import sys
4
  from huggingface_hub import ModelCard, HfApi
@@ -24,19 +23,19 @@ MODEL_ID = "mlabonne/NeuralBeagle14-7B"
24
 
25
  # Define a class to cache model cards
26
  class CachedModelCard(ModelCard):
27
- _cache = {}
28
-
29
- @classmethod
30
- def load(cls, model_id: str, **kwargs) -> "ModelCard":
31
- if model_id not in cls._cache:
32
- try:
33
- print('REQUEST ModelCard:', model_id)
34
- cls._cache[model_id] = super().load(model_id, **kwargs)
35
- except:
36
- cls._cache[model_id] = None
37
- else:
38
- print('CACHED:', model_id)
39
- return cls._cache[model_id]
40
 
41
  # Function to get model names from a YAML file
42
  def get_model_names_from_yaml(url):
@@ -65,7 +64,7 @@ def get_license_color(model):
65
  print(f"Error retrieving license for {model}: {e}")
66
  return 'lightgray'
67
 
68
-
69
  # Function to find model names in the family tree
70
  def get_model_names(model, genealogy, found_models=None, visited_models=None):
71
  print('---')
@@ -138,7 +137,7 @@ def calculate_width_at_depth(G, root):
138
  queue.append((child, depth + 1))
139
  return depth_count
140
 
141
-
142
  # Function to create the family tree
143
  def create_family_tree(start_model):
144
  genealogy = defaultdict(list)
@@ -189,7 +188,7 @@ def create_family_tree(start_model):
189
  plt.legend(handles=legend_elements, loc='upper left')
190
 
191
  plt.title(f"{start_model}'s Family Tree", fontsize=20)
192
-
193
  # Capture the plot as an image in memory
194
  img_buffer = BytesIO()
195
  plt.savefig(img_buffer, format='png', bbox_inches='tight')
@@ -200,7 +199,7 @@ def create_family_tree(start_model):
200
  img = Image.open(img_buffer)
201
 
202
  return img
203
-
204
  with gr.Blocks() as demo:
205
  gr.Markdown(TITLE)
206
  model_id = gr.Textbox(label="Model ID", value="mlabonne/NeuralBeagle14-7B")
@@ -209,8 +208,6 @@ with gr.Blocks() as demo:
209
  btn.click(fn=create_family_tree, inputs=model_id, outputs=out)
210
 
211
  demo.queue(api_open=False).launch(show_api=False)
212
-
213
-
214
- create_family_tree(MODEL_ID)
215
 
216
 
 
 
 
1
  import gradio as gr
2
  import sys
3
  from huggingface_hub import ModelCard, HfApi
 
23
 
24
  # Define a class to cache model cards
25
  class CachedModelCard(ModelCard):
26
+ _cache = {}
27
+
28
+ @classmethod
29
+ def load(cls, model_id: str, **kwargs) -> "ModelCard":
30
+ if model_id not in cls._cache:
31
+ try:
32
+ print('REQUEST ModelCard:', model_id)
33
+ cls._cache[model_id] = super().load(model_id, **kwargs)
34
+ except:
35
+ cls._cache[model_id] = None
36
+ else:
37
+ print('CACHED:', model_id)
38
+ return cls._cache[model_id]
39
 
40
  # Function to get model names from a YAML file
41
  def get_model_names_from_yaml(url):
 
64
  print(f"Error retrieving license for {model}: {e}")
65
  return 'lightgray'
66
 
67
+
68
  # Function to find model names in the family tree
69
  def get_model_names(model, genealogy, found_models=None, visited_models=None):
70
  print('---')
 
137
  queue.append((child, depth + 1))
138
  return depth_count
139
 
140
+
141
  # Function to create the family tree
142
  def create_family_tree(start_model):
143
  genealogy = defaultdict(list)
 
188
  plt.legend(handles=legend_elements, loc='upper left')
189
 
190
  plt.title(f"{start_model}'s Family Tree", fontsize=20)
191
+
192
  # Capture the plot as an image in memory
193
  img_buffer = BytesIO()
194
  plt.savefig(img_buffer, format='png', bbox_inches='tight')
 
199
  img = Image.open(img_buffer)
200
 
201
  return img
202
+
203
  with gr.Blocks() as demo:
204
  gr.Markdown(TITLE)
205
  model_id = gr.Textbox(label="Model ID", value="mlabonne/NeuralBeagle14-7B")
 
208
  btn.click(fn=create_family_tree, inputs=model_id, outputs=out)
209
 
210
  demo.queue(api_open=False).launch(show_api=False)
 
 
 
211
 
212
 
213
+ create_family_tree(MODEL_ID)