Ashrafb commited on
Commit
97fd3ba
·
verified ·
1 Parent(s): ddd39c7

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +9 -2
main.py CHANGED
@@ -112,15 +112,22 @@ def inference(img, version, scale):
112
 
113
 
114
 
 
 
115
  @app.post("/upload/")
116
  async def upload_image(file: UploadFile = File(...), version: str = Form(...), scale: int = Form(...)):
117
  try:
 
 
 
 
 
118
  # Save the uploaded file
119
- with open(f"uploaded_image{os.path.splitext(file.filename)[1]}", "wb") as buffer:
120
  shutil.copyfileobj(file.file, buffer)
121
 
122
  # Perform image enhancement
123
- enhanced_image, save_path = inference(f"uploaded_image{os.path.splitext(file.filename)[1]}", version, scale)
124
 
125
  # Return the enhanced image
126
  if enhanced_image is not None:
 
112
 
113
 
114
 
115
+ import time
116
+
117
  @app.post("/upload/")
118
  async def upload_image(file: UploadFile = File(...), version: str = Form(...), scale: int = Form(...)):
119
  try:
120
+ # Create a unique filename with timestamp
121
+ timestamp = str(int(time.time()))
122
+ file_extension = os.path.splitext(file.filename)[1]
123
+ filename = f"uploaded_image_{timestamp}{file_extension}"
124
+
125
  # Save the uploaded file
126
+ with open(filename, "wb") as buffer:
127
  shutil.copyfileobj(file.file, buffer)
128
 
129
  # Perform image enhancement
130
+ enhanced_image, save_path = inference(filename, version, scale)
131
 
132
  # Return the enhanced image
133
  if enhanced_image is not None: