broadfield-dev commited on
Commit
4446b5e
Β·
verified Β·
1 Parent(s): 656c5bd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -7
app.py CHANGED
@@ -30,9 +30,13 @@ try:
30
  print("model_logic.py loaded successfully.")
31
  except ImportError:
32
  print("Warning: Local modules (build_logic.py, model_logic.py) not found. Using dummy functions.")
33
- def get_available_providers(): return ["DummyProvider"]
34
- def get_models_for_provider(p): return ["dummy-model"]
35
- def get_default_model_for_provider(p): return "dummy-model"
 
 
 
 
36
  # The dummy function already accepts the api_key argument ('a')
37
  def generate_stream(p, m, a, msgs):
38
  yield f"Using dummy model. API Key provided: {'Yes' if a else 'No'}. This is a dummy response as local modules were not found."
@@ -724,9 +728,31 @@ with gr.Blocks(theme=custom_theme, css=custom_css) as demo:
724
  load_space_button = gr.Button("πŸ”„ Load Existing Space", variant="secondary")
725
 
726
  with gr.Accordion("πŸ€– AI Model Settings", open=True):
727
- provider_select = gr.Dropdown(label="AI Provider", choices=get_available_providers(), value=get_default_model_for_provider(get_available_providers()[0] if get_available_providers() else 'Groq'))
728
- model_select = gr.Dropdown(label="AI Model", choices=[])
729
- # --- NEW UI ELEMENT ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
730
  provider_api_key_input = gr.Textbox(label="Model Provider API Key (Optional)", type="password", placeholder="sk_... (overrides backend settings)")
731
  system_prompt_input = gr.Textbox(label="System Prompt", lines=10, value=DEFAULT_SYSTEM_PROMPT, elem_id="system-prompt")
732
 
@@ -781,7 +807,6 @@ with gr.Blocks(theme=custom_theme, css=custom_css) as demo:
781
  # --- Event Listeners ---
782
  provider_select.change(update_models_dropdown, inputs=provider_select, outputs=model_select)
783
 
784
- # --- UPDATED chat_inputs LIST ---
785
  chat_inputs = [chat_message_input, chatbot_display, hf_api_key_input, provider_api_key_input, provider_select, model_select, system_prompt_input, owner_name_input, space_name_input]
786
  chat_outputs = [
787
  chat_message_input, chatbot_display, status_output,
 
30
  print("model_logic.py loaded successfully.")
31
  except ImportError:
32
  print("Warning: Local modules (build_logic.py, model_logic.py) not found. Using dummy functions.")
33
+ def get_available_providers(): return ["DummyProvider", "Groq"] # Added Groq for testing
34
+ def get_models_for_provider(p):
35
+ if p == 'Groq': return ["llama3-8b-8192", "gemma-7b-it"]
36
+ return ["dummy-model"]
37
+ def get_default_model_for_provider(p):
38
+ if p == 'Groq': return "llama3-8b-8192"
39
+ return "dummy-model"
40
  # The dummy function already accepts the api_key argument ('a')
41
  def generate_stream(p, m, a, msgs):
42
  yield f"Using dummy model. API Key provided: {'Yes' if a else 'No'}. This is a dummy response as local modules were not found."
 
728
  load_space_button = gr.Button("πŸ”„ Load Existing Space", variant="secondary")
729
 
730
  with gr.Accordion("πŸ€– AI Model Settings", open=True):
731
+ # --- MODIFIED: Set up default provider and model logic on load ---
732
+ available_providers = get_available_providers()
733
+ default_provider = 'Groq'
734
+ # Fallback if 'Groq' is not an option
735
+ if default_provider not in available_providers:
736
+ default_provider = available_providers[0] if available_providers else None
737
+
738
+ # Get initial models and the default model for the selected provider
739
+ initial_models = get_models_for_provider(default_provider) if default_provider else []
740
+ initial_model = get_default_model_for_provider(default_provider) if default_provider else None
741
+ # Fallback for the model as well
742
+ if initial_model not in initial_models:
743
+ initial_model = initial_models[0] if initial_models else None
744
+
745
+ provider_select = gr.Dropdown(
746
+ label="AI Provider",
747
+ choices=available_providers,
748
+ value=default_provider
749
+ )
750
+ model_select = gr.Dropdown(
751
+ label="AI Model",
752
+ choices=initial_models,
753
+ value=initial_model
754
+ )
755
+ # --- END MODIFICATION ---
756
  provider_api_key_input = gr.Textbox(label="Model Provider API Key (Optional)", type="password", placeholder="sk_... (overrides backend settings)")
757
  system_prompt_input = gr.Textbox(label="System Prompt", lines=10, value=DEFAULT_SYSTEM_PROMPT, elem_id="system-prompt")
758
 
 
807
  # --- Event Listeners ---
808
  provider_select.change(update_models_dropdown, inputs=provider_select, outputs=model_select)
809
 
 
810
  chat_inputs = [chat_message_input, chatbot_display, hf_api_key_input, provider_api_key_input, provider_select, model_select, system_prompt_input, owner_name_input, space_name_input]
811
  chat_outputs = [
812
  chat_message_input, chatbot_display, status_output,