|
import gradio as gr |
|
|
|
|
|
def list_files(file_path): |
|
import os |
|
|
|
icon_csv = "π " |
|
icon_txt = "π " |
|
|
|
current_directory = os.getcwd() |
|
file_list = [] |
|
for filename in os.listdir(current_directory): |
|
if filename.endswith(".csv"): |
|
file_list.append(icon_csv + filename) |
|
elif filename.endswith(".txt"): |
|
file_list.append(icon_txt + filename) |
|
if file_list: |
|
return "\n".join(file_list) |
|
else: |
|
return "No .csv or .txt files found in the current directory." |
|
|
|
|
|
def read_file(file_path): |
|
try: |
|
with open(file_path, "r") as file: |
|
contents = file.read() |
|
return f"{contents}" |
|
|
|
except FileNotFoundError: |
|
return "File not found." |
|
|
|
|
|
def delete_file(file_path): |
|
try: |
|
import os |
|
os.remove(file_path) |
|
return f"{file_path} has been deleted." |
|
except FileNotFoundError: |
|
return "File not found." |
|
|
|
|
|
def write_file(file_path, content): |
|
try: |
|
with open(file_path, "w") as file: |
|
file.write(content) |
|
return f"Successfully written to {file_path}." |
|
except: |
|
return "Error occurred while writing to file." |
|
|
|
|
|
def append_file(file_path, content): |
|
try: |
|
with open(file_path, "a") as file: |
|
file.write(content) |
|
return f"Successfully appended to {file_path}." |
|
except: |
|
return "Error occurred while appending to file." |
|
|
|
demo = gr.Blocks() |
|
with demo: |
|
fileName = gr.Textbox(label="Filename") |
|
fileContent = gr.TextArea(label="File Content") |
|
completedMessage = gr.Textbox(label="Completed") |
|
|
|
label = gr.Label() |
|
with gr.Row(): |
|
listFiles = gr.Button("π List File(s)") |
|
readFile = gr.Button("π Read File") |
|
saveFile = gr.Button("πΎ Save File") |
|
deleteFile = gr.Button("ποΈ Delete File") |
|
appendFile = gr.Button("β Append File") |
|
|
|
listFiles.click(list_files, inputs=fileName, outputs=fileContent) |
|
readFile.click(read_file, inputs=fileName, outputs=fileContent) |
|
saveFile.click(write_file, inputs=[fileName, fileContent], outputs=completedMessage) |
|
deleteFile.click(delete_file, inputs=fileName, outputs=completedMessage) |
|
appendFile.click(append_file, inputs=[fileName, fileContent], outputs=completedMessage ) |
|
|
|
gr.Markdown(""" |
|
π‘π§ π |
|
π€ππ |
|
ππ€£π |
|
π―π¨βπΌπ¬ |
|
πππ |
|
π±π»π |
|
|
|
π€ AI Feedback Memory System for Smart Communities π‘π§ π |
|
Remember important details about the people and places in your community. |
|
Input information and the system will use advanced algorithms ππ to help you remember key details. Plus, it's fun! π€£ππ. |
|
|
|
Available now on Hugging Face for all smart devices π±π»π. Enjoy! πππ |
|
""") |
|
|
|
demo.launch() |