Update App.Py Version 2
#5
by
abubakaraabi786
- opened
app.py
CHANGED
|
@@ -125,7 +125,7 @@ def update_example_questions(programming_language: str):
|
|
| 125 |
]
|
| 126 |
}
|
| 127 |
|
| 128 |
-
return examples.get(programming_language, examples["General"])
|
| 129 |
|
| 130 |
# Create Gradio interface
|
| 131 |
with gr.Blocks(theme=gr.themes.Soft(), title="CodeMentor - Programming Tutor") as demo:
|
|
@@ -186,17 +186,25 @@ with gr.Blocks(theme=gr.themes.Soft(), title="CodeMentor - Programming Tutor") a
|
|
| 186 |
info="Maximum length of responses"
|
| 187 |
)
|
| 188 |
|
| 189 |
-
# Example questions
|
| 190 |
-
gr.Markdown("### π‘
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 196 |
)
|
| 197 |
|
| 198 |
-
#
|
| 199 |
-
|
|
|
|
|
|
|
|
|
|
| 200 |
|
| 201 |
with gr.Column(scale=2):
|
| 202 |
# Chat interface
|
|
@@ -214,20 +222,22 @@ with gr.Blocks(theme=gr.themes.Soft(), title="CodeMentor - Programming Tutor") a
|
|
| 214 |
lines=2
|
| 215 |
)
|
| 216 |
|
| 217 |
-
|
| 218 |
-
|
|
|
|
|
|
|
| 219 |
|
| 220 |
# Update example questions when language changes
|
| 221 |
language_dropdown.change(
|
| 222 |
fn=update_example_questions,
|
| 223 |
inputs=language_dropdown,
|
| 224 |
-
outputs=
|
| 225 |
)
|
| 226 |
|
| 227 |
-
# Handle example question
|
| 228 |
-
|
| 229 |
fn=lambda x: x,
|
| 230 |
-
inputs=[
|
| 231 |
outputs=msg
|
| 232 |
)
|
| 233 |
|
|
@@ -251,6 +261,30 @@ with gr.Blocks(theme=gr.themes.Soft(), title="CodeMentor - Programming Tutor") a
|
|
| 251 |
outputs=[chatbot, chat_state]
|
| 252 |
)
|
| 253 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 254 |
# Footer
|
| 255 |
gr.Markdown("""
|
| 256 |
---
|
|
|
|
| 125 |
]
|
| 126 |
}
|
| 127 |
|
| 128 |
+
return gr.update(choices=examples.get(programming_language, examples["General"]))
|
| 129 |
|
| 130 |
# Create Gradio interface
|
| 131 |
with gr.Blocks(theme=gr.themes.Soft(), title="CodeMentor - Programming Tutor") as demo:
|
|
|
|
| 186 |
info="Maximum length of responses"
|
| 187 |
)
|
| 188 |
|
| 189 |
+
# Example questions dropdown (replacing Dataset)
|
| 190 |
+
gr.Markdown("### π‘ Example Questions")
|
| 191 |
+
example_dropdown = gr.Dropdown(
|
| 192 |
+
choices=[
|
| 193 |
+
"Explain list comprehensions with examples",
|
| 194 |
+
"How do decorators work in Python?",
|
| 195 |
+
"What's the difference between 'is' and '=='?",
|
| 196 |
+
"Show me how to handle exceptions properly"
|
| 197 |
+
],
|
| 198 |
+
label="Quick Questions",
|
| 199 |
+
info="Select a question to ask",
|
| 200 |
+
allow_custom_value=True
|
| 201 |
)
|
| 202 |
|
| 203 |
+
# Quick action buttons
|
| 204 |
+
gr.Markdown("### β‘ Quick Actions")
|
| 205 |
+
with gr.Row():
|
| 206 |
+
clear_btn = gr.Button("π§Ή Clear Chat", variant="secondary", size="sm")
|
| 207 |
+
reset_btn = gr.Button("π Reset Settings", variant="secondary", size="sm")
|
| 208 |
|
| 209 |
with gr.Column(scale=2):
|
| 210 |
# Chat interface
|
|
|
|
| 222 |
lines=2
|
| 223 |
)
|
| 224 |
|
| 225 |
+
with gr.Row():
|
| 226 |
+
# Send button
|
| 227 |
+
send_btn = gr.Button("π Send", variant="primary")
|
| 228 |
+
stop_btn = gr.Button("βΉοΈ Stop", variant="stop")
|
| 229 |
|
| 230 |
# Update example questions when language changes
|
| 231 |
language_dropdown.change(
|
| 232 |
fn=update_example_questions,
|
| 233 |
inputs=language_dropdown,
|
| 234 |
+
outputs=example_dropdown
|
| 235 |
)
|
| 236 |
|
| 237 |
+
# Handle example question selection
|
| 238 |
+
example_dropdown.change(
|
| 239 |
fn=lambda x: x,
|
| 240 |
+
inputs=[example_dropdown],
|
| 241 |
outputs=msg
|
| 242 |
)
|
| 243 |
|
|
|
|
| 261 |
outputs=[chatbot, chat_state]
|
| 262 |
)
|
| 263 |
|
| 264 |
+
# Handle reset button
|
| 265 |
+
def reset_settings():
|
| 266 |
+
return [
|
| 267 |
+
"Llama 3 (8B) - Fast", # model_dropdown
|
| 268 |
+
"Python", # language_dropdown
|
| 269 |
+
0.7, # temperature_slider
|
| 270 |
+
500, # max_tokens_slider
|
| 271 |
+
"Explain list comprehensions with examples" # example_dropdown
|
| 272 |
+
]
|
| 273 |
+
|
| 274 |
+
reset_btn.click(
|
| 275 |
+
fn=reset_settings,
|
| 276 |
+
inputs=None,
|
| 277 |
+
outputs=[model_dropdown, language_dropdown, temperature_slider, max_tokens_slider, example_dropdown]
|
| 278 |
+
)
|
| 279 |
+
|
| 280 |
+
# Handle stop button
|
| 281 |
+
stop_btn.click(
|
| 282 |
+
fn=None,
|
| 283 |
+
inputs=None,
|
| 284 |
+
outputs=None,
|
| 285 |
+
cancels=[]
|
| 286 |
+
)
|
| 287 |
+
|
| 288 |
# Footer
|
| 289 |
gr.Markdown("""
|
| 290 |
---
|