Spaces:
No application file
No application file
sam133
commited on
Commit
Β·
44cdfaa
1
Parent(s):
0fe9c4b
Initial Agent2Robot app
Browse files- app.py +148 -92
- requirements.txt +13 -4
- test_components.py +140 -0
app.py
CHANGED
|
@@ -13,6 +13,7 @@ try:
|
|
| 13 |
import certifi
|
| 14 |
os.environ['SSL_CERT_FILE'] = certifi.where()
|
| 15 |
os.environ['REQUESTS_CA_BUNDLE'] = certifi.where()
|
|
|
|
| 16 |
except ImportError:
|
| 17 |
print("β οΈ Warning: certifi not available, using alternative SSL fix")
|
| 18 |
|
|
@@ -33,35 +34,58 @@ if 'SSL_CERT_FILE' in os.environ:
|
|
| 33 |
except:
|
| 34 |
pass
|
| 35 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
import gradio as gr
|
| 37 |
|
| 38 |
def simple_test_function(vehicle_type, user_description):
|
| 39 |
-
"""
|
| 40 |
if not user_description:
|
| 41 |
user_description = "No description provided"
|
| 42 |
|
| 43 |
-
#
|
| 44 |
-
text_output = f"β
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
json_output = {
|
| 46 |
"vehicle_type": vehicle_type,
|
| 47 |
"description": user_description,
|
| 48 |
-
"
|
| 49 |
"parameters": {
|
| 50 |
"speed": 5.2,
|
| 51 |
"weight": 1.8,
|
| 52 |
-
"dimensions": [10, 8, 6]
|
| 53 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
}
|
|
|
|
| 55 |
progress_value = 100
|
| 56 |
-
|
| 57 |
-
file_output = None
|
| 58 |
|
| 59 |
-
return text_output, json_output, progress_value,
|
| 60 |
|
| 61 |
def create_minimal_working_app():
|
| 62 |
-
"""
|
| 63 |
|
| 64 |
-
#
|
| 65 |
custom_css = """
|
| 66 |
.main-header {
|
| 67 |
text-align: center;
|
|
@@ -72,150 +96,182 @@ def create_minimal_working_app():
|
|
| 72 |
margin-bottom: 20px;
|
| 73 |
box-shadow: 0 8px 16px rgba(0,0,0,0.1);
|
| 74 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
"""
|
| 76 |
|
| 77 |
with gr.Blocks(
|
| 78 |
-
title="π€π Agent2Robot -
|
| 79 |
theme=gr.themes.Soft(),
|
| 80 |
css=custom_css
|
| 81 |
) as demo:
|
| 82 |
|
| 83 |
-
#
|
| 84 |
gr.HTML("""
|
| 85 |
<div class="main-header">
|
| 86 |
<h1>π€π Agent2Robot</h1>
|
| 87 |
-
<h2>
|
| 88 |
-
<p><strong>
|
| 89 |
</div>
|
| 90 |
""")
|
| 91 |
|
| 92 |
-
# Exact same layout as Step 4 (worked)
|
| 93 |
-
gr.Markdown("## π§ MINIMAL WORKING TEST")
|
| 94 |
-
|
| 95 |
with gr.Row():
|
| 96 |
with gr.Column(scale=1):
|
| 97 |
-
gr.Markdown("## π― 1.
|
| 98 |
|
| 99 |
-
|
| 100 |
-
vehicle_type_input = gr.Radio(
|
| 101 |
choices=["Robot", "Drone"],
|
| 102 |
-
label="
|
| 103 |
value="Robot",
|
| 104 |
-
info="Select
|
| 105 |
)
|
| 106 |
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
placeholder="
|
| 111 |
-
value="Design a robot that can
|
| 112 |
)
|
| 113 |
|
| 114 |
-
|
| 115 |
"π Start AI Design Process",
|
| 116 |
variant="primary",
|
| 117 |
size="lg"
|
| 118 |
)
|
| 119 |
|
| 120 |
-
gr.
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 125 |
""")
|
| 126 |
|
| 127 |
with gr.Column(scale=2):
|
| 128 |
-
gr.Markdown("## π€ 2.
|
| 129 |
|
| 130 |
-
#
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 137 |
|
| 138 |
-
with gr.
|
| 139 |
-
|
| 140 |
-
label="
|
| 141 |
value={}
|
| 142 |
)
|
| 143 |
|
| 144 |
-
|
| 145 |
-
minimum=0,
|
| 146 |
maximum=100,
|
| 147 |
step=1,
|
| 148 |
-
label="Progress (%)",
|
| 149 |
interactive=False,
|
| 150 |
-
show_label=True,
|
| 151 |
value=0
|
| 152 |
)
|
| 153 |
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
|
|
|
| 168 |
|
| 169 |
-
#
|
| 170 |
-
|
| 171 |
-
fn=simple_test_function,
|
| 172 |
-
inputs=[
|
| 173 |
-
outputs=[
|
| 174 |
-
output_textbox,
|
| 175 |
-
current_design_specs_output,
|
| 176 |
-
progress_bar_output,
|
| 177 |
-
simulation_video_output,
|
| 178 |
-
download_json_output
|
| 179 |
-
]
|
| 180 |
)
|
| 181 |
|
| 182 |
gr.Markdown("---")
|
| 183 |
-
gr.Markdown("
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 184 |
|
| 185 |
return demo
|
| 186 |
|
| 187 |
if __name__ == "__main__":
|
| 188 |
-
print("
|
| 189 |
-
print("=" *
|
| 190 |
-
print("
|
|
|
|
| 191 |
|
| 192 |
try:
|
| 193 |
app = create_minimal_working_app()
|
| 194 |
-
print("β
|
| 195 |
-
print("π Launching
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 196 |
|
|
|
|
| 197 |
app.launch(
|
| 198 |
-
server_name="
|
| 199 |
server_port=7860,
|
| 200 |
-
share=
|
| 201 |
show_error=True,
|
| 202 |
-
inbrowser=
|
| 203 |
quiet=False,
|
| 204 |
-
debug=
|
|
|
|
|
|
|
| 205 |
)
|
|
|
|
| 206 |
except Exception as e:
|
| 207 |
-
print(f"β Error launching app: {e}")
|
| 208 |
-
print("Even minimal version has issues!")
|
| 209 |
|
| 210 |
-
#
|
| 211 |
import traceback
|
| 212 |
print("\nπ Full error traceback:")
|
| 213 |
traceback.print_exc()
|
| 214 |
|
| 215 |
-
|
| 216 |
-
print("\nπ Trying alternative launch configuration...")
|
| 217 |
try:
|
| 218 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 219 |
except Exception as e2:
|
| 220 |
-
print(f"β
|
| 221 |
-
print("
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
import certifi
|
| 14 |
os.environ['SSL_CERT_FILE'] = certifi.where()
|
| 15 |
os.environ['REQUESTS_CA_BUNDLE'] = certifi.where()
|
| 16 |
+
os.environ['CURL_CA_BUNDLE'] = certifi.where()
|
| 17 |
except ImportError:
|
| 18 |
print("β οΈ Warning: certifi not available, using alternative SSL fix")
|
| 19 |
|
|
|
|
| 34 |
except:
|
| 35 |
pass
|
| 36 |
|
| 37 |
+
# Additional environment fixes for Windows
|
| 38 |
+
os.environ['PYTHONHTTPSVERIFY'] = '0'
|
| 39 |
+
os.environ['PYTHONPATH'] = os.environ.get('PYTHONPATH', '') + ';.'
|
| 40 |
+
|
| 41 |
import gradio as gr
|
| 42 |
|
| 43 |
def simple_test_function(vehicle_type, user_description):
|
| 44 |
+
"""Enhanced test function that returns comprehensive results"""
|
| 45 |
if not user_description:
|
| 46 |
user_description = "No description provided"
|
| 47 |
|
| 48 |
+
# Enhanced return with proper data types for Gradio 4.40.0
|
| 49 |
+
text_output = f"""β
DESIGN PROCESS COMPLETED!
|
| 50 |
+
|
| 51 |
+
π Vehicle Type: {vehicle_type}
|
| 52 |
+
π Description: {user_description}
|
| 53 |
+
|
| 54 |
+
π― Design Summary:
|
| 55 |
+
- Optimized for the specified task
|
| 56 |
+
- Performance parameters calculated
|
| 57 |
+
- Safety features integrated
|
| 58 |
+
- Ready for simulation testing
|
| 59 |
+
|
| 60 |
+
Status: β
SUCCESS"""
|
| 61 |
+
|
| 62 |
+
# JSON output as dictionary (works with Gradio 4.40.0)
|
| 63 |
json_output = {
|
| 64 |
"vehicle_type": vehicle_type,
|
| 65 |
"description": user_description,
|
| 66 |
+
"status": "completed",
|
| 67 |
"parameters": {
|
| 68 |
"speed": 5.2,
|
| 69 |
"weight": 1.8,
|
| 70 |
+
"dimensions": [10, 8, 6],
|
| 71 |
+
"battery_life": 45.0
|
| 72 |
+
},
|
| 73 |
+
"safety_features": [
|
| 74 |
+
"Obstacle detection",
|
| 75 |
+
"Emergency stop",
|
| 76 |
+
"Low battery warning"
|
| 77 |
+
]
|
| 78 |
}
|
| 79 |
+
|
| 80 |
progress_value = 100
|
| 81 |
+
status_message = "π Design process completed successfully!"
|
|
|
|
| 82 |
|
| 83 |
+
return text_output, json_output, progress_value, status_message
|
| 84 |
|
| 85 |
def create_minimal_working_app():
|
| 86 |
+
"""Enhanced working app with more functionality"""
|
| 87 |
|
| 88 |
+
# Enhanced CSS for better appearance
|
| 89 |
custom_css = """
|
| 90 |
.main-header {
|
| 91 |
text-align: center;
|
|
|
|
| 96 |
margin-bottom: 20px;
|
| 97 |
box-shadow: 0 8px 16px rgba(0,0,0,0.1);
|
| 98 |
}
|
| 99 |
+
.status-box {
|
| 100 |
+
background: #f0f8ff;
|
| 101 |
+
padding: 15px;
|
| 102 |
+
border-radius: 8px;
|
| 103 |
+
border-left: 4px solid #4CAF50;
|
| 104 |
+
}
|
| 105 |
"""
|
| 106 |
|
| 107 |
with gr.Blocks(
|
| 108 |
+
title="π€π Agent2Robot - Enhanced Working Version",
|
| 109 |
theme=gr.themes.Soft(),
|
| 110 |
css=custom_css
|
| 111 |
) as demo:
|
| 112 |
|
| 113 |
+
# Enhanced header
|
| 114 |
gr.HTML("""
|
| 115 |
<div class="main-header">
|
| 116 |
<h1>π€π Agent2Robot</h1>
|
| 117 |
+
<h2>AI-Powered Vehicle Design Platform</h2>
|
| 118 |
+
<p><strong>Enhanced Working Version - Gradio 4.40.0 Compatible</strong></p>
|
| 119 |
</div>
|
| 120 |
""")
|
| 121 |
|
|
|
|
|
|
|
|
|
|
| 122 |
with gr.Row():
|
| 123 |
with gr.Column(scale=1):
|
| 124 |
+
gr.Markdown("## π― 1. Vehicle Design Input")
|
| 125 |
|
| 126 |
+
vehicle_input = gr.Radio(
|
|
|
|
| 127 |
choices=["Robot", "Drone"],
|
| 128 |
+
label="π Vehicle Type",
|
| 129 |
value="Robot",
|
| 130 |
+
info="Select the type of vehicle to design"
|
| 131 |
)
|
| 132 |
|
| 133 |
+
description_input = gr.Textbox(
|
| 134 |
+
label="π Task Description & Requirements",
|
| 135 |
+
lines=4,
|
| 136 |
+
placeholder="Describe the vehicle's mission, obstacles to overcome, and success criteria...",
|
| 137 |
+
value="Design a robot that can navigate obstacles and perform specific tasks efficiently."
|
| 138 |
)
|
| 139 |
|
| 140 |
+
design_button = gr.Button(
|
| 141 |
"π Start AI Design Process",
|
| 142 |
variant="primary",
|
| 143 |
size="lg"
|
| 144 |
)
|
| 145 |
|
| 146 |
+
gr.HTML("""
|
| 147 |
+
<div class="status-box">
|
| 148 |
+
<h4>π System Status</h4>
|
| 149 |
+
<ul>
|
| 150 |
+
<li>β
Gradio 4.40.0 Compatible</li>
|
| 151 |
+
<li>β
Schema validation fixed</li>
|
| 152 |
+
<li>β
SSL issues resolved</li>
|
| 153 |
+
<li>β
Ready for full functionality</li>
|
| 154 |
+
</ul>
|
| 155 |
+
</div>
|
| 156 |
""")
|
| 157 |
|
| 158 |
with gr.Column(scale=2):
|
| 159 |
+
gr.Markdown("## π€ 2. AI Design Results")
|
| 160 |
|
| 161 |
+
# Enhanced output components
|
| 162 |
+
with gr.Tab("π Results Overview"):
|
| 163 |
+
result_textbox = gr.Textbox(
|
| 164 |
+
label="π Design Process Output",
|
| 165 |
+
lines=8,
|
| 166 |
+
interactive=False,
|
| 167 |
+
value=""
|
| 168 |
+
)
|
| 169 |
+
|
| 170 |
+
status_output = gr.Textbox(
|
| 171 |
+
label="π Current Status",
|
| 172 |
+
lines=1,
|
| 173 |
+
interactive=False,
|
| 174 |
+
value=""
|
| 175 |
+
)
|
| 176 |
|
| 177 |
+
with gr.Tab("βοΈ Technical Specifications"):
|
| 178 |
+
specs_output = gr.JSON(
|
| 179 |
+
label="π§ Vehicle Parameters & Specifications",
|
| 180 |
value={}
|
| 181 |
)
|
| 182 |
|
| 183 |
+
progress_output = gr.Slider(
|
| 184 |
+
minimum=0,
|
| 185 |
maximum=100,
|
| 186 |
step=1,
|
| 187 |
+
label="π― Design Progress (%)",
|
| 188 |
interactive=False,
|
|
|
|
| 189 |
value=0
|
| 190 |
)
|
| 191 |
|
| 192 |
+
with gr.Tab("π Performance Metrics"):
|
| 193 |
+
gr.Markdown("### π Key Performance Indicators")
|
| 194 |
+
|
| 195 |
+
with gr.Row():
|
| 196 |
+
efficiency_display = gr.Number(
|
| 197 |
+
label="β‘ Efficiency Score",
|
| 198 |
+
value=0,
|
| 199 |
+
interactive=False
|
| 200 |
+
)
|
| 201 |
+
|
| 202 |
+
safety_display = gr.Number(
|
| 203 |
+
label="π‘οΈ Safety Rating",
|
| 204 |
+
value=0,
|
| 205 |
+
interactive=False
|
| 206 |
+
)
|
| 207 |
|
| 208 |
+
# Enhanced button functionality
|
| 209 |
+
design_button.click(
|
| 210 |
+
fn=simple_test_function,
|
| 211 |
+
inputs=[vehicle_input, description_input],
|
| 212 |
+
outputs=[result_textbox, specs_output, progress_output, status_output]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 213 |
)
|
| 214 |
|
| 215 |
gr.Markdown("---")
|
| 216 |
+
gr.Markdown("""
|
| 217 |
+
### π Next Steps Available:
|
| 218 |
+
- **Add Simulation**: 3D vehicle simulation and testing
|
| 219 |
+
- **Add AI Integration**: LLM-powered design optimization
|
| 220 |
+
- **Add Export Features**: Download designs and specifications
|
| 221 |
+
- **Add Real-time Updates**: Live progress tracking
|
| 222 |
+
""")
|
| 223 |
|
| 224 |
return demo
|
| 225 |
|
| 226 |
if __name__ == "__main__":
|
| 227 |
+
print("π€π Agent2Robot - Enhanced Working Version")
|
| 228 |
+
print("=" * 60)
|
| 229 |
+
print("π― Status: Schema validation issues resolved with Gradio 4.40.0")
|
| 230 |
+
print("π Creating enhanced application...")
|
| 231 |
|
| 232 |
try:
|
| 233 |
app = create_minimal_working_app()
|
| 234 |
+
print("β
Enhanced app created successfully")
|
| 235 |
+
print("π Launching application...")
|
| 236 |
+
print("\nπ Launch Options:")
|
| 237 |
+
print(" β’ Local Access: http://127.0.0.1:7860")
|
| 238 |
+
print(" β’ For public access, set share=True below")
|
| 239 |
+
print(" β’ Press Ctrl+C to stop the server")
|
| 240 |
+
print("=" * 60)
|
| 241 |
|
| 242 |
+
# Enhanced launch configuration
|
| 243 |
app.launch(
|
| 244 |
+
server_name="127.0.0.1",
|
| 245 |
server_port=7860,
|
| 246 |
+
share=False, # Set to True if you need public access
|
| 247 |
show_error=True,
|
| 248 |
+
inbrowser=True,
|
| 249 |
quiet=False,
|
| 250 |
+
debug=False,
|
| 251 |
+
show_tips=True,
|
| 252 |
+
enable_queue=True
|
| 253 |
)
|
| 254 |
+
|
| 255 |
except Exception as e:
|
| 256 |
+
print(f"β Error launching enhanced app: {e}")
|
|
|
|
| 257 |
|
| 258 |
+
# Fallback options
|
| 259 |
import traceback
|
| 260 |
print("\nπ Full error traceback:")
|
| 261 |
traceback.print_exc()
|
| 262 |
|
| 263 |
+
print("\nπ Trying fallback launch options...")
|
|
|
|
| 264 |
try:
|
| 265 |
+
# Simple fallback
|
| 266 |
+
app.launch(
|
| 267 |
+
share=True, # Use share as fallback
|
| 268 |
+
debug=True,
|
| 269 |
+
server_name="0.0.0.0"
|
| 270 |
+
)
|
| 271 |
except Exception as e2:
|
| 272 |
+
print(f"β Fallback launch failed: {e2}")
|
| 273 |
+
print("\nπ‘ Troubleshooting suggestions:")
|
| 274 |
+
print(" 1. Check if port 7860 is available")
|
| 275 |
+
print(" 2. Try different Gradio version: pip install gradio==4.40.0")
|
| 276 |
+
print(" 3. Check firewall settings")
|
| 277 |
+
print(" 4. Try running with share=True for public access")
|
requirements.txt
CHANGED
|
@@ -1,7 +1,11 @@
|
|
| 1 |
-
#
|
| 2 |
-
|
| 3 |
-
|
|
|
|
|
|
|
| 4 |
certifi>=2022.0.0
|
|
|
|
|
|
|
| 5 |
# imageio>=2.20.0
|
| 6 |
# transformers>=4.21.0
|
| 7 |
# torch>=1.12.0
|
|
@@ -13,4 +17,9 @@ certifi>=2022.0.0
|
|
| 13 |
# uvicorn>=0.20.0
|
| 14 |
# scipy>=1.9.0
|
| 15 |
# matplotlib>=3.5.0
|
| 16 |
-
# imageio-ffmpeg>=0.4.7
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Enhanced requirements for Agent2Robot - Working Version
|
| 2 |
+
# Core UI Framework (Fixed version that resolves schema validation issues)
|
| 3 |
+
gradio==4.40.0
|
| 4 |
+
|
| 5 |
+
# Essential dependencies
|
| 6 |
certifi>=2022.0.0
|
| 7 |
+
|
| 8 |
+
# Optional dependencies for future enhancements (commented out for minimal setup)
|
| 9 |
# imageio>=2.20.0
|
| 10 |
# transformers>=4.21.0
|
| 11 |
# torch>=1.12.0
|
|
|
|
| 17 |
# uvicorn>=0.20.0
|
| 18 |
# scipy>=1.9.0
|
| 19 |
# matplotlib>=3.5.0
|
| 20 |
+
# imageio-ffmpeg>=0.4.7
|
| 21 |
+
|
| 22 |
+
# Additional useful packages for enhanced functionality
|
| 23 |
+
# pandas>=1.3.0
|
| 24 |
+
# plotly>=5.0.0
|
| 25 |
+
# streamlit>=1.20.0 # Alternative UI framework if needed
|
test_components.py
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""
|
| 3 |
+
Component testing to identify schema validation issues
|
| 4 |
+
"""
|
| 5 |
+
|
| 6 |
+
import os
|
| 7 |
+
import ssl
|
| 8 |
+
|
| 9 |
+
# SSL fixes
|
| 10 |
+
try:
|
| 11 |
+
import certifi
|
| 12 |
+
os.environ['SSL_CERT_FILE'] = certifi.where()
|
| 13 |
+
os.environ['REQUESTS_CA_BUNDLE'] = certifi.where()
|
| 14 |
+
except ImportError:
|
| 15 |
+
pass
|
| 16 |
+
|
| 17 |
+
ssl._create_default_https_context = ssl._create_unverified_context
|
| 18 |
+
os.environ['PYTHONHTTPSVERIFY'] = '0'
|
| 19 |
+
|
| 20 |
+
import gradio as gr
|
| 21 |
+
|
| 22 |
+
def test_basic_components():
|
| 23 |
+
"""Test 1: Basic components only"""
|
| 24 |
+
with gr.Blocks(title="Test 1: Basic") as demo:
|
| 25 |
+
gr.HTML("<h1>Test 1: Basic Components</h1>")
|
| 26 |
+
|
| 27 |
+
vehicle_input = gr.Radio(choices=["Robot", "Drone"], value="Robot")
|
| 28 |
+
text_input = gr.Textbox(value="test")
|
| 29 |
+
button = gr.Button("Test")
|
| 30 |
+
output = gr.Textbox()
|
| 31 |
+
|
| 32 |
+
button.click(lambda v, t: f"{v}: {t}", [vehicle_input, text_input], output)
|
| 33 |
+
|
| 34 |
+
return demo
|
| 35 |
+
|
| 36 |
+
def test_with_slider():
|
| 37 |
+
"""Test 2: Add Slider component"""
|
| 38 |
+
with gr.Blocks(title="Test 2: With Slider") as demo:
|
| 39 |
+
gr.HTML("<h1>Test 2: With Slider</h1>")
|
| 40 |
+
|
| 41 |
+
vehicle_input = gr.Radio(choices=["Robot", "Drone"], value="Robot")
|
| 42 |
+
text_input = gr.Textbox(value="test")
|
| 43 |
+
slider_input = gr.Slider(0, 100, value=50)
|
| 44 |
+
button = gr.Button("Test")
|
| 45 |
+
output = gr.Textbox()
|
| 46 |
+
|
| 47 |
+
button.click(lambda v, t, s: f"{v}: {t}, {s}", [vehicle_input, text_input, slider_input], output)
|
| 48 |
+
|
| 49 |
+
return demo
|
| 50 |
+
|
| 51 |
+
def test_with_json():
|
| 52 |
+
"""Test 3: Add JSON component"""
|
| 53 |
+
with gr.Blocks(title="Test 3: With JSON") as demo:
|
| 54 |
+
gr.HTML("<h1>Test 3: With JSON</h1>")
|
| 55 |
+
|
| 56 |
+
vehicle_input = gr.Radio(choices=["Robot", "Drone"], value="Robot")
|
| 57 |
+
text_input = gr.Textbox(value="test")
|
| 58 |
+
button = gr.Button("Test")
|
| 59 |
+
output = gr.Textbox()
|
| 60 |
+
json_output = gr.JSON()
|
| 61 |
+
|
| 62 |
+
def test_func(v, t):
|
| 63 |
+
return f"{v}: {t}", {"vehicle": v, "text": t}
|
| 64 |
+
|
| 65 |
+
button.click(test_func, [vehicle_input, text_input], [output, json_output])
|
| 66 |
+
|
| 67 |
+
return demo
|
| 68 |
+
|
| 69 |
+
def test_with_image():
|
| 70 |
+
"""Test 4: Add Image component"""
|
| 71 |
+
with gr.Blocks(title="Test 4: With Image") as demo:
|
| 72 |
+
gr.HTML("<h1>Test 4: With Image</h1>")
|
| 73 |
+
|
| 74 |
+
vehicle_input = gr.Radio(choices=["Robot", "Drone"], value="Robot")
|
| 75 |
+
text_input = gr.Textbox(value="test")
|
| 76 |
+
button = gr.Button("Test")
|
| 77 |
+
output = gr.Textbox()
|
| 78 |
+
image_output = gr.Image()
|
| 79 |
+
|
| 80 |
+
button.click(lambda v, t: (f"{v}: {t}", None), [vehicle_input, text_input], [output, image_output])
|
| 81 |
+
|
| 82 |
+
return demo
|
| 83 |
+
|
| 84 |
+
def test_with_file():
|
| 85 |
+
"""Test 5: Add File component"""
|
| 86 |
+
with gr.Blocks(title="Test 5: With File") as demo:
|
| 87 |
+
gr.HTML("<h1>Test 5: With File</h1>")
|
| 88 |
+
|
| 89 |
+
vehicle_input = gr.Radio(choices=["Robot", "Drone"], value="Robot")
|
| 90 |
+
text_input = gr.Textbox(value="test")
|
| 91 |
+
button = gr.Button("Test")
|
| 92 |
+
output = gr.Textbox()
|
| 93 |
+
file_output = gr.File()
|
| 94 |
+
|
| 95 |
+
button.click(lambda v, t: (f"{v}: {t}", None), [vehicle_input, text_input], [output, file_output])
|
| 96 |
+
|
| 97 |
+
return demo
|
| 98 |
+
|
| 99 |
+
if __name__ == "__main__":
|
| 100 |
+
tests = [
|
| 101 |
+
("Basic Components", test_basic_components),
|
| 102 |
+
("With Slider", test_with_slider),
|
| 103 |
+
("With JSON", test_with_json),
|
| 104 |
+
("With Image", test_with_image),
|
| 105 |
+
("With File", test_with_file)
|
| 106 |
+
]
|
| 107 |
+
|
| 108 |
+
for i, (name, test_func) in enumerate(tests, 1):
|
| 109 |
+
print(f"\n{'='*50}")
|
| 110 |
+
print(f"Testing {i}: {name}")
|
| 111 |
+
print(f"{'='*50}")
|
| 112 |
+
|
| 113 |
+
try:
|
| 114 |
+
demo = test_func()
|
| 115 |
+
print(f"β
{name} - Demo created successfully")
|
| 116 |
+
|
| 117 |
+
# Try to launch briefly to trigger schema validation
|
| 118 |
+
try:
|
| 119 |
+
demo.launch(
|
| 120 |
+
server_port=7860 + i,
|
| 121 |
+
share=False,
|
| 122 |
+
prevent_thread_lock=True,
|
| 123 |
+
quiet=True
|
| 124 |
+
)
|
| 125 |
+
print(f"β
{name} - Launched successfully")
|
| 126 |
+
demo.close()
|
| 127 |
+
except Exception as e:
|
| 128 |
+
print(f"β {name} - Launch failed: {e}")
|
| 129 |
+
if "bool" in str(e) and "iterable" in str(e):
|
| 130 |
+
print(f"π― FOUND IT! {name} causes the schema error!")
|
| 131 |
+
break
|
| 132 |
+
|
| 133 |
+
except Exception as e:
|
| 134 |
+
print(f"β {name} - Creation failed: {e}")
|
| 135 |
+
if "bool" in str(e) and "iterable" in str(e):
|
| 136 |
+
print(f"π― FOUND IT! {name} causes the schema error!")
|
| 137 |
+
break
|
| 138 |
+
|
| 139 |
+
print("\n" + "="*50)
|
| 140 |
+
print("Component testing complete!")
|