Guest User

Random image generator on local host

a guest
Jan 11th, 2025
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.56 KB | Source Code | 0 0
  1. import os
  2. import random
  3. from flask import Flask, send_file # Make sure you have Flask enabled
  4.  
  5. app = Flask(__name__)
  6.  
  7. @app.route('/')
  8. def random_image():
  9.     folder_path = 'C:\\Folder\\ImageFolder'  # Update this with your folder path, change it for Linux to Linux folder structure - e.g., /home/your_username/Images
  10.     images = os.listdir(folder_path)
  11.     random_image = random.choice(images)
  12.     return send_file(os.path.join(folder_path, random_image))
  13.  
  14. if __name__ == '__main__':
  15.     app.run(host='0.0.0.0', port=5000) # Change port to whatever you want
  16.  
  17.  
Advertisement
Add Comment
Please, Sign In to add comment