Spaces:
Paused
Paused
#!/usr/bin/env python3 | |
""" | |
Simple Gradio Dropdown Test | |
Test basic dropdown functionality with GPU detection | |
""" | |
import gradio as gr | |
import torch | |
import os | |
def get_test_gpus(): | |
"""Simple GPU detection for testing""" | |
gpus = [] | |
if torch.cuda.is_available(): | |
device_count = torch.cuda.device_count() | |
print(f"CUDA devices found: {device_count}") | |
for i in range(device_count): | |
try: | |
name = torch.cuda.get_device_name(i) | |
memory = torch.cuda.get_device_properties(i).total_memory / (1024**3) | |
gpu_option = f"GPU {i}: {name} ({memory:.1f}GB)" | |
gpus.append(gpu_option) | |
print(f"Added: {gpu_option}") | |
except Exception as e: | |
print(f"Error with GPU {i}: {e}") | |
gpus.append(f"GPU {i}: Error") | |
gpus.append("CPU Only") | |
print(f"Final GPU list: {gpus}") | |
return gpus | |
def on_gpu_change(selected_gpu): | |
"""Handle GPU selection change""" | |
print(f"Selected GPU: {selected_gpu}") | |
return f"You selected: {selected_gpu}" | |
def refresh_gpus(): | |
"""Refresh GPU list""" | |
new_gpus = get_test_gpus() | |
print(f"Refreshed GPUs: {new_gpus}") | |
return gr.update(choices=new_gpus, value=new_gpus[0]) | |
# Get initial GPU list | |
gpu_list = get_test_gpus() | |
# Create simple interface | |
with gr.Blocks(title="GPU Dropdown Test") as demo: | |
gr.Markdown("# GPU Dropdown Test") | |
with gr.Row(): | |
gpu_dropdown = gr.Dropdown( | |
label="Select GPU", | |
choices=gpu_list, | |
value=gpu_list[0] if gpu_list else None, | |
interactive=True, | |
allow_custom_value=False, | |
scale=4 | |
) | |
refresh_btn = gr.Button("π Refresh", scale=1) | |
output_text = gr.Textbox( | |
label="Selected", | |
value=f"Current selection: {gpu_list[0] if gpu_list else 'None'}", | |
interactive=False | |
) | |
status_text = gr.Textbox( | |
label="Status", | |
value=f"Detected {len(gpu_list)} options: {', '.join(gpu_list)}", | |
interactive=False, | |
lines=2 | |
) | |
# Event handlers | |
gpu_dropdown.change(on_gpu_change, inputs=[gpu_dropdown], outputs=[output_text]) | |
refresh_btn.click(refresh_gpus, outputs=[gpu_dropdown]) | |
if __name__ == "__main__": | |
demo.launch(debug=True) |