Spaces:
Paused
Paused
File size: 2,454 Bytes
289fb74 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
#!/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) |