Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -11,7 +11,6 @@ client = OpenAI(
|
|
| 11 |
)
|
| 12 |
print("OpenAI client initialized.")
|
| 13 |
|
| 14 |
-
|
| 15 |
def respond(
|
| 16 |
message,
|
| 17 |
history: list[tuple[str, str]],
|
|
@@ -23,6 +22,7 @@ def respond(
|
|
| 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,23 +77,12 @@ def respond(
|
|
| 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,14 +120,13 @@ seed_slider = gr.Slider(
|
|
| 131 |
label="Seed (-1 for random)"
|
| 132 |
)
|
| 133 |
|
| 134 |
-
#
|
| 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,7 +136,6 @@ def set_custom_model_from_radio(selected):
|
|
| 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,7 +145,6 @@ demo = gr.ChatInterface(
|
|
| 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,11 +152,10 @@ demo = gr.ChatInterface(
|
|
| 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
|
| 173 |
-
custom_model_box
|
| 174 |
|
| 175 |
model_search_box = gr.Textbox(
|
| 176 |
label="Filter Models",
|
|
@@ -232,4 +217,4 @@ print("Gradio interface initialized.")
|
|
| 232 |
|
| 233 |
if __name__ == "__main__":
|
| 234 |
print("Launching the demo application.")
|
| 235 |
-
demo.
|
|
|
|
| 11 |
)
|
| 12 |
print("OpenAI client initialized.")
|
| 13 |
|
|
|
|
| 14 |
def respond(
|
| 15 |
message,
|
| 16 |
history: list[tuple[str, str]],
|
|
|
|
| 22 |
seed,
|
| 23 |
custom_model
|
| 24 |
):
|
| 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 |
# GRADIO UI
|
| 81 |
|
| 82 |
+
chatbot = gr.Chatbot(height=600, show_copy_button=True, placeholder="Select a model and begin chatting", likeable=True, layout="panel")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 83 |
print("Chatbot interface created.")
|
| 84 |
|
| 85 |
+
system_message_box = gr.Textbox(value="", placeholder="You are a helpful assistant.", label="System Prompt")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 86 |
|
| 87 |
max_tokens_slider = gr.Slider(
|
| 88 |
minimum=1,
|
|
|
|
| 120 |
label="Seed (-1 for random)"
|
| 121 |
)
|
| 122 |
|
| 123 |
+
# The custom_model_box is moved here to be at the top of the Model Selection accordion
|
| 124 |
custom_model_box = gr.Textbox(
|
| 125 |
value="",
|
| 126 |
label="Custom Model",
|
| 127 |
info="(Optional) Provide a custom Hugging Face model path. Overrides any selected featured model.",
|
| 128 |
placeholder="meta-llama/Llama-3.3-70B-Instruct"
|
| 129 |
)
|
|
|
|
| 130 |
|
| 131 |
def set_custom_model_from_radio(selected):
|
| 132 |
"""
|
|
|
|
| 136 |
print(f"Featured model selected: {selected}")
|
| 137 |
return selected
|
| 138 |
|
|
|
|
| 139 |
demo = gr.ChatInterface(
|
| 140 |
fn=respond,
|
| 141 |
additional_inputs=[
|
|
|
|
| 145 |
top_p_slider,
|
| 146 |
frequency_penalty_slider,
|
| 147 |
seed_slider,
|
|
|
|
| 148 |
],
|
| 149 |
fill_height=True,
|
| 150 |
chatbot=chatbot,
|
|
|
|
| 152 |
)
|
| 153 |
print("ChatInterface object created.")
|
| 154 |
|
|
|
|
| 155 |
with demo:
|
| 156 |
with gr.Accordion("Model Selection", open=False):
|
| 157 |
+
# Place custom_model_box at the top of the accordion
|
| 158 |
+
custom_model_box.render()
|
| 159 |
|
| 160 |
model_search_box = gr.Textbox(
|
| 161 |
label="Filter Models",
|
|
|
|
| 217 |
|
| 218 |
if __name__ == "__main__":
|
| 219 |
print("Launching the demo application.")
|
| 220 |
+
demo.launch()
|