Update app.py
Browse files
app.py
CHANGED
|
@@ -149,7 +149,7 @@ def generation_code(
|
|
| 149 |
|
| 150 |
|
| 151 |
# ==============================================================================
|
| 152 |
-
# UI LAYOUT
|
| 153 |
# ==============================================================================
|
| 154 |
|
| 155 |
with gr.Blocks(theme=gr.themes.Soft(), title="AnyCoder - AI Code Generator") as demo:
|
|
@@ -163,8 +163,6 @@ with gr.Blocks(theme=gr.themes.Soft(), title="AnyCoder - AI Code Generator") as
|
|
| 163 |
gr.Markdown("## π AnyCoder AI")
|
| 164 |
gr.Markdown("Your personal AI partner for generating, modifying, and understanding code.")
|
| 165 |
|
| 166 |
-
# Create a flat list of model names for the dropdown.
|
| 167 |
-
# The grouped choices format was causing a ValueError with the current setup.
|
| 168 |
model_choices = [model["name"] for model in AVAILABLE_MODELS]
|
| 169 |
|
| 170 |
model_dd = gr.Dropdown(
|
|
@@ -198,39 +196,39 @@ with gr.Blocks(theme=gr.themes.Soft(), title="AnyCoder - AI Code Generator") as
|
|
| 198 |
with gr.Tab("ποΈ Live Preview", id="preview_tab"):
|
| 199 |
preview_out = gr.HTML(label="Live Preview")
|
| 200 |
with gr.Tab("π History", id="history_tab"):
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
#
|
| 205 |
-
#
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
|
| 211 |
-
|
| 212 |
-
model_dd.change(fn=on_model_change, inputs=[model_dd], outputs=[model_state])
|
| 213 |
-
|
| 214 |
-
language_dd.change(fn=lambda lang: gr.Code(language=lang), inputs=[language_dd], outputs=[code_out])
|
| 215 |
-
|
| 216 |
-
gen_btn.click(
|
| 217 |
-
|
| 218 |
-
|
| 219 |
-
|
| 220 |
-
|
| 221 |
-
|
| 222 |
-
|
| 223 |
-
)
|
| 224 |
-
|
| 225 |
-
def clear_session():
|
| 226 |
-
|
| 227 |
-
|
| 228 |
-
|
| 229 |
-
|
| 230 |
-
|
| 231 |
-
|
| 232 |
-
|
| 233 |
-
|
| 234 |
|
| 235 |
# ==============================================================================
|
| 236 |
# APPLICATION ENTRY POINT
|
|
|
|
| 149 |
|
| 150 |
|
| 151 |
# ==============================================================================
|
| 152 |
+
# UI LAYOUT & EVENT WIRING
|
| 153 |
# ==============================================================================
|
| 154 |
|
| 155 |
with gr.Blocks(theme=gr.themes.Soft(), title="AnyCoder - AI Code Generator") as demo:
|
|
|
|
| 163 |
gr.Markdown("## π AnyCoder AI")
|
| 164 |
gr.Markdown("Your personal AI partner for generating, modifying, and understanding code.")
|
| 165 |
|
|
|
|
|
|
|
| 166 |
model_choices = [model["name"] for model in AVAILABLE_MODELS]
|
| 167 |
|
| 168 |
model_dd = gr.Dropdown(
|
|
|
|
| 196 |
with gr.Tab("ποΈ Live Preview", id="preview_tab"):
|
| 197 |
preview_out = gr.HTML(label="Live Preview")
|
| 198 |
with gr.Tab("π History", id="history_tab"):
|
| 199 |
+
# Removed deprecated 'bubble_full_width' parameter
|
| 200 |
+
chat_out = gr.Chatbot(label="Conversation History", type="messages")
|
| 201 |
+
|
| 202 |
+
# --- Event Wiring ---
|
| 203 |
+
# Event listeners must be defined within the gr.Blocks context.
|
| 204 |
+
|
| 205 |
+
def on_model_change(model_name: str) -> Dict:
|
| 206 |
+
"""Updates the model_state when the user selects a new model."""
|
| 207 |
+
model_details = get_model_details(model_name)
|
| 208 |
+
return model_details or initial_model
|
| 209 |
+
|
| 210 |
+
model_dd.change(fn=on_model_change, inputs=[model_dd], outputs=[model_state])
|
| 211 |
+
|
| 212 |
+
language_dd.change(fn=lambda lang: gr.Code(language=lang), inputs=[language_dd], outputs=[code_out])
|
| 213 |
+
|
| 214 |
+
gen_btn.click(
|
| 215 |
+
fn=generation_code,
|
| 216 |
+
inputs=[
|
| 217 |
+
prompt_in, file_in, url_site,
|
| 218 |
+
model_state, search_chk, language_dd, history_state
|
| 219 |
+
],
|
| 220 |
+
outputs=[code_out, history_state, preview_out, chat_out]
|
| 221 |
+
)
|
| 222 |
+
|
| 223 |
+
def clear_session():
|
| 224 |
+
"""Resets the UI components and state to their initial values."""
|
| 225 |
+
return "", [], "", [], None, ""
|
| 226 |
+
|
| 227 |
+
clr_btn.click(
|
| 228 |
+
fn=clear_session,
|
| 229 |
+
outputs=[prompt_in, history_state, preview_out, chat_out, file_in, url_site],
|
| 230 |
+
queue=False
|
| 231 |
+
)
|
| 232 |
|
| 233 |
# ==============================================================================
|
| 234 |
# APPLICATION ENTRY POINT
|