Spaces:
Runtime error
Runtime error
File size: 852 Bytes
4f394eb 7d54bec 6804d36 7d54bec 6804d36 7d54bec 4f394eb |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
import os
import gradio as gr
# Define the folder where uploaded files will be saved
upload_folder = "uploaded_files"
# Ensure the folder exists; if not, create it
if not os.path.exists(upload_folder):
os.makedirs(upload_folder)
# Function to handle the file upload
def save_file(file):
# Get the file name
file_name = file.name
# Save the file to the specified folder
file_path = os.path.join(upload_folder, file_name)
with open(file_path, "wb") as f:
f.write(file.read())
return f"File saved to: {file_path}"
# Create the Gradio interface
iface = gr.Interface(
fn=save_file, # The function to handle file saving
inputs=gr.inputs.File(), # Input widget to upload a file
outputs="text" # Output: confirmation message with file path
)
# Launch the app
iface.launch()
|