Update app.py
Browse files
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 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
|
|
|
|
|
|
|
|
|
|
14 |
|
15 |
-
|
16 |
-
|
17 |
|
18 |
-
demo
|
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()
|
|