Commit
·
b41883d
1
Parent(s):
74f00ae
Update app.py
Browse files
app.py
CHANGED
@@ -130,10 +130,21 @@ def write_file(file_path, content):
|
|
130 |
try:
|
131 |
with open(file_path, "w") as file:
|
132 |
file.write(content)
|
133 |
-
|
|
|
|
|
|
|
|
|
134 |
except:
|
135 |
return "Error occurred while writing to file."
|
136 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
137 |
# Function to append to a file
|
138 |
def append_file(file_path, content):
|
139 |
try:
|
@@ -187,12 +198,14 @@ with gr.Blocks(css = """#col_container {width: 1400px; margin-left: auto; margin
|
|
187 |
fileContent = gr.TextArea(label="File Content")
|
188 |
completedMessage = gr.Textbox(label="Completed")
|
189 |
label = gr.Label()
|
|
|
190 |
with gr.Row():
|
191 |
listFiles = gr.Button("📄 List File(s)")
|
192 |
readFile = gr.Button("📖 Read File")
|
193 |
saveFile = gr.Button("💾 Save File")
|
194 |
deleteFile = gr.Button("🗑️ Delete File")
|
195 |
appendFile = gr.Button("➕ Append File")
|
|
|
196 |
listFiles.click(list_files, inputs=fileName, outputs=fileContent)
|
197 |
readFile.click(read_file, inputs=fileName, outputs=fileContent)
|
198 |
saveFile.click(write_file, inputs=[fileName, fileContent], outputs=completedMessage)
|
|
|
130 |
try:
|
131 |
with open(file_path, "w") as file:
|
132 |
file.write(content)
|
133 |
+
with open(file_path, "rb") as file:
|
134 |
+
contents = file.read()
|
135 |
+
b64 = base64.b64encode(contents).decode()
|
136 |
+
href = f'<a href="data:application/octet-stream;base64,{b64}" download="{file_path}">Download</a>'
|
137 |
+
return f"Successfully written to {file_path}.", href
|
138 |
except:
|
139 |
return "Error occurred while writing to file."
|
140 |
|
141 |
+
def download_link(file_path):
|
142 |
+
with open(file_path, "rb") as file:
|
143 |
+
contents = file.read()
|
144 |
+
b64 = base64.b64encode(contents).decode()
|
145 |
+
href = f'<a href="data:application/octet-stream;base64,{b64}" download="{file_path}">Download</a>'
|
146 |
+
return href
|
147 |
+
|
148 |
# Function to append to a file
|
149 |
def append_file(file_path, content):
|
150 |
try:
|
|
|
198 |
fileContent = gr.TextArea(label="File Content")
|
199 |
completedMessage = gr.Textbox(label="Completed")
|
200 |
label = gr.Label()
|
201 |
+
|
202 |
with gr.Row():
|
203 |
listFiles = gr.Button("📄 List File(s)")
|
204 |
readFile = gr.Button("📖 Read File")
|
205 |
saveFile = gr.Button("💾 Save File")
|
206 |
deleteFile = gr.Button("🗑️ Delete File")
|
207 |
appendFile = gr.Button("➕ Append File")
|
208 |
+
|
209 |
listFiles.click(list_files, inputs=fileName, outputs=fileContent)
|
210 |
readFile.click(read_file, inputs=fileName, outputs=fileContent)
|
211 |
saveFile.click(write_file, inputs=[fileName, fileContent], outputs=completedMessage)
|