Spaces:
Runtime error
Runtime error
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() | |