kenichi9999999 commited on
Commit
a0816e0
·
1 Parent(s): 587a88a
contbk/gra_05_files/files.py CHANGED
@@ -75,5 +75,5 @@ def build_interface(base_directory):
75
 
76
 
77
 
78
- base_directory = "/home/user/app/routers" # Here you can specify any directory you want to explore
79
  gradio_interface = build_interface(base_directory)
 
75
 
76
 
77
 
78
+ base_directory = "/home/user/app/controllers/github" # Here you can specify any directory you want to explore
79
  gradio_interface = build_interface(base_directory)
controllers/gra_05_files/chat.py ADDED
@@ -0,0 +1,115 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import shutil
2
+ import gradio as gr
3
+ from mysite.libs.utilities import chat_with_interpreter, completion, process_file
4
+ from interpreter import interpreter
5
+ import mysite.interpreter.interpreter_config # インポートするだけで設定が適用されます
6
+ import importlib
7
+ import os
8
+ import pkgutil
9
+ import async_timeout
10
+ import asyncio
11
+
12
+
13
+ DESCRIPTION = """
14
+ <div>
15
+ <h1 style="text-align: center;">develop site</h1>
16
+ <p>🦕 共同開発 AIシステム設定 LINE開発 CHATGPTS CHATGPTアシスタント設定 AI自動開発設定 APPSHEET GAS PYTHON</p>
17
+ </div>
18
+ <!-- Start of HubSpot Embed Code -->
19
+ <script type="text/javascript" id="hs-script-loader" async defer src="//js-na1.hs-scripts.com/46277896.js"></script>
20
+ <!-- End of HubSpot Embed Code -->
21
+ """
22
+
23
+ LICENSE = """
24
+ <p/>
25
+ <!-- Start of HubSpot Embed Code -->
26
+ <script type="text/javascript" id="hs-script-loader" async defer src="//js-na1.hs-scripts.com/46277896.js"></script>
27
+ <!-- End of HubSpot Embed Code -->
28
+ ---
29
+ Built with Meta Llama 3
30
+ """
31
+
32
+ PLACEHOLDER = """
33
+ <div style="padding: 30px; text-align: center; display: flex; flex-direction: column; align-items: center;">
34
+ <img src="https://ysharma-dummy-chat-app.hf.space/file=/tmp/gradio/8e75e61cc9bab22b7ce3dec85ab0e6db1da5d107/Meta_lockup_positive%20primary_RGB.jpg" style="width: 80%; max-width: 550px; height: auto; opacity: 0.55; ">
35
+ <h1 style="font-size: 28px; margin-bottom: 2px; opacity: 0.55;">Meta llama3</h1>
36
+ <p style="font-size: 18px; margin-bottom: 2px; opacity: 0.65;">Ask me anything...</p>
37
+ </div>
38
+ """
39
+
40
+
41
+ # チャットインターフェースの関数定義
42
+ # def chat_with_interpreter(message):
43
+ # return "Response: " + message
44
+
45
+
46
+ # カスタムCSSの定義
47
+ css = """
48
+ .gradio-container {
49
+ height: 100vh; /* 全体の高さを100vhに設定 */
50
+ display: flex;
51
+ flex-direction: column;
52
+ }
53
+ .gradio-tabs {
54
+ flex: 1; /* タブ全体の高さを最大に設定 */
55
+ display: flex;
56
+ flex-direction: column;
57
+ }
58
+ .gradio-tab-item {
59
+ flex: 1; /* 各タブの高さを最大に設定 */
60
+ display: flex;
61
+ flex-direction: column;
62
+ overflow: hidden; /* オーバーフローを隠す */
63
+ }
64
+ .gradio-block {
65
+ flex: 1; /* ブロックの高さを最大に設定 */
66
+ display: flex;
67
+ flex-direction: column;
68
+ }
69
+ .gradio-chatbot {
70
+ height: 100vh; /* チャットボットの高さを100vhに設定 */
71
+ overflow-y: auto; /* 縦スクロールを有効にする */
72
+ }
73
+ """
74
+ GENERATION_TIMEOUT_SEC = 60
75
+ # Gradio block
76
+ chatbot2 = gr.Chatbot(height=450, placeholder=PLACEHOLDER, label="Gradio ChatInterface")
77
+
78
+ with gr.Blocks(fill_height=True, css=css) as chat:
79
+ # gr.Markdown(DESCRIPTION)
80
+ # gr.DuplicateButton(value="Duplicate Space for private use", elem_id="duplicate-button")
81
+ gr.ChatInterface(
82
+ fn=completion,
83
+ chatbot=chatbot2,
84
+ fill_height=True,
85
+ additional_inputs_accordion=gr.Accordion(
86
+ label="⚙️ Parameters", open=False, render=False
87
+ ),
88
+ additional_inputs=[
89
+ gr.Slider(
90
+ minimum=0,
91
+ maximum=1,
92
+ step=0.1,
93
+ value=0.95,
94
+ label="Temperature",
95
+ render=False,
96
+ ),
97
+ gr.Slider(
98
+ minimum=128,
99
+ maximum=4096,
100
+ step=1,
101
+ value=512,
102
+ label="Max new tokens",
103
+ render=False,
104
+ ),
105
+ ],
106
+ examples=[
107
+ ["HTMLのサンプルを作成して"],
108
+ [
109
+ "CUDA_VISIBLE_DEVICES=0 llamafactory-cli train examples/lora_single_gpu/llama3_lora_sft.yaml"
110
+ ],
111
+ ],
112
+ cache_examples=False,
113
+ )
114
+
115
+ gr.Markdown(LICENSE)
controllers/gra_05_files/files.py ADDED
@@ -0,0 +1,79 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import shutil
2
+ import gradio as gr
3
+ from mysite.libs.utilities import chat_with_interpreter, completion, process_file
4
+ from interpreter import interpreter
5
+ import mysite.interpreter.interpreter_config # インポートするだけで設定が適用されます
6
+ import importlib
7
+ import os
8
+ import pkgutil
9
+ import async_timeout
10
+ import asyncio
11
+
12
+
13
+ def list_files_in_directory(directory):
14
+ tree = []
15
+ for root, dirs, files in os.walk(directory):
16
+ path = root.split(os.sep)
17
+ for dir_name in dirs:
18
+ tree.append((os.path.join(root, dir_name), '/'.join(path + [dir_name])))
19
+ for file_name in files:
20
+ tree.append((os.path.join(root, file_name), '/'.join(path + [file_name])))
21
+ return tree
22
+
23
+ def read_file(file_path):
24
+ try:
25
+ with open(file_path, 'r', encoding='utf-8') as file:
26
+ return file.read()
27
+ except UnicodeDecodeError:
28
+ with open(file_path, 'rb') as file:
29
+ content = file.read()
30
+ try:
31
+ return content.decode('utf-8')
32
+ except UnicodeDecodeError:
33
+ try:
34
+ return content.decode('latin-1')
35
+ except UnicodeDecodeError:
36
+ return "Cannot decode file content with utf-8 or latin-1 encoding."
37
+
38
+ def save_file(file_path, content):
39
+ with open(file_path, 'w', encoding='utf-8') as file:
40
+ file.write(content)
41
+ return "File saved successfully"
42
+
43
+ def on_file_select(selected_file):
44
+ if os.path.isfile(selected_file):
45
+ return read_file(selected_file)
46
+ return ""
47
+
48
+ def build_interface(base_directory):
49
+ file_list = list_files_in_directory(base_directory)
50
+ file_display = [f[1] for f in file_list]
51
+ file_paths = {f[1]: f[0] for f in file_list}
52
+
53
+ with gr.Blocks() as demo:
54
+ gr.Markdown("## File Explorer and Editor")
55
+
56
+ file_dropdown = gr.Dropdown(label="Select a file or folder", choices=file_display)
57
+ file_editor = gr.Textbox(label="File Editor", lines=20)
58
+ save_button = gr.Button("Save File")
59
+
60
+ def update_editor(selected_display):
61
+ selected_file = file_paths.get(selected_display, "")
62
+ return on_file_select(selected_file)
63
+
64
+ def on_edit_button_click(selected_display, new_content):
65
+ selected_file = file_paths.get(selected_display, "")
66
+ if os.path.isfile(selected_file):
67
+ return save_file(selected_file, new_content)
68
+ return "File not found"
69
+
70
+ file_dropdown.change(fn=update_editor, inputs=file_dropdown, outputs=file_editor)
71
+ save_button.click(fn=on_edit_button_click, inputs=[file_dropdown, file_editor], outputs=None)
72
+
73
+ return demo
74
+
75
+
76
+
77
+
78
+ base_directory = "/home/user/app/controllers/github" # Here you can specify any directory you want to explore
79
+ gradio_interface = build_interface(base_directory)