Spaces:
No application file
No application file
File size: 4,599 Bytes
44cdfaa |
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 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
#!/usr/bin/env python3
"""
Component testing to identify schema validation issues
"""
import os
import ssl
# SSL fixes
try:
import certifi
os.environ['SSL_CERT_FILE'] = certifi.where()
os.environ['REQUESTS_CA_BUNDLE'] = certifi.where()
except ImportError:
pass
ssl._create_default_https_context = ssl._create_unverified_context
os.environ['PYTHONHTTPSVERIFY'] = '0'
import gradio as gr
def test_basic_components():
"""Test 1: Basic components only"""
with gr.Blocks(title="Test 1: Basic") as demo:
gr.HTML("<h1>Test 1: Basic Components</h1>")
vehicle_input = gr.Radio(choices=["Robot", "Drone"], value="Robot")
text_input = gr.Textbox(value="test")
button = gr.Button("Test")
output = gr.Textbox()
button.click(lambda v, t: f"{v}: {t}", [vehicle_input, text_input], output)
return demo
def test_with_slider():
"""Test 2: Add Slider component"""
with gr.Blocks(title="Test 2: With Slider") as demo:
gr.HTML("<h1>Test 2: With Slider</h1>")
vehicle_input = gr.Radio(choices=["Robot", "Drone"], value="Robot")
text_input = gr.Textbox(value="test")
slider_input = gr.Slider(0, 100, value=50)
button = gr.Button("Test")
output = gr.Textbox()
button.click(lambda v, t, s: f"{v}: {t}, {s}", [vehicle_input, text_input, slider_input], output)
return demo
def test_with_json():
"""Test 3: Add JSON component"""
with gr.Blocks(title="Test 3: With JSON") as demo:
gr.HTML("<h1>Test 3: With JSON</h1>")
vehicle_input = gr.Radio(choices=["Robot", "Drone"], value="Robot")
text_input = gr.Textbox(value="test")
button = gr.Button("Test")
output = gr.Textbox()
json_output = gr.JSON()
def test_func(v, t):
return f"{v}: {t}", {"vehicle": v, "text": t}
button.click(test_func, [vehicle_input, text_input], [output, json_output])
return demo
def test_with_image():
"""Test 4: Add Image component"""
with gr.Blocks(title="Test 4: With Image") as demo:
gr.HTML("<h1>Test 4: With Image</h1>")
vehicle_input = gr.Radio(choices=["Robot", "Drone"], value="Robot")
text_input = gr.Textbox(value="test")
button = gr.Button("Test")
output = gr.Textbox()
image_output = gr.Image()
button.click(lambda v, t: (f"{v}: {t}", None), [vehicle_input, text_input], [output, image_output])
return demo
def test_with_file():
"""Test 5: Add File component"""
with gr.Blocks(title="Test 5: With File") as demo:
gr.HTML("<h1>Test 5: With File</h1>")
vehicle_input = gr.Radio(choices=["Robot", "Drone"], value="Robot")
text_input = gr.Textbox(value="test")
button = gr.Button("Test")
output = gr.Textbox()
file_output = gr.File()
button.click(lambda v, t: (f"{v}: {t}", None), [vehicle_input, text_input], [output, file_output])
return demo
if __name__ == "__main__":
tests = [
("Basic Components", test_basic_components),
("With Slider", test_with_slider),
("With JSON", test_with_json),
("With Image", test_with_image),
("With File", test_with_file)
]
for i, (name, test_func) in enumerate(tests, 1):
print(f"\n{'='*50}")
print(f"Testing {i}: {name}")
print(f"{'='*50}")
try:
demo = test_func()
print(f"β
{name} - Demo created successfully")
# Try to launch briefly to trigger schema validation
try:
demo.launch(
server_port=7860 + i,
share=False,
prevent_thread_lock=True,
quiet=True
)
print(f"β
{name} - Launched successfully")
demo.close()
except Exception as e:
print(f"β {name} - Launch failed: {e}")
if "bool" in str(e) and "iterable" in str(e):
print(f"π― FOUND IT! {name} causes the schema error!")
break
except Exception as e:
print(f"β {name} - Creation failed: {e}")
if "bool" in str(e) and "iterable" in str(e):
print(f"π― FOUND IT! {name} causes the schema error!")
break
print("\n" + "="*50)
print("Component testing complete!") |