Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -24,6 +24,8 @@ def respond(
|
|
24 |
temperature: float,
|
25 |
top_p: float,
|
26 |
):
|
|
|
|
|
27 |
if model_choice not in AVAILABLE_MODELS:
|
28 |
return "Error: Invalid model selection."
|
29 |
|
@@ -68,6 +70,7 @@ def respond(
|
|
68 |
yield f"Error: {str(e)}"
|
69 |
|
70 |
def check_password(input_password):
|
|
|
71 |
if input_password == PASSWORD:
|
72 |
return gr.update(visible=False), gr.update(visible=True)
|
73 |
else:
|
@@ -87,31 +90,27 @@ with gr.Blocks() as demo:
|
|
87 |
system_prompt = gr.Textbox(
|
88 |
value="You are a helpful assistant.", label="System message"
|
89 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
90 |
chat = gr.ChatInterface(
|
91 |
respond,
|
92 |
chatbot=gr.Chatbot(height=400), # Set the desired height here
|
93 |
-
additional_inputs=[system_prompt]
|
94 |
)
|
95 |
|
96 |
-
with gr.Column():
|
97 |
-
model_choice = gr.Dropdown(
|
98 |
-
choices=list(AVAILABLE_MODELS.keys()),
|
99 |
-
value=list(AVAILABLE_MODELS.keys())[0],
|
100 |
-
label="Select Model"
|
101 |
-
)
|
102 |
-
max_tokens = gr.Slider(
|
103 |
-
minimum=1, maximum=30000, value=2048, step=100, label="Max new tokens"
|
104 |
-
)
|
105 |
-
temperature = gr.Slider(
|
106 |
-
minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"
|
107 |
-
)
|
108 |
-
top_p = gr.Slider(
|
109 |
-
minimum=0.1, maximum=1.0, value=0.95, step=0.05, label="Top-p (nucleus sampling)"
|
110 |
-
)
|
111 |
-
|
112 |
-
# Update chat interface to include additional inputs
|
113 |
-
chat.additional_inputs.extend([model_choice, max_tokens, temperature, top_p])
|
114 |
-
|
115 |
submit_button.click(
|
116 |
check_password, inputs=password_input, outputs=[password_input, chat_interface]
|
117 |
)
|
|
|
24 |
temperature: float,
|
25 |
top_p: float,
|
26 |
):
|
27 |
+
"""Handles chatbot responses with Perplexity AI."""
|
28 |
+
|
29 |
if model_choice not in AVAILABLE_MODELS:
|
30 |
return "Error: Invalid model selection."
|
31 |
|
|
|
70 |
yield f"Error: {str(e)}"
|
71 |
|
72 |
def check_password(input_password):
|
73 |
+
"""Validates the password before showing the chat interface."""
|
74 |
if input_password == PASSWORD:
|
75 |
return gr.update(visible=False), gr.update(visible=True)
|
76 |
else:
|
|
|
90 |
system_prompt = gr.Textbox(
|
91 |
value="You are a helpful assistant.", label="System message"
|
92 |
)
|
93 |
+
model_choice = gr.Dropdown(
|
94 |
+
choices=list(AVAILABLE_MODELS.keys()),
|
95 |
+
value=list(AVAILABLE_MODELS.keys())[0],
|
96 |
+
label="Select Model"
|
97 |
+
)
|
98 |
+
max_tokens = gr.Slider(
|
99 |
+
minimum=1, maximum=30000, value=2048, step=100, label="Max new tokens"
|
100 |
+
)
|
101 |
+
temperature = gr.Slider(
|
102 |
+
minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"
|
103 |
+
)
|
104 |
+
top_p = gr.Slider(
|
105 |
+
minimum=0.1, maximum=1.0, value=0.95, step=0.05, label="Top-p (nucleus sampling)"
|
106 |
+
)
|
107 |
+
|
108 |
chat = gr.ChatInterface(
|
109 |
respond,
|
110 |
chatbot=gr.Chatbot(height=400), # Set the desired height here
|
111 |
+
additional_inputs=[system_prompt, model_choice, max_tokens, temperature, top_p] # Pass extra parameters
|
112 |
)
|
113 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
114 |
submit_button.click(
|
115 |
check_password, inputs=password_input, outputs=[password_input, chat_interface]
|
116 |
)
|