Update app.py
Browse files
app.py
CHANGED
@@ -5,13 +5,71 @@ api = gr.Interface.load("models/bigscience/bloom")
|
|
5 |
|
6 |
def change_textbox(choice, textin):
|
7 |
if choice == "Expository":
|
8 |
-
return textin[:-50] + api(textin[-50:])
|
9 |
elif choice == "Narrative":
|
10 |
-
return textin[:-50] + api(textin[-50:])
|
|
|
11 |
else:
|
12 |
-
return textin[:-50] + api(textin[-50:])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
|
14 |
with gr.Blocks() as block:
|
|
|
|
|
|
|
|
|
15 |
radio = gr.Radio(
|
16 |
["Expository", "Narrative", "Opinion"], label="What kind of essay would you like to write?"
|
17 |
)
|
@@ -21,5 +79,19 @@ with gr.Blocks() as block:
|
|
21 |
textout = gr.Textbox(lines=2, interactive=True)
|
22 |
textout.update(lines=8, visible=True)
|
23 |
|
24 |
-
radio.change(fn=change_textbox, inputs=[radio, textin], outputs=textout)
|
25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
|
6 |
def change_textbox(choice, textin):
|
7 |
if choice == "Expository":
|
8 |
+
return [textin[:-50] + api(textin[-50:]), api(textin[-50:])]
|
9 |
elif choice == "Narrative":
|
10 |
+
#return textin[:-50] + api(textin[-50:])
|
11 |
+
return [textin[:-50] + api(textin[-50:]), api(textin[-50:])]
|
12 |
else:
|
13 |
+
#return textin[:-50] + api(textin[-50:])
|
14 |
+
return [textin[:-50] + api(textin[-50:]), api(textin[-50:])]
|
15 |
+
|
16 |
+
|
17 |
+
|
18 |
+
# Function to list files with .csv and .txt extensions in the current directory
|
19 |
+
def list_files(file_path):
|
20 |
+
import os
|
21 |
+
current_directory = os.getcwd()
|
22 |
+
file_list = []
|
23 |
+
for filename in os.listdir(current_directory):
|
24 |
+
if filename.endswith(".csv") or filename.endswith(".txt"):
|
25 |
+
file_list.append(filename)
|
26 |
+
if file_list:
|
27 |
+
return "\n".join(file_list)
|
28 |
+
else:
|
29 |
+
return "No .csv or .txt files found in the current directory."
|
30 |
+
|
31 |
+
# Function to read a file
|
32 |
+
def read_file(file_path):
|
33 |
+
try:
|
34 |
+
with open(file_path, "r") as file:
|
35 |
+
contents = file.read()
|
36 |
+
return f"{contents}"
|
37 |
+
#return f"Contents of {file_path}:\n{contents}"
|
38 |
+
except FileNotFoundError:
|
39 |
+
return "File not found."
|
40 |
+
|
41 |
+
# Function to delete a file
|
42 |
+
def delete_file(file_path):
|
43 |
+
try:
|
44 |
+
import os
|
45 |
+
os.remove(file_path)
|
46 |
+
return f"{file_path} has been deleted."
|
47 |
+
except FileNotFoundError:
|
48 |
+
return "File not found."
|
49 |
+
|
50 |
+
# Function to write to a file
|
51 |
+
def write_file(file_path, content):
|
52 |
+
try:
|
53 |
+
with open(file_path, "w") as file:
|
54 |
+
file.write(content)
|
55 |
+
return f"Successfully written to {file_path}."
|
56 |
+
except:
|
57 |
+
return "Error occurred while writing to file."
|
58 |
+
|
59 |
+
# Function to append to a file
|
60 |
+
def append_file(file_path, content):
|
61 |
+
try:
|
62 |
+
with open(file_path, "a") as file:
|
63 |
+
file.write(content)
|
64 |
+
return f"Successfully appended to {file_path}."
|
65 |
+
except:
|
66 |
+
return "Error occurred while appending to file."
|
67 |
|
68 |
with gr.Blocks() as block:
|
69 |
+
fileName = gr.Textbox(label="Filename")
|
70 |
+
fileContent = gr.TextArea(label="File Content")
|
71 |
+
completedMessage = gr.Textbox(label="Completed")
|
72 |
+
|
73 |
radio = gr.Radio(
|
74 |
["Expository", "Narrative", "Opinion"], label="What kind of essay would you like to write?"
|
75 |
)
|
|
|
79 |
textout = gr.Textbox(lines=2, interactive=True)
|
80 |
textout.update(lines=8, visible=True)
|
81 |
|
82 |
+
radio.change(fn=change_textbox, inputs=[radio, textin], outputs=[textout, fileContent])
|
83 |
+
|
84 |
+
listFiles = gr.Button("List CSV and TXT File(s)")
|
85 |
+
readFile = gr.Button("Read File")
|
86 |
+
saveFile = gr.Button("Save File")
|
87 |
+
deleteFile = gr.Button("Delete File")
|
88 |
+
appendFile = gr.Button("Append File")
|
89 |
+
|
90 |
+
|
91 |
+
listFiles.click(list_files, inputs=fileName, outputs=fileContent)
|
92 |
+
readFile.click(read_file, inputs=fileName, outputs=fileContent)
|
93 |
+
saveFile.click(write_file, inputs=[fileName, fileContent], outputs=completedMessage)
|
94 |
+
deleteFile.click(delete_file, inputs=fileName, outputs=completedMessage)
|
95 |
+
appendFile.click(append_file, inputs=[fileName, fileContent], outputs=completedMessage )
|
96 |
+
|
97 |
+
block.launch()
|