fix: prediction script

main
MrWaradana 12 months ago
parent 48c495ec12
commit 76d1f50a19

@ -1,10 +1,11 @@
# from uvicorn import Config, Server
import uvicorn
from src.config import PORT, HOST
if __name__ == "__main__":
uvicorn.run(
"src.main:app",
host=HOST,
port=PORT,
reload=True
)
"src.main:app",
host=HOST,
port=PORT,
# reload=True
)

Binary file not shown.

@ -94,37 +94,26 @@ async def create(
# Get the directory of the current file
# directory_path = "../modules/plant"
directory_path = os.path.abspath(os.path.join(os.path.dirname(__file__), '../modules/plant'))
directory_path = os.path.abspath(
os.path.join(os.path.dirname(__file__), "../modules/plant")
)
# Construct path to the script
script_path = os.path.join(directory_path, "run.py")
if not os.path.exists(script_path):
logger.error(f"Script not found at path: {script_path}")
raise FileNotFoundError(f"Script not found at path: {script_path}")
# Execute script
try:
process = await asyncio.create_subprocess_exec(
"python",
script_path,
stdout=PIPE,
stderr=PIPE,
cwd=directory_path
"python", script_path, stdout=PIPE, stderr=PIPE, cwd=directory_path
)
stdout, stderr = await process.communicate()
# Check if the script executed successfully
if process.returncode != 0:
error_message = stderr.decode()
logger.error(f"Script execution failed: {error_message}")
# Depending on your requirements, you might want to raise an exception here
print(f"Script execution error: {stderr.decode()}")
else:
logger.info(f"Script executed successfully: {stdout.decode()}")
except asyncio.SubprocessError as e:
logger.error(f"Failed to execute script: {e}")
raise Exception(f"Failed to execute script: {e}")
# Handle subprocess error appropriately
print(f"Script output: {stdout.decode()}")
except Exception as e:
print(f"Error executing script: {e}")
return transaction_data

Loading…
Cancel
Save