Skip to content

Conversation

@Jason0411202
Copy link
Collaborator

Description

API 範例: http://140.123.97.203:3000/processimg/?param1=input_folder&param2=output_folder

param1 代表輸入圖片的目錄
param2 代表輸出圖片的目錄

啟動這個 摸server 前需要進入以下 conda 環境: /mnt/Nami/users/Jason0411202/anaconda3/envs/real-esrgan

成功的話應該會長這樣
image

Changes

describe changes you made for each file

Comment on lines +12 to +14
# api 範例: http://localhost:8000/processimg/?param1=./input_folder&param2=./output_folder
@app.get("/processimg/")
def process_image(param1: str, param2: str): # 接受兩個參數,分別代表輸入圖片路徑跟輸出圖片路徑
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry to review this now.
suggestion: Can we make it more scalable so we can process an image at a time and to prevent security issues with query params maybe we can use POST instead, thanks

Suggested change
# api 範例: http://localhost:8000/processimg/?param1=./input_folder&param2=./output_folder
@app.get("/processimg/")
def process_image(param1: str, param2: str): # 接受兩個參數,分別代表輸入圖片路徑跟輸出圖片路徑
# api 範例: http://localhost:8000/processimg
@app.post("/processimg/")
def process_image(req):
input_image_path = body['input_img_path']
output_image_path = body['output_img_path']

again, sorry for the late review and not saying the requirements when you're implementing🙇‍♂️🙏

Comment on lines +1 to +19
#!/bin/bash

# 進入本專案所需環境
conda activate /mnt/Nami/users/Jason0411202/anaconda3/envs/real3dportrait

# 執行 cutting_video.py 腳本
python cutting_video.py

# 切換到 Real-ESRGAN 目錄
cd Real-ESRGAN

# 執行 inference_realesrgan.py 腳本
python inference_realesrgan.py -n RealESRGAN_x4plus -i inputs --face_enhance

# 返回上一層目錄
cd ..

# 執行 scaling_video.py 腳本
python scaling_video.py
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't we have an api for this?

return {"message": "Script executed successfully", "output": result.stdout.strip()}

except subprocess.CalledProcessError as e:
return {"message": "Script execution failed", "error": str(e), "stderr": e.stderr}

Check warning

Code scanning / CodeQL

Information exposure through an exception Medium

Stack trace information
flows to this location and may be exposed to an external user.

Copilot Autofix

AI about 1 year ago

To fix the problem, we should modify the code to log the detailed error information on the server and return a generic error message to the user. This approach ensures that sensitive information is not exposed to end users while still providing developers with the necessary information to debug issues.

  1. Import the logging module to enable logging of error details.
  2. Configure the logging settings to log error messages to a file or other logging infrastructure.
  3. Modify the exception handling block to log the detailed error information and return a generic error message to the user.
Suggested changeset 1
packages/videoCutting/FastAPI.py

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/packages/videoCutting/FastAPI.py b/packages/videoCutting/FastAPI.py
--- a/packages/videoCutting/FastAPI.py
+++ b/packages/videoCutting/FastAPI.py
@@ -1,7 +1,9 @@
-import subprocess
-import uvicorn
-from fastapi import FastAPI
-from dotenv import load_dotenv, set_key
-
-app = FastAPI()
+import subprocess
+import uvicorn
+from fastapi import FastAPI
+from dotenv import load_dotenv, set_key
+import logging
+
+logging.basicConfig(filename='app.log', level=logging.ERROR)
+app = FastAPI()
 
@@ -29,4 +31,5 @@
     
-    except subprocess.CalledProcessError as e:
-        return {"message": "Script execution failed", "error": str(e), "stderr": e.stderr}
+    except subprocess.CalledProcessError as e:
+        logging.error(f"Script execution failed: {e}, stderr: {e.stderr}")
+        return {"message": "An internal error has occurred. Please try again later."}
 
EOF
@@ -1,7 +1,9 @@
import subprocess
import uvicorn
from fastapi import FastAPI
from dotenv import load_dotenv, set_key

app = FastAPI()
import subprocess
import uvicorn
from fastapi import FastAPI
from dotenv import load_dotenv, set_key
import logging

logging.basicConfig(filename='app.log', level=logging.ERROR)
app = FastAPI()

@@ -29,4 +31,5 @@

except subprocess.CalledProcessError as e:
return {"message": "Script execution failed", "error": str(e), "stderr": e.stderr}
except subprocess.CalledProcessError as e:
logging.error(f"Script execution failed: {e}, stderr: {e.stderr}")
return {"message": "An internal error has occurred. Please try again later."}

Copilot is powered by AI and may make mistakes. Always verify output.
Copy link
Owner

@andrewhsugithub andrewhsugithub left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in input and output folder we can add a .gitignore for privacy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants