cpuai commited on
Commit
91705d3
·
verified ·
1 Parent(s): 76c0ba0

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +43 -0
app.py ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """
3
+ Gradio set_static_paths() English demo
4
+ Run: python app.py
5
+ Requires: pip install "gradio>=5.31.0"
6
+ """
7
+
8
+ from pathlib import Path
9
+ import gradio as gr
10
+
11
+ # --------------------------------------------------------------------
12
+ # 1) Tell Gradio which directory should be exposed as a static folder.
13
+ # --------------------------------------------------------------------
14
+ BASE_DIR = Path(__file__).resolve().parent
15
+ STATIC_DIR = BASE_DIR / "static" # ./static
16
+
17
+ gr.set_static_paths([STATIC_DIR])
18
+
19
+ # --------------------------------------------------------------------
20
+ # 2) Build a minimal UI that references the static assets.
21
+ # --------------------------------------------------------------------
22
+ with gr.Blocks(title="Static Assets Demo") as demo:
23
+ gr.Markdown("## Static assets served via gr.set_static_paths()")
24
+ # Link to the static HTML page
25
+ gr.HTML(
26
+ '<a href="/gradio_api/file=static/index.html" target="_blank">'
27
+ "Open index.html"
28
+ "</a>"
29
+ )
30
+ # Display the static image
31
+ gr.HTML(
32
+ '<img src="/gradio_api/file=static/logo.png" style="max-width:200px;">'
33
+ )
34
+
35
+ # --------------------------------------------------------------------
36
+ # 3) Launch! allowed_paths keeps working even if you remove set_static_paths.
37
+ # --------------------------------------------------------------------
38
+ if __name__ == "__main__":
39
+ demo.launch(
40
+ server_name="0.0.0.0",
41
+ server_port=7860,
42
+ allowed_paths=[STATIC_DIR], # optional but recommended
43
+ )