Spaces:
Runtime error
Runtime error
| from flask import Flask,send_file,send_from_directory,request | |
| from cloudinary.uploader import upload, destroy | |
| import cloudinary | |
| from cloudinary import CloudinaryImage | |
| import json | |
| import requests | |
| cloudinary.config( | |
| cloud_name = "dkgjezoob", | |
| api_key = "227641121219831", | |
| api_secret = "e8FCO1xjr8jNWysDiop8pRBtaG4" | |
| ) | |
| app = Flask(__name__) | |
| # The absolute path of the directory containing images for users to download | |
| app.config["CLIENT_IMAGES"] = r"/home/hawkeye/Desktop/StableDiffusion/images" | |
| def hello(): | |
| return "Hello World" | |
| def get_image(): | |
| image_file=r'./images/one.png' | |
| upload(image_file,public_id='message') | |
| srcURL = CloudinaryImage("message").build_url() | |
| return json.dumps({"url":srcURL}) | |
| def download_image(): | |
| url = "http://res.cloudinary.com/dkgjezoob/image/upload/message" | |
| response = requests.get(url) | |
| if response.status_code == 200: | |
| with open("file.png", "wb") as file: | |
| file.write(response.content) | |
| print("File downloaded successfully!") | |
| else: | |
| print("Failed to download the file.") | |
| if __name__ == '__main__': | |
| app.run(host='0.0.0.0',port = 8000, threaded = True, debug = True) | |