|
import gradio as gr |
|
import os |
|
|
|
def process_file(file_obj): |
|
if file_obj is None: |
|
return "No file uploaded." |
|
|
|
|
|
save_path = os.path.join(os.getcwd(), file_obj.name) |
|
with open(save_path, "wb") as f: |
|
f.write(file_obj.read()) |
|
|
|
|
|
return save_path |
|
|
|
def process_text(text): |
|
|
|
return text |
|
|
|
with gr.Blocks() as demo: |
|
|
|
with gr.Group(): |
|
with gr.Row(): |
|
text_input = gr.Textbox(label="Enter Text Here") |
|
submit_text_button = gr.Button("Submit Text") |
|
text_output = gr.Text(label="Processed Text") |
|
submit_text_button.click(process_text, inputs=text_input, outputs=text_output) |
|
|
|
|
|
with gr.Group(): |
|
with gr.Row(): |
|
file_input = gr.File(label="Drag & Drop File Here") |
|
submit_file_button = gr.Button("Submit File") |
|
file_output = gr.Text(label="File Path") |
|
submit_file_button.click(process_file, inputs=file_input, outputs=file_output) |
|
|
|
demo.launch() |
|
|