Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from pathlib import Path
|
3 |
+
|
4 |
+
current_file_path = Path(__file__).resolve()
|
5 |
+
relative_path = "path/to/file"
|
6 |
+
absolute_path = (current_file_path.parent / ".." / ".." / "gradio").resolve()
|
7 |
+
|
8 |
+
def get_file_content(file):
|
9 |
+
return (file,)
|
10 |
+
|
11 |
+
with gr.Blocks() as demo:
|
12 |
+
gr.Markdown("---")
|
13 |
+
gr.Markdown('### `FileExplorer` to `Code` -- `file_count="single"`')
|
14 |
+
with gr.Group():
|
15 |
+
with gr.Row():
|
16 |
+
file_3 = gr.FileExplorer(
|
17 |
+
scale=1,
|
18 |
+
glob="**/components/**/*.py",
|
19 |
+
value=["themes/utils"],
|
20 |
+
file_count="single",
|
21 |
+
root_dir=absolute_path,
|
22 |
+
ignore_glob="**/__init__.py",
|
23 |
+
elem_id="file",
|
24 |
+
)
|
25 |
+
|
26 |
+
code = gr.Code(lines=30, scale=2, language="python")
|
27 |
+
|
28 |
+
file_3.change(get_file_content, file_3, code)
|
29 |
+
|
30 |
+
if __name__ == "__main__":
|
31 |
+
demo.launch()
|