K00B404 commited on
Commit
ff6be41
·
verified ·
1 Parent(s): e358e48

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -22
app.py CHANGED
@@ -50,29 +50,14 @@ def get_prompt(name):
50
  """Retrieve a system prompt by name."""
51
  return system_prompts.get(name, "")
52
 
53
-
54
- def update_dropdown_choices(models):
55
- """Update dropdown choices dynamically."""
56
- if not models:
57
- return [], None # Return empty choices and no default value
58
- return models, models[0]
59
-
60
-
61
-
62
  def fetch_models(task):
63
  """Fetch models for a specific task from Hugging Face Hub."""
64
  try:
65
  models = list_models(filter=f"pipeline_tags:{task}")
66
- models += [
67
- "HuggingFaceH4/zephyr-7b-beta",
68
- "HuggingFaceH4/zephyr-7b-alpha",
69
- "HuggingFaceH4/zephyr-6b"
70
- ]
71
-
72
  return [model.modelId for model in models]
73
  except Exception as e:
74
  return [f"Error fetching models: {str(e)}"]
75
- task_choices=["text-generation", "image-classification", "text-classification", "translation"]
76
  # Gradio Interface
77
  with gr.Blocks() as demo:
78
  gr.Markdown("## Hugging Face Chatbot with Dynamic Model Selection")
@@ -81,16 +66,13 @@ with gr.Blocks() as demo:
81
  with gr.Column():
82
  # Task selection
83
  task_selector = gr.Dropdown(
84
- choices=task_choices,
85
  label="Select Task",
86
  value="text-generation"
87
  )
88
- models=fetch_models(task_choices[0])
89
  # Model selector
90
  model_selector = gr.Dropdown(choices=[], label="Select Model")
91
- # Example of handling model updates
92
- model_selector.choices = models
93
- model_selector.value = models[0]
94
 
95
  # System prompt and input
96
  system_prompt_name = gr.Dropdown(choices=list(system_prompts.keys()), label="Select System Prompt")
@@ -114,4 +96,4 @@ with gr.Blocks() as demo:
114
  submit_button.click(chat_with_model, inputs=[user_input, system_prompt_content, model_selector], outputs=[output])
115
 
116
  # Run the app
117
- demo.launch()
 
50
  """Retrieve a system prompt by name."""
51
  return system_prompts.get(name, "")
52
 
 
 
 
 
 
 
 
 
 
53
  def fetch_models(task):
54
  """Fetch models for a specific task from Hugging Face Hub."""
55
  try:
56
  models = list_models(filter=f"pipeline_tags:{task}")
 
 
 
 
 
 
57
  return [model.modelId for model in models]
58
  except Exception as e:
59
  return [f"Error fetching models: {str(e)}"]
60
+
61
  # Gradio Interface
62
  with gr.Blocks() as demo:
63
  gr.Markdown("## Hugging Face Chatbot with Dynamic Model Selection")
 
66
  with gr.Column():
67
  # Task selection
68
  task_selector = gr.Dropdown(
69
+ choices=["text-generation", "image-classification", "text-classification", "translation"],
70
  label="Select Task",
71
  value="text-generation"
72
  )
73
+
74
  # Model selector
75
  model_selector = gr.Dropdown(choices=[], label="Select Model")
 
 
 
76
 
77
  # System prompt and input
78
  system_prompt_name = gr.Dropdown(choices=list(system_prompts.keys()), label="Select System Prompt")
 
96
  submit_button.click(chat_with_model, inputs=[user_input, system_prompt_content, model_selector], outputs=[output])
97
 
98
  # Run the app
99
+ demo.launch()