Update app.py
Browse files
app.py
CHANGED
|
@@ -2,24 +2,17 @@ import gradio as gr
|
|
| 2 |
|
| 3 |
FILE = "saved_text.txt"
|
| 4 |
|
| 5 |
-
def
|
| 6 |
-
try:
|
| 7 |
-
with open(FILE, "r") as f:
|
| 8 |
-
return f.read()
|
| 9 |
-
except FileNotFoundError:
|
| 10 |
-
return ""
|
| 11 |
-
|
| 12 |
-
def append_and_show(text):
|
| 13 |
if text.strip():
|
| 14 |
with open(FILE, "a") as f:
|
| 15 |
f.write(text + "\n")
|
| 16 |
-
return
|
| 17 |
|
| 18 |
iface = gr.Interface(
|
| 19 |
-
fn=
|
| 20 |
inputs=gr.Textbox(lines=5, label="Type here"),
|
| 21 |
-
outputs=
|
| 22 |
-
title="Append
|
| 23 |
)
|
| 24 |
|
| 25 |
if __name__ == "__main__":
|
|
|
|
| 2 |
|
| 3 |
FILE = "saved_text.txt"
|
| 4 |
|
| 5 |
+
def append_text(text):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
if text.strip():
|
| 7 |
with open(FILE, "a") as f:
|
| 8 |
f.write(text + "\n")
|
| 9 |
+
return f"Appended: {text}"
|
| 10 |
|
| 11 |
iface = gr.Interface(
|
| 12 |
+
fn=append_text,
|
| 13 |
inputs=gr.Textbox(lines=5, label="Type here"),
|
| 14 |
+
outputs="text",
|
| 15 |
+
title="Append Text to File"
|
| 16 |
)
|
| 17 |
|
| 18 |
if __name__ == "__main__":
|