Files changed (1) hide show
  1. app.py +48 -0
app.py CHANGED
@@ -10,6 +10,32 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
10
 
11
  # --- Basic Agent Definition ---
12
  # ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
  class BasicAgent:
14
  def __init__(self):
15
  print("BasicAgent initialized.")
@@ -48,6 +74,28 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
48
  agent_code = f"https://huggingface.co/spaces/{space_id}/tree/main"
49
  print(agent_code)
50
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
51
  # 2. Fetch Questions
52
  print(f"Fetching questions from: {questions_url}")
53
  try:
 
10
 
11
  # --- Basic Agent Definition ---
12
  # ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
13
+ try:
14
+ # 1. Extract the standard ML task (e.g., "text-classification")
15
+ task = extract_task(user_query)
16
+
17
+ # 2. Get relevant models for the task
18
+ models = scrape_huggingface_models(task)
19
+
20
+ if not models:
21
+ return f"❌ No models found for task `{task}`. Try refining your query."
22
+
23
+ # 3. Format response as a markdown table
24
+ response = f"### πŸ” Models for task: `{task}`\n\n"
25
+ response += "| Model Name | Task | Architecture |\n"
26
+ response += "|------------|------|---------------|\n"
27
+
28
+ for model in models:
29
+ name = model.get("model_name", "unknown")
30
+ task_name = model.get("task", "unknown")
31
+ arch = model.get("architecture", "unknown")
32
+ response += f"| [{name}](https://huggingface.co/{name}) | {task_name} | {arch} |\n"
33
+
34
+ return response
35
+
36
+ except Exception as e:
37
+ return f"❌ Error: {str(e)}"
38
+
39
  class BasicAgent:
40
  def __init__(self):
41
  print("BasicAgent initialized.")
 
74
  agent_code = f"https://huggingface.co/spaces/{space_id}/tree/main"
75
  print(agent_code)
76
 
77
+ # Gradio interface for deployment
78
+ def gradio_ui():
79
+ with gr.Blocks() as demo:
80
+ gr.Markdown("# Hugging Face Model Finder Agent")
81
+ gr.Markdown("Enter a task description, and I'll find suitable ML models for you!")
82
+
83
+ # User input for task description
84
+ user_input = gr.Textbox(label="Describe the ML Task", placeholder="e.g., 'I need a text summarization model'", lines=2)
85
+
86
+ # Output for model search results
87
+ output = gr.Markdown()
88
+
89
+ # Connect the input/output to the agent
90
+ user_input.submit(run_agent, inputs=user_input, outputs=output)
91
+
92
+ return demo
93
+
94
+ # Run the Gradio interface (will run locally, and can be deployed to Spaces)
95
+ if __name__ == "__main__":
96
+ gradio_ui().launch()
97
+
98
+
99
  # 2. Fetch Questions
100
  print(f"Fetching questions from: {questions_url}")
101
  try: