Update app.py
Browse files
app.py
CHANGED
@@ -26,16 +26,22 @@ def normalize(values):
|
|
26 |
min_val, max_val = min(values), max(values)
|
27 |
return [(v - min_val) / (max_val - min_val) if max_val > min_val else 0 for v in values]
|
28 |
|
29 |
-
# Function to get weighted recommendations based on
|
30 |
-
def get_weighted_recommendations_from_hf(
|
31 |
if weights is None:
|
32 |
weights = {"similarity": 0.7, "downloads": 0.2, "likes": 0.1}
|
33 |
|
34 |
model_data = fetch_models_from_hf(task_filter)
|
35 |
|
|
|
|
|
|
|
36 |
model_ids = [model["model_id"] for model in model_data]
|
37 |
model_tags = [' '.join(model["tags"]) for model in model_data]
|
38 |
|
|
|
|
|
|
|
39 |
model_embeddings = semantic_model.encode(model_tags)
|
40 |
user_embedding = semantic_model.encode(user_query)
|
41 |
|
@@ -63,21 +69,20 @@ def get_weighted_recommendations_from_hf(user_query, task_filter, weights=None):
|
|
63 |
return '\n'.join(result)
|
64 |
|
65 |
# Gradio chatbot interface
|
66 |
-
def respond(
|
67 |
-
# Provide model recommendations based on the
|
68 |
-
return get_weighted_recommendations_from_hf(
|
69 |
|
70 |
# Gradio Interface
|
71 |
demo = gr.Interface(
|
72 |
fn=respond,
|
73 |
inputs=[
|
74 |
-
gr.Textbox(label="Enter your query", placeholder="What kind of model are you looking for?"),
|
75 |
gr.Textbox(label="Task Filter", placeholder="Enter the task, e.g., text-classification"),
|
76 |
gr.Textbox(value="You are using the Hugging Face model recommender system.", label="System message")
|
77 |
],
|
78 |
outputs=gr.Textbox(label="Model Recommendations"),
|
79 |
title="Hugging Face Model Recommender",
|
80 |
-
description="This chatbot recommends models from Hugging Face based on
|
81 |
)
|
82 |
|
83 |
if __name__ == "__main__":
|
|
|
26 |
min_val, max_val = min(values), max(values)
|
27 |
return [(v - min_val) / (max_val - min_val) if max_val > min_val else 0 for v in values]
|
28 |
|
29 |
+
# Function to get weighted recommendations based on task filter and additional metrics
|
30 |
+
def get_weighted_recommendations_from_hf(task_filter, weights=None):
|
31 |
if weights is None:
|
32 |
weights = {"similarity": 0.7, "downloads": 0.2, "likes": 0.1}
|
33 |
|
34 |
model_data = fetch_models_from_hf(task_filter)
|
35 |
|
36 |
+
if len(model_data) == 0:
|
37 |
+
return "No models found for the specified task filter."
|
38 |
+
|
39 |
model_ids = [model["model_id"] for model in model_data]
|
40 |
model_tags = [' '.join(model["tags"]) for model in model_data]
|
41 |
|
42 |
+
# Use a fixed user query based on task filter
|
43 |
+
user_query = f"best model for {task_filter}"
|
44 |
+
|
45 |
model_embeddings = semantic_model.encode(model_tags)
|
46 |
user_embedding = semantic_model.encode(user_query)
|
47 |
|
|
|
69 |
return '\n'.join(result)
|
70 |
|
71 |
# Gradio chatbot interface
|
72 |
+
def respond(task_filter, history=None, weights=None):
|
73 |
+
# Provide model recommendations based on the task filter
|
74 |
+
return get_weighted_recommendations_from_hf(task_filter, weights)
|
75 |
|
76 |
# Gradio Interface
|
77 |
demo = gr.Interface(
|
78 |
fn=respond,
|
79 |
inputs=[
|
|
|
80 |
gr.Textbox(label="Task Filter", placeholder="Enter the task, e.g., text-classification"),
|
81 |
gr.Textbox(value="You are using the Hugging Face model recommender system.", label="System message")
|
82 |
],
|
83 |
outputs=gr.Textbox(label="Model Recommendations"),
|
84 |
title="Hugging Face Model Recommender",
|
85 |
+
description="This chatbot recommends models from Hugging Face based on the task you're interested in."
|
86 |
)
|
87 |
|
88 |
if __name__ == "__main__":
|