File size: 3,069 Bytes
c71b48d
 
8f54139
933a7e0
8f54139
bf36acb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8f54139
c71b48d
 
 
8f54139
 
 
c71b48d
8f54139
c71b48d
8f54139
c71b48d
 
8f54139
c71b48d
8f54139
c71b48d
8f54139
c71b48d
8f54139
c71b48d
 
 
 
8f54139
c71b48d
8f54139
c71b48d
8f54139
c71b48d
 
 
 
8f54139
c71b48d
8f54139
c71b48d
8f54139
 
 
 
 
 
 
f05a5d2
1abfb38
f05a5d2
 
 
 
8f54139
 
 
 
 
 
6251d32
e3dc8e9
6251d32
 
 
 
 
 
 
3037481
 
6251d32
 
3037481
6251d32
8f54139
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import gradio as gr

# Function to list files with .csv and .txt extensions in the current directory
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."

# Function to read a file
def read_file(file_path):
    try:
        with open(file_path, "r") as file:
            contents = file.read()
            return f"{contents}"
            #return f"Contents of {file_path}:\n{contents}"
    except FileNotFoundError:
        return "File not found."

# Function to delete a file
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."

# Function to write to a file
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."

# Function to append to a 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()