Update app.py
Browse files
app.py
CHANGED
@@ -1,5 +1,19 @@
|
|
1 |
import gradio as gr
|
2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
# Function to read a file
|
4 |
def read_file(file_path):
|
5 |
try:
|
@@ -45,11 +59,13 @@ with demo:
|
|
45 |
|
46 |
label = gr.Label()
|
47 |
|
|
|
48 |
readFile = gr.Button("Read File")
|
49 |
saveFile = gr.Button("Save File")
|
50 |
deleteFile = gr.Button("Delete File")
|
51 |
appendFile = gr.Button("Append File")
|
52 |
|
|
|
53 |
readFile.click(read_file, inputs=fileName, outputs=fileContent)
|
54 |
saveFile.click(write_file, inputs=[fileName, fileContent], outputs=completedMessage)
|
55 |
deleteFile.click(delete_file, inputs=fileName, outputs=completedMessage)
|
|
|
1 |
import gradio as gr
|
2 |
|
3 |
+
|
4 |
+
# Function to list files with .csv and .txt extensions in the current directory
|
5 |
+
def list_files(file_path):
|
6 |
+
import os
|
7 |
+
current_directory = os.getcwd()
|
8 |
+
file_list = []
|
9 |
+
for filename in os.listdir(current_directory):
|
10 |
+
if filename.endswith(".csv") or filename.endswith(".txt"):
|
11 |
+
file_list.append(filename)
|
12 |
+
if file_list:
|
13 |
+
return "\n".join(file_list)
|
14 |
+
else:
|
15 |
+
return "No .csv or .txt files found in the current directory."
|
16 |
+
|
17 |
# Function to read a file
|
18 |
def read_file(file_path):
|
19 |
try:
|
|
|
59 |
|
60 |
label = gr.Label()
|
61 |
|
62 |
+
listFiles = gr.Button("List CSV and TXT File(s)")
|
63 |
readFile = gr.Button("Read File")
|
64 |
saveFile = gr.Button("Save File")
|
65 |
deleteFile = gr.Button("Delete File")
|
66 |
appendFile = gr.Button("Append File")
|
67 |
|
68 |
+
listFiles.click(list_files, inputs=fileName, outputs=fileContent)
|
69 |
readFile.click(read_file, inputs=fileName, outputs=fileContent)
|
70 |
saveFile.click(write_file, inputs=[fileName, fileContent], outputs=completedMessage)
|
71 |
deleteFile.click(delete_file, inputs=fileName, outputs=completedMessage)
|