Nymbo commited on
Commit
2845063
·
verified ·
1 Parent(s): a05c183

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -6
app.py CHANGED
@@ -23,7 +23,6 @@ def respond(
23
  seed,
24
  custom_model
25
  ):
26
-
27
  print(f"Received message: {message}")
28
  print(f"History: {history}")
29
  print(f"System message: {system_message}")
@@ -78,12 +77,23 @@ def respond(
78
 
79
  print("Completed response generation.")
80
 
 
81
  # GRADIO UI
82
 
83
- chatbot = gr.Chatbot(height=600, show_copy_button=True, placeholder="Select a model and begin chatting", likeable=True, layout="panel")
 
 
 
 
 
 
84
  print("Chatbot interface created.")
85
 
86
- system_message_box = gr.Textbox(value="", placeholder="You are a helpful assistant.", label="System Prompt")
 
 
 
 
87
 
88
  max_tokens_slider = gr.Slider(
89
  minimum=1,
@@ -121,13 +131,14 @@ seed_slider = gr.Slider(
121
  label="Seed (-1 for random)"
122
  )
123
 
124
- # The custom_model_box is what the respond function sees as "custom_model"
125
  custom_model_box = gr.Textbox(
126
  value="",
127
  label="Custom Model",
128
  info="(Optional) Provide a custom Hugging Face model path. Overrides any selected featured model.",
129
  placeholder="meta-llama/Llama-3.3-70B-Instruct"
130
  )
 
131
 
132
  def set_custom_model_from_radio(selected):
133
  """
@@ -137,6 +148,7 @@ def set_custom_model_from_radio(selected):
137
  print(f"Featured model selected: {selected}")
138
  return selected
139
 
 
140
  demo = gr.ChatInterface(
141
  fn=respond,
142
  additional_inputs=[
@@ -146,7 +158,7 @@ demo = gr.ChatInterface(
146
  top_p_slider,
147
  frequency_penalty_slider,
148
  seed_slider,
149
- custom_model_box,
150
  ],
151
  fill_height=True,
152
  chatbot=chatbot,
@@ -154,8 +166,12 @@ demo = gr.ChatInterface(
154
  )
155
  print("ChatInterface object created.")
156
 
 
157
  with demo:
158
  with gr.Accordion("Model Selection", open=False):
 
 
 
159
  model_search_box = gr.Textbox(
160
  label="Filter Models",
161
  placeholder="Search for a featured model...",
@@ -216,4 +232,4 @@ print("Gradio interface initialized.")
216
 
217
  if __name__ == "__main__":
218
  print("Launching the demo application.")
219
- demo.launch()
 
23
  seed,
24
  custom_model
25
  ):
 
26
  print(f"Received message: {message}")
27
  print(f"History: {history}")
28
  print(f"System message: {system_message}")
 
77
 
78
  print("Completed response generation.")
79
 
80
+
81
  # GRADIO UI
82
 
83
+ chatbot = gr.Chatbot(
84
+ height=600,
85
+ show_copy_button=True,
86
+ placeholder="Select a model and begin chatting",
87
+ likeable=True,
88
+ layout="panel",
89
+ )
90
  print("Chatbot interface created.")
91
 
92
+ system_message_box = gr.Textbox(
93
+ value="",
94
+ placeholder="You are a helpful assistant.",
95
+ label="System Prompt"
96
+ )
97
 
98
  max_tokens_slider = gr.Slider(
99
  minimum=1,
 
131
  label="Seed (-1 for random)"
132
  )
133
 
134
+ # 1) Define the Custom Model textbox outside so it can be passed to ChatInterface:
135
  custom_model_box = gr.Textbox(
136
  value="",
137
  label="Custom Model",
138
  info="(Optional) Provide a custom Hugging Face model path. Overrides any selected featured model.",
139
  placeholder="meta-llama/Llama-3.3-70B-Instruct"
140
  )
141
+ print("Custom model box created.")
142
 
143
  def set_custom_model_from_radio(selected):
144
  """
 
148
  print(f"Featured model selected: {selected}")
149
  return selected
150
 
151
+ # 2) Pass it to additional_inputs so `respond` can still receive the value:
152
  demo = gr.ChatInterface(
153
  fn=respond,
154
  additional_inputs=[
 
158
  top_p_slider,
159
  frequency_penalty_slider,
160
  seed_slider,
161
+ custom_model_box, # stays an input to respond
162
  ],
163
  fill_height=True,
164
  chatbot=chatbot,
 
166
  )
167
  print("ChatInterface object created.")
168
 
169
+ # 3) Move the actual UI layout of custom_model_box to the top of the Model Selection accordion:
170
  with demo:
171
  with gr.Accordion("Model Selection", open=False):
172
+ # Place the custom_model_box FIRST in this Accordion
173
+ custom_model_box
174
+
175
  model_search_box = gr.Textbox(
176
  label="Filter Models",
177
  placeholder="Search for a featured model...",
 
232
 
233
  if __name__ == "__main__":
234
  print("Launching the demo application.")
235
+ demo.Launch()