rdave88 commited on
Commit
abdf2b3
Β·
verified Β·
1 Parent(s): 14ca101

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -4
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
- "Given a user query, extract the most likely machine learning task "
28
- "from the following list: text-classification, token-classification, "
29
- "translation, summarization, question-answering, object-detection. "
30
- f"Query: {user_input}. Only return the task name."
 
 
 
 
 
 
 
 
 
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}"