mimbres commited on
Commit
8e9bd69
1 Parent(s): 8d6c019

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -11
app.py CHANGED
@@ -1,19 +1,32 @@
1
  import gradio as gr
2
  import os
3
 
 
 
 
 
 
 
 
 
 
4
  def process_text(text):
5
  return text
6
 
7
- def process_file(file_info):
8
- if file_info is None:
9
- return "No file uploaded."
10
- filepath, filename = file_info
11
- save_path = os.path.join(os.getcwd(), filename)
12
- os.rename(filepath, save_path)
13
- return save_path
 
 
 
 
 
14
 
15
- text_interface = gr.Interface(fn=process_text, inputs=gr.Textbox(placeholder="Enter sentence here..."), outputs="text")
16
- file_interface = gr.Interface(fn=process_file, inputs=gr.File(label="Drag & Drop File Here"), outputs="text")
17
 
18
- demo = gr.Parallel(text_interface, file_interface)
19
- demo.launch()
 
1
  import gradio as gr
2
  import os
3
 
4
+ def process_file(file_obj):
5
+ if file_obj is None:
6
+ return "No file uploaded."
7
+
8
+ save_path = os.path.join(os.getcwd(), file_obj.name)
9
+ with open(save_path, "wb") as f:
10
+ f.write(file_obj.read())
11
+ return save_path
12
+
13
  def process_text(text):
14
  return text
15
 
16
+ with gr.Blocks() as demo:
17
+ with gr.Row():
18
+ file_input = gr.File(label="Drag & Drop File Here")
19
+ submit_file_button = gr.Button("Submit File")
20
+
21
+ file_output = gr.Text(label="File Path")
22
+
23
+ with gr.Row():
24
+ text_input = gr.Textbox(label="Enter Text Here")
25
+ submit_text_button = gr.Button("Submit Text")
26
+
27
+ text_output = gr.Text(label="Processed Text")
28
 
29
+ submit_file_button.click(process_file, inputs=file_input, outputs=file_output)
30
+ submit_text_button.click(process_text, inputs=text_input, outputs=text_output)
31
 
32
+ demo.launch()