akki2825 commited on
Commit
522fb71
·
verified ·
1 Parent(s): fd126c9
Files changed (1) hide show
  1. app.py +41 -0
app.py ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+
3
+ def add_line_breaks(file, position):
4
+ try:
5
+ # Read the text from the uploaded file
6
+ text = file.read()
7
+
8
+ # Ensure position is within valid range
9
+ position = max(0, min(position, len(text)))
10
+
11
+ # Insert \n at the specified position
12
+ modified_text = text[:position] + "\n" + text[position:]
13
+
14
+ return modified_text
15
+ except Exception as e:
16
+ return f"Error: {str(e)}"
17
+
18
+ def main():
19
+ with gr.Blocks() as demo:
20
+ gr.Markdown("# Text Line Break Adder")
21
+
22
+ with gr.Row():
23
+ file_input = gr.File(label="Upload Text File", placeholder="Select a .txt file")
24
+ position_input = gr.Number(label="Position to Insert Line Break",
25
+ placeholder="Enter position (0-based index)",
26
+ value=0)
27
+
28
+ with gr.Row():
29
+ add_button = gr.Button("Add Line Break")
30
+ text_output = gr.Textbox(label="Modified Text", lines=10)
31
+
32
+ add_button.click(
33
+ fn=add_line_breaks,
34
+ inputs=[file_input, position_input],
35
+ outputs=text_output
36
+ )
37
+
38
+ demo.launch()
39
+
40
+ if __name__ == "__main__":
41
+ main()