kenken999 commited on
Commit
3af7f80
β€’
1 Parent(s): 185f702
mysite/gradio_config.py CHANGED
@@ -36,7 +36,77 @@ def include_gradio_interfaces():
36
  print(f"Collected Gradio Interfaces: {gradio_names}")
37
  return gradio_interfaces, list(gradio_names)
38
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
39
 
 
 
 
 
40
 
41
 
42
  def setup_gradio_interfaces():
@@ -68,8 +138,8 @@ def setup_gradio_interfaces():
68
 
69
  from routers.postg.gradio_app import crud_interface
70
 
71
- default_interfaces = [demo4,democs,crud_interface()]
72
- default_names = ["demo4","δ»•ζ§˜ζ›Έγ‹γ‚‰δ½œζˆ","d1"]
73
 
74
  gradio_interfaces, gradio_names = include_gradio_interfaces()
75
 
 
36
  print(f"Collected Gradio Interfaces: {gradio_names}")
37
  return gradio_interfaces, list(gradio_names)
38
 
39
+ import os
40
+ import gradio as gr
41
+
42
+ def list_files_in_directory(directory):
43
+ tree = []
44
+ for root, dirs, files in os.walk(directory):
45
+ path = root.split(os.sep)
46
+ for dir_name in dirs:
47
+ tree.append((os.path.join(root, dir_name), '/'.join(path + [dir_name])))
48
+ for file_name in files:
49
+ tree.append((os.path.join(root, file_name), '/'.join(path + [file_name])))
50
+ return tree
51
+
52
+ def read_file(file_path):
53
+ try:
54
+ with open(file_path, 'r', encoding='utf-8') as file:
55
+ return file.read()
56
+ except UnicodeDecodeError:
57
+ with open(file_path, 'rb') as file:
58
+ content = file.read()
59
+ try:
60
+ return content.decode('utf-8')
61
+ except UnicodeDecodeError:
62
+ try:
63
+ return content.decode('latin-1')
64
+ except UnicodeDecodeError:
65
+ return "Cannot decode file content with utf-8 or latin-1 encoding."
66
+
67
+ def save_file(file_path, content):
68
+ with open(file_path, 'w', encoding='utf-8') as file:
69
+ file.write(content)
70
+ return "File saved successfully"
71
+
72
+ def on_file_select(selected_file):
73
+ if os.path.isfile(selected_file):
74
+ return read_file(selected_file)
75
+ return ""
76
+
77
+ def build_interface(base_directory):
78
+ file_list = list_files_in_directory(base_directory)
79
+ file_display = [f[1] for f in file_list]
80
+ file_paths = {f[1]: f[0] for f in file_list}
81
+
82
+ with gr.Blocks() as demo:
83
+ gr.Markdown("## File Explorer and Editor")
84
+
85
+ file_dropdown = gr.Dropdown(label="Select a file or folder", choices=file_display)
86
+ file_editor = gr.Textbox(label="File Editor", lines=20)
87
+ save_button = gr.Button("Save File")
88
+
89
+ def update_editor(selected_display):
90
+ selected_file = file_paths.get(selected_display, "")
91
+ return on_file_select(selected_file)
92
+
93
+ def on_edit_button_click(selected_display, new_content):
94
+ selected_file = file_paths.get(selected_display, "")
95
+ if os.path.isfile(selected_file):
96
+ return save_file(selected_file, new_content)
97
+ return "File not found"
98
+
99
+ file_dropdown.change(fn=update_editor, inputs=file_dropdown, outputs=file_editor)
100
+ save_button.click(fn=on_edit_button_click, inputs=[file_dropdown, file_editor], outputs=None)
101
+
102
+ return demo
103
+
104
+
105
 
106
+ #if __name__ == "__main__":
107
+ base_directory = "/home/user/app/routers" # Here you can specify any directory you want to explore
108
+ demo = build_interface(base_directory)
109
+ #demo.launch()
110
 
111
 
112
  def setup_gradio_interfaces():
 
138
 
139
  from routers.postg.gradio_app import crud_interface
140
 
141
+ default_interfaces = [demo4,democs,crud_interface()]#,demo]
142
+ default_names = ["OpenInterpreter","δ»•ζ§˜ζ›Έγ‹γ‚‰δ½œζˆ","Database",]#"demo"]
143
 
144
  gradio_interfaces, gradio_names = include_gradio_interfaces()
145
 
routers/ai/tests/test_gradio_interface.py CHANGED
@@ -1,6 +1,6 @@
1
  import pytest
2
  from gradio_interface import gradio_interface
3
-
4
  def test_gradio_interface():
5
  # implement tests for Gradio frontend
6
  pass
 
1
  import pytest
2
  from gradio_interface import gradio_interface
3
+ ##########
4
  def test_gradio_interface():
5
  # implement tests for Gradio frontend
6
  pass