Spaces:
Running
Running
update gradio
Browse files
app.py
CHANGED
@@ -1265,8 +1265,19 @@ with gr.Blocks(
|
|
1265 |
if m['name'] == model_name:
|
1266 |
return m, update_image_input_visibility(m)
|
1267 |
return AVAILABLE_MODELS[0], update_image_input_visibility(AVAILABLE_MODELS[0])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1268 |
def save_prompt(input):
|
1269 |
return {setting: {"system": input}}
|
|
|
1270 |
model_dropdown.change(
|
1271 |
lambda model_name: on_model_change(model_name),
|
1272 |
inputs=model_dropdown,
|
@@ -1294,6 +1305,13 @@ with gr.Blocks(
|
|
1294 |
return gr.update(language=get_gradio_language(language))
|
1295 |
|
1296 |
language_dropdown.change(update_code_language, inputs=language_dropdown, outputs=code_output)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1297 |
|
1298 |
def preview_logic(code, language):
|
1299 |
if language == "html":
|
@@ -1435,10 +1453,17 @@ If you have any questions, checkout our [documentation](https://docs.streamlit.i
|
|
1435 |
(app_py_path, "src/streamlit_app.py"),
|
1436 |
(readme_path, "README.md"),
|
1437 |
]
|
1438 |
-
else:
|
1439 |
file_name = "app.py"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1440 |
with tempfile.NamedTemporaryFile("w", suffix=".py", delete=False) as f:
|
1441 |
-
f.write(
|
1442 |
temp_path = f.name
|
1443 |
files_to_upload = [(temp_path, file_name)]
|
1444 |
# Upload all files
|
|
|
1265 |
if m['name'] == model_name:
|
1266 |
return m, update_image_input_visibility(m)
|
1267 |
return AVAILABLE_MODELS[0], update_image_input_visibility(AVAILABLE_MODELS[0])
|
1268 |
+
|
1269 |
+
def on_sdk_change(sdk_name):
|
1270 |
+
# Automatically set language based on SDK selection
|
1271 |
+
if sdk_name == "Gradio (Python)":
|
1272 |
+
return gr.update(value="python"), gr.update(language="python")
|
1273 |
+
elif sdk_name == "Streamlit (Python)":
|
1274 |
+
return gr.update(value="python"), gr.update(language="python")
|
1275 |
+
else: # Static (HTML)
|
1276 |
+
return gr.update(value="html"), gr.update(language="html")
|
1277 |
+
|
1278 |
def save_prompt(input):
|
1279 |
return {setting: {"system": input}}
|
1280 |
+
|
1281 |
model_dropdown.change(
|
1282 |
lambda model_name: on_model_change(model_name),
|
1283 |
inputs=model_dropdown,
|
|
|
1305 |
return gr.update(language=get_gradio_language(language))
|
1306 |
|
1307 |
language_dropdown.change(update_code_language, inputs=language_dropdown, outputs=code_output)
|
1308 |
+
|
1309 |
+
# Add SDK change handler after code_output is defined
|
1310 |
+
sdk_dropdown.change(
|
1311 |
+
on_sdk_change,
|
1312 |
+
inputs=sdk_dropdown,
|
1313 |
+
outputs=[language_dropdown, code_output]
|
1314 |
+
)
|
1315 |
|
1316 |
def preview_logic(code, language):
|
1317 |
if language == "html":
|
|
|
1453 |
(app_py_path, "src/streamlit_app.py"),
|
1454 |
(readme_path, "README.md"),
|
1455 |
]
|
1456 |
+
else: # Gradio (Python)
|
1457 |
file_name = "app.py"
|
1458 |
+
# Check if the code is already Python/Gradio code or HTML
|
1459 |
+
if code.strip().startswith('import gradio') or code.strip().startswith('import gr') or 'gradio' in code.lower():
|
1460 |
+
# Code is already Python/Gradio, use it directly
|
1461 |
+
app_py = code
|
1462 |
+
else:
|
1463 |
+
# Code is HTML, wrap it in a Gradio app structure
|
1464 |
+
app_py = wrap_html_in_gradio_app(code)
|
1465 |
with tempfile.NamedTemporaryFile("w", suffix=".py", delete=False) as f:
|
1466 |
+
f.write(app_py)
|
1467 |
temp_path = f.name
|
1468 |
files_to_upload = [(temp_path, file_name)]
|
1469 |
# Upload all files
|