indiapuig commited on
Commit
afb15c7
·
verified ·
1 Parent(s): 8679bfe

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -12
app.py CHANGED
@@ -2,24 +2,17 @@ import gradio as gr
2
 
3
  FILE = "saved_text.txt"
4
 
5
- def load_text():
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 load_text()
17
 
18
  iface = gr.Interface(
19
- fn=append_and_show,
20
  inputs=gr.Textbox(lines=5, label="Type here"),
21
- outputs=gr.Textbox(lines=15, label="Saved Text"),
22
- title="Append and Save Text",
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__":