Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,11 +1,14 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
import
|
|
|
|
|
|
|
| 3 |
|
| 4 |
-
# Create a
|
| 5 |
-
app =
|
| 6 |
|
|
|
|
| 7 |
@app.get("/d3-test")
|
| 8 |
-
def serve_test_page():
|
| 9 |
html_content = """
|
| 10 |
<!DOCTYPE html>
|
| 11 |
<html>
|
|
@@ -47,7 +50,7 @@ def serve_test_page():
|
|
| 47 |
try {
|
| 48 |
// Check if d3 is defined
|
| 49 |
if (typeof d3 !== 'undefined') {
|
| 50 |
-
statusDiv.textContent =
|
| 51 |
statusDiv.className = 'success';
|
| 52 |
|
| 53 |
// Create a simple SVG to verify D3 functions work
|
|
@@ -74,7 +77,7 @@ def serve_test_page():
|
|
| 74 |
statusDiv.className = 'error';
|
| 75 |
}
|
| 76 |
} catch (error) {
|
| 77 |
-
statusDiv.textContent =
|
| 78 |
statusDiv.className = 'error';
|
| 79 |
console.error('D3 test error:', error);
|
| 80 |
}
|
|
@@ -84,22 +87,29 @@ def serve_test_page():
|
|
| 84 |
</html>
|
| 85 |
"""
|
| 86 |
|
| 87 |
-
return
|
| 88 |
|
| 89 |
-
# Create a simple Gradio interface
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 90 |
with gr.Blocks() as demo:
|
| 91 |
gr.Markdown("# D3.js Load Test")
|
|
|
|
| 92 |
|
| 93 |
-
#
|
| 94 |
-
gr.HTML('<iframe src="/d3-test" style="width:100%; height:300px; border:none;"></iframe>')
|
| 95 |
-
|
| 96 |
-
# Add a refresh button
|
| 97 |
def refresh():
|
| 98 |
-
|
| 99 |
-
return f'<iframe src="/d3-test?t={timestamp}" style="width:100%; height:300px; border:none;"></iframe>'
|
| 100 |
|
| 101 |
-
gr.Button("Refresh Test").click(fn=refresh, outputs=
|
|
|
|
|
|
|
|
|
|
| 102 |
|
| 103 |
-
#
|
| 104 |
if __name__ == "__main__":
|
| 105 |
-
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import random
|
| 3 |
+
import fastapi
|
| 4 |
+
from fastapi import FastAPI
|
| 5 |
|
| 6 |
+
# Create a FastAPI app
|
| 7 |
+
app = FastAPI()
|
| 8 |
|
| 9 |
+
# Route to serve a simple D3.js test page
|
| 10 |
@app.get("/d3-test")
|
| 11 |
+
async def serve_test_page():
|
| 12 |
html_content = """
|
| 13 |
<!DOCTYPE html>
|
| 14 |
<html>
|
|
|
|
| 50 |
try {
|
| 51 |
// Check if d3 is defined
|
| 52 |
if (typeof d3 !== 'undefined') {
|
| 53 |
+
statusDiv.textContent = 'D3.js successfully loaded! (Version: ' + d3.version + ')';
|
| 54 |
statusDiv.className = 'success';
|
| 55 |
|
| 56 |
// Create a simple SVG to verify D3 functions work
|
|
|
|
| 77 |
statusDiv.className = 'error';
|
| 78 |
}
|
| 79 |
} catch (error) {
|
| 80 |
+
statusDiv.textContent = 'Error: ' + error.message;
|
| 81 |
statusDiv.className = 'error';
|
| 82 |
console.error('D3 test error:', error);
|
| 83 |
}
|
|
|
|
| 87 |
</html>
|
| 88 |
"""
|
| 89 |
|
| 90 |
+
return fastapi.responses.HTMLResponse(content=html_content)
|
| 91 |
|
| 92 |
+
# Create a simple Gradio interface with an iframe
|
| 93 |
+
def create_iframe():
|
| 94 |
+
# Add a random parameter to force reload
|
| 95 |
+
random_param = random.randint(1, 10000)
|
| 96 |
+
return f'<iframe src="/d3-test?t={random_param}" style="width:100%; height:300px; border:none;"></iframe>'
|
| 97 |
+
|
| 98 |
+
# Create the Gradio blocks
|
| 99 |
with gr.Blocks() as demo:
|
| 100 |
gr.Markdown("# D3.js Load Test")
|
| 101 |
+
iframe_output = gr.HTML(create_iframe())
|
| 102 |
|
| 103 |
+
# Refresh button
|
|
|
|
|
|
|
|
|
|
| 104 |
def refresh():
|
| 105 |
+
return create_iframe()
|
|
|
|
| 106 |
|
| 107 |
+
gr.Button("Refresh Test").click(fn=refresh, outputs=iframe_output)
|
| 108 |
+
|
| 109 |
+
# Mount the Gradio app to the FastAPI app
|
| 110 |
+
gr.mount_gradio_app(app, demo, path="/")
|
| 111 |
|
| 112 |
+
# Start the server
|
| 113 |
if __name__ == "__main__":
|
| 114 |
+
import uvicorn
|
| 115 |
+
uvicorn.run(app, host="0.0.0.0", port=7860)
|