Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -21,18 +21,29 @@ TASK_ALIASES = {
|
|
21 |
def normalize_task(task):
|
22 |
return TASK_ALIASES.get(task.lower(), task)
|
23 |
|
|
|
24 |
# π Extract task from user input
|
25 |
def extract_task(user_input):
|
26 |
prompt = (
|
27 |
-
"
|
28 |
-
"from the following
|
29 |
-
"translation, summarization,
|
30 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
)
|
32 |
result = task_extractor(prompt, max_new_tokens=10)
|
33 |
task = result[0]["generated_text"].strip().lower()
|
34 |
return normalize_task(task)
|
35 |
|
|
|
36 |
# π Scrape models from Hugging Face
|
37 |
def get_models_for_task(task):
|
38 |
url = f"https://huggingface.co/models?pipeline_tag={task}"
|
|
|
21 |
def normalize_task(task):
|
22 |
return TASK_ALIASES.get(task.lower(), task)
|
23 |
|
24 |
+
#
|
25 |
# π Extract task from user input
|
26 |
def extract_task(user_input):
|
27 |
prompt = (
|
28 |
+
"You are a helpful AI assistant. Your job is to identify the correct Hugging Face model task "
|
29 |
+
"based on the user's request. Choose one from the following official tasks:\n"
|
30 |
+
"text-classification, token-classification, translation, summarization, object-detection, "
|
31 |
+
"image-classification, question-answering, zero-shot-classification, conversational.\n\n"
|
32 |
+
"Here are some examples:\n"
|
33 |
+
"- 'Translate French to English' β translation\n"
|
34 |
+
"- 'Summarize this legal document' β summarization\n"
|
35 |
+
"- 'Detect humans in images' β object-detection\n"
|
36 |
+
"- 'Classify news articles about finance' β text-classification\n"
|
37 |
+
"- 'Extract people and organizations from legal documents' β token-classification\n"
|
38 |
+
"- 'Build a chatbot for tourists' β conversational\n\n"
|
39 |
+
f"User request: '{user_input}'\n"
|
40 |
+
"Return only the task name from the list above."
|
41 |
)
|
42 |
result = task_extractor(prompt, max_new_tokens=10)
|
43 |
task = result[0]["generated_text"].strip().lower()
|
44 |
return normalize_task(task)
|
45 |
|
46 |
+
|
47 |
# π Scrape models from Hugging Face
|
48 |
def get_models_for_task(task):
|
49 |
url = f"https://huggingface.co/models?pipeline_tag={task}"
|