import os import gradio as gr def list_files(file_path): return "\n".join([filename for filename in os.listdir() if filename.endswith((".csv", ".txt"))]) or "📂 No .csv or .txt files found in the current directory." def read_file(file_path): try: with open(file_path, "r") as file: return file.read() except FileNotFoundError: return "❌ File not found." def delete_file(file_path): try: 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." def add_emojis(interface): #interface.label = f"📂 {interface.label}" interface.title = f"📁 {interface.title}" interface.description = f"📂 {interface.description}" #interface.outputs.label = f"📄 {interface.outputs.label}" return interface demo = add_emojis(gr.Interface( fn=list_files, inputs=gr.Textbox(label="List CSV and TXT File(s)"), outputs="text", layout="vertical" )) demo2 = add_emojis(gr.Interface( fn=read_file, inputs=[ gr.Textbox(label="Read File"), gr.TextArea(label="✍️ File Content") ], outputs="text", layout="vertical" )) demo3 = add_emojis(gr.Interface( fn=write_file, inputs=[ gr.Textbox(label="Save File"), gr.TextArea(label="✍️ File Content") ], outputs="text", layout="vertical" )) demo4 = add_emojis(gr.Interface( fn=delete_file, inputs=gr.Textbox(label="Delete File"), outputs="text", layout="vertical" )) demo5 = add_emojis(gr.Interface( fn=append_file, inputs=[ gr.Textbox(label="Append File"), gr.TextArea(label="✍️ File Content") ], outputs="text", layout="vertical" )) demo.launch()