import gradio as gr from PIL import Image import os import io def get_file_info(file): """Get file info from the uploaded file.""" if file is None: return "No file uploaded." # Extract original filename original_name = os.path.splitext(os.path.basename(file.name))[0] # Open the image file image = Image.open(file.name) # Get image dimensions width, height = image.size # Calculate file size size_bytes = os.path.getsize(file.name) size_kb = size_bytes / 1024 return f"""

Original Name: {original_name}

Size: {width}x{height}px ({size_kb:.1f} KB)

""" with gr.Blocks(title="Gradio File Info Test") as interface: gr.Markdown("# 🖼️ Gradio File Info Test 🛠️") gr.Markdown("📤 Upload an image to test file info handling.") with gr.Row(): with gr.Column(scale=1): # Input column input_file = gr.File(label="Upload Image") input_info = gr.HTML(label="Input Image Information") # For showing input image info # Update image info when file changes input_file.change( fn=get_file_info, inputs=[input_file], outputs=[input_info] ) if __name__ == "__main__": interface.launch()