Spaces:
Runtime error
Runtime error
Commit Β·
4f8340a
1
Parent(s): c4c0f29
Add comprehensive API documentation and testing functionality
Browse files- Add detailed API endpoint information in the interface
- Include request/response format examples for Thunkable integration
- Add API test function to verify detection pipeline works
- Explain that 'No API found' message is normal for Gradio 4.36.0
- Show API test results in the interface for debugging
338 unmodified lines33934034134234334413 unmodified lines35835936036136236336436524 unmodified lines390391392393394395396397398399400401402338 unmodified linesprint(f"β Traceback: {traceback.format_exc()}")return False# Load models on startupprint("Loading RetinaFace models...")print("Running model loading test...")13 unmodified linesif model_loaded:gr.Markdown("β **Status**: Models loaded successfully!")else:gr.Markdown("β **Status**: Error loading models")with gr.Row():with gr.Column():24 unmodified lines)gr.Markdown("""## API UsageUse `/api/predict` endpoint with:```json{"data": [image, "mobilenet", 0.5, 0.4]}```""")return demo338 unmodified lines33934034134234334434534634734834935035135235335435535635735835936036136236336413 unmodified lines37837938038138238338438538638738838924 unmodified lines414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461338 unmodified linesprint(f"β Traceback: {traceback.format_exc()}")return False# API test functiondef test_api_endpoint():"""Test function to verify API is working"""try:# Create a simple test imageimport numpy as nptest_img = np.random.randint(0, 255, (100, 100, 3), dtype=np.uint8)test_pil = Image.fromarray(test_img)# Test the detect_faces function directlyresult_img, result_text = detect_faces(test_pil, "mobilenet", 0.5, 0.4)if result_img is not None:return "β API function test passed - detection pipeline works"else:return f"β API function test failed: {result_text}"except Exception as e:return f"β API test error: {str(e)}"# Load models on startupprint("Loading RetinaFace models...")print("Running model loading test...")13 unmodified linesif model_loaded:gr.Markdown("β **Status**: Models loaded successfully!")# Test API functionalityapi_test_result = test_api_endpoint()gr.Markdown(f"π§ **API Test**: {api_test_result}")else:gr.Markdown("β **Status**: Error loading models")gr.Markdown("π§ **API Test**: Cannot test API - models not loaded")with gr.Row():with gr.Column():24 unmodified lines)gr.Markdown("""## π API Information**Your API is automatically available at these endpoints:**### Main API Endpoint```POST /api/predict```**Request format:**```json{"data": ["<image_as_PIL_or_path>","mobilenet",0.5,0.4]}```**Response format:**```json{"data": ["<processed_image>","**Detection Results:**\\n- **Faces Detected:** 2\\n..."]}```### For Thunkable Integration:- **URL:** `https://aditya-g07-retinaface-face-detection.hf.space/api/predict`- **Method:** POST- **Content-Type:** application/json### API Status:- β **Gradio auto-generates API endpoints**- β **No additional configuration needed**- β **"No API found" message is normal for Gradio 4.36.0****Note:** The "No API found" error in the UI doesn't affect API functionality.""")return demo
app.py+62-3