test / app.py
mimbres's picture
Update app.py
4a3ead8 verified
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()