Commit
·
bbef4d5
1
Parent(s):
b2d865a
Update app.py
Browse files
app.py
CHANGED
|
@@ -138,12 +138,23 @@ def write_file(file_path, content):
|
|
| 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):
|
|
@@ -210,7 +221,7 @@ with gr.Blocks(css = """#col_container {width: 1400px; margin-left: auto; margin
|
|
| 210 |
listFiles.click(list_files, inputs=fileName, outputs=fileContent)
|
| 211 |
readFile.click(read_file, inputs=fileName, outputs=fileContent)
|
| 212 |
saveFile.click(write_file, inputs=[fileName, fileContent], outputs=completedMessage)
|
| 213 |
-
downloadFile.click(
|
| 214 |
deleteFile.click(delete_file, inputs=fileName, outputs=completedMessage)
|
| 215 |
appendFile.click(append_file, inputs=[fileName, fileContent], outputs=completedMessage )
|
| 216 |
|
|
|
|
| 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 |
+
def download_file(file_path, content):
|
| 149 |
+
# Get the user's desktop directory
|
| 150 |
+
desktop_dir = os.path.join(os.path.join(os.path.expanduser('~')), 'Desktop')
|
| 151 |
+
|
| 152 |
+
# Write the input to a new file on the desktop
|
| 153 |
+
with open(os.path.join(desktop_dir, file_path), "w") as f:
|
| 154 |
+
f.write(content)
|
| 155 |
+
|
| 156 |
+
return "File saved to desktop!"
|
| 157 |
+
|
| 158 |
|
| 159 |
# Function to append to a file
|
| 160 |
def append_file(file_path, content):
|
|
|
|
| 221 |
listFiles.click(list_files, inputs=fileName, outputs=fileContent)
|
| 222 |
readFile.click(read_file, inputs=fileName, outputs=fileContent)
|
| 223 |
saveFile.click(write_file, inputs=[fileName, fileContent], outputs=completedMessage)
|
| 224 |
+
downloadFile.click(download_file, inputs=[fileName, fileContent], outputs=completedMessage)
|
| 225 |
deleteFile.click(delete_file, inputs=fileName, outputs=completedMessage)
|
| 226 |
appendFile.click(append_file, inputs=[fileName, fileContent], outputs=completedMessage )
|
| 227 |
|