Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -86,6 +86,64 @@ def predict(inputs, top_p, temperature, chat_counter, chatbot=[], history=[]):
|
|
86 |
def reset_textbox():
|
87 |
return gr.update(value='')
|
88 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
89 |
title = """<h1 align="center">Memory Chat Story Generator ChatGPT</h1>"""
|
90 |
description = """
|
91 |
## ChatGPT Datasets π
|
@@ -123,6 +181,25 @@ with gr.Blocks(css = """#col_container {width: 1400px; margin-left: auto; margin
|
|
123 |
temperature = gr.Slider( minimum=-0, maximum=5.0, value=1.0, step=0.1, interactive=True, label="Temperature",)
|
124 |
chat_counter = gr.Number(value=0, visible=True, precision=0)
|
125 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
126 |
inputs.submit(predict, [inputs, top_p, temperature,chat_counter, chatbot, state], [chatbot, state, chat_counter])
|
127 |
b1.click(predict, [inputs, top_p, temperature, chat_counter, chatbot, state], [chatbot, state, chat_counter])
|
128 |
b1.click(reset_textbox, [], [inputs])
|
|
|
86 |
def reset_textbox():
|
87 |
return gr.update(value='')
|
88 |
|
89 |
+
|
90 |
+
|
91 |
+
|
92 |
+
# Episodic and Semantic IO
|
93 |
+
def list_files(file_path):
|
94 |
+
import os
|
95 |
+
icon_csv = "π "
|
96 |
+
icon_txt = "π "
|
97 |
+
current_directory = os.getcwd()
|
98 |
+
file_list = []
|
99 |
+
for filename in os.listdir(current_directory):
|
100 |
+
if filename.endswith(".csv"):
|
101 |
+
file_list.append(icon_csv + filename)
|
102 |
+
elif filename.endswith(".txt"):
|
103 |
+
file_list.append(icon_txt + filename)
|
104 |
+
if file_list:
|
105 |
+
return "\n".join(file_list)
|
106 |
+
else:
|
107 |
+
return "No .csv or .txt files found in the current directory."
|
108 |
+
|
109 |
+
# Function to read a file
|
110 |
+
def read_file(file_path):
|
111 |
+
try:
|
112 |
+
with open(file_path, "r") as file:
|
113 |
+
contents = file.read()
|
114 |
+
return f"{contents}"
|
115 |
+
#return f"Contents of {file_path}:\n{contents}"
|
116 |
+
except FileNotFoundError:
|
117 |
+
return "File not found."
|
118 |
+
|
119 |
+
# Function to delete a file
|
120 |
+
def delete_file(file_path):
|
121 |
+
try:
|
122 |
+
import os
|
123 |
+
os.remove(file_path)
|
124 |
+
return f"{file_path} has been deleted."
|
125 |
+
except FileNotFoundError:
|
126 |
+
return "File not found."
|
127 |
+
|
128 |
+
# Function to write to a file
|
129 |
+
def write_file(file_path, content):
|
130 |
+
try:
|
131 |
+
with open(file_path, "w") as file:
|
132 |
+
file.write(content)
|
133 |
+
return f"Successfully written to {file_path}."
|
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:
|
140 |
+
with open(file_path, "a") as file:
|
141 |
+
file.write(content)
|
142 |
+
return f"Successfully appended to {file_path}."
|
143 |
+
except:
|
144 |
+
return "Error occurred while appending to file."
|
145 |
+
|
146 |
+
|
147 |
title = """<h1 align="center">Memory Chat Story Generator ChatGPT</h1>"""
|
148 |
description = """
|
149 |
## ChatGPT Datasets π
|
|
|
181 |
temperature = gr.Slider( minimum=-0, maximum=5.0, value=1.0, step=0.1, interactive=True, label="Temperature",)
|
182 |
chat_counter = gr.Number(value=0, visible=True, precision=0)
|
183 |
|
184 |
+
|
185 |
+
# Episodic/Semantic IO
|
186 |
+
fileName = gr.Textbox(label="Filename")
|
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)
|
199 |
+
deleteFile.click(delete_file, inputs=fileName, outputs=completedMessage)
|
200 |
+
appendFile.click(append_file, inputs=[fileName, fileContent], outputs=completedMessage )
|
201 |
+
|
202 |
+
|
203 |
inputs.submit(predict, [inputs, top_p, temperature,chat_counter, chatbot, state], [chatbot, state, chat_counter])
|
204 |
b1.click(predict, [inputs, top_p, temperature, chat_counter, chatbot, state], [chatbot, state, chat_counter])
|
205 |
b1.click(reset_textbox, [], [inputs])
|