DOCKER : compatible docker + APY : python micro services - IA services coming...

This commit is contained in:
fred 2024-02-25 19:26:43 +01:00
parent c921b12b87
commit c44839ae38
10 changed files with 265 additions and 14 deletions

View File

@ -102,9 +102,18 @@ if [[ ${QRCODE} == "station" ]]; then
ISTATION=$(cat ~/.zen/tmp/ISTATION)
fi
## FIND STATION GPS CLOSEST ACTIVE KEY
## GET SATELLITE IMAGE
source ~/.zen/GPS
echo "... ~/.zen/GPS ... $LAT $LON ..."
ville=$(my_IPCity)
echo "my_IPCity = $ville"
api_key="ac5e65a2fd10d3788d40cdae0d4516ba" # Remplacez YOUR_API_KEY par votre clé API OpenWeatherMap
url="http://api.openweathermap.org/data/2.5/weather?q=$ville&appid=$api_key&units=metric"
meteo=$(curl -s $url)
# Extraire les informations pertinentes de la réponse JSON
temperature=$(echo $meteo | jq -r '.main.temp')
description=$(echo $meteo | jq -r '.weather[0].description')
echo "La météo à $ville : $description, Température: $temperature °C"
## SHOW ZenStation FRONT
sed "s~_STATION_~${myIPFS}${ISTATION}/~g" $MY_PATH/../templates/ZenStation/index.html > ~/.zen/tmp/${MOATS}/index.htm

46
APY/addfile.sh Executable file
View File

@ -0,0 +1,46 @@
#!/bin/bash
# Usage: bash addfile.sh <filename> <mime_type> <file_type>
filename="$1"
mime_type="$2"
file_type="$3"
echo "Processing file: $filename"
echo "MIME type: $mime_type"
echo "File type: $file_type"
# Check file type and perform corresponding treatment
case $file_type in
"video")
if [[ $mime_type == *"video"* ]]; then
# Video processing logic
echo "Video processing..."
# Add more processing steps as needed
else
echo "Invalid file type for video processing"
fi
;;
"audio")
if [[ $mime_type == *"audio"* ]]; then
# Audio processing logic
echo "Audio processing..."
# Add more processing steps as needed
else
echo "Invalid file type for audio processing"
fi
;;
"text")
if [[ $mime_type == *"text"* ]]; then
# Text processing logic
echo "Text processing..."
# Add more processing steps as needed
else
echo "Invalid file type for text processing"
fi
;;
*)
echo "Unknown file type: $file_type"
;;
esac
echo "File processing complete."

170
APY/upload_video.10101.py Executable file
View File

@ -0,0 +1,170 @@
#!/usr/bin/python3
from fastapi import FastAPI, File, UploadFile, Form, HTTPException
from fastapi.responses import HTMLResponse, JSONResponse
import subprocess
import os
import magic
app = FastAPI()
# HTML form for file upload
html_form = """
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>File Upload and Processing</title>
<style>
body {
font-family: 'Arial', sans-serif;
background-color: #f5f5f5;
margin: 0;
display: flex;
align-items: center;
justify-content: center;
height: 100vh;
}
#upload-container {
background-color: #ffffff;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
padding: 20px;
border-radius: 8px;
text-align: center;
}
h1 {
color: #333333;
}
form {
margin-top: 20px;
display: flex;
flex-direction: column;
align-items: center;
}
input[type="file"] {
margin-bottom: 10px;
}
input[type="button"] {
background-color: #4caf50;
color: white;
border: none;
padding: 10px 20px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
cursor: pointer;
border-radius: 4px;
}
#result-container {
margin-top: 20px;
}
#loading-indicator {
display: none;
margin-top: 20px;
}
</style>
</head>
<body>
<div id="upload-container">
<h1>File Upload and Processing</h1>
<form id="upload-form" enctype="multipart/form-data" method="post">
<input type="file" id="file" accept="video/*,audio/*,text/*" required>
<br>
<label for="convert_to">Choose file type:</label>
<input type="radio" id="video" name="convert_to" value="video" checked>
<label for="video">Video</label>
<input type="radio" id="audio" name="convert_to" value="audio">
<label for="audio">Audio</label>
<input type="radio" id="text" name="convert_to" value="text">
<label for="text">Text</label>
<br>
<input type="button" value="Upload" onclick="uploadFile()">
<div id="loading-indicator">Loading...</div>
</form>
<div id="result-container"></div>
</div>
<script>
async function uploadFile() {
const fileInput = document.getElementById('file');
const file = fileInput.files[0];
const fileType = document.querySelector('input[name="convert_to"]:checked').value;
const formData = new FormData();
formData.append('file', file);
formData.append('convert_to', fileType);
// Show loading indicator
const loadingIndicator = document.getElementById('loading-indicator');
loadingIndicator.style.display = 'block';
try {
const response = await fetch('/upload', {
method: 'POST',
body: formData
});
const result = await response.json();
document.getElementById('result-container').innerHTML = JSON.stringify(result, null, 2);
} catch (error) {
console.error('Error uploading file:', error);
} finally {
// Hide loading indicator after response or error
loadingIndicator.style.display = 'none';
}
}
</script>
</body>
</html>
"""
@app.get("/")
async def read_root():
return HTMLResponse(content=html_form, status_code=200)
def get_mime_type(file: UploadFile):
mime = magic.Magic()
mime_type = mime.from_buffer(file.file.read(1024))
return mime_type
@app.post("/upload")
async def create_upload_file(file: UploadFile = File(...), convert_to: str = Form(...)):
# Validate file size
max_file_size = 100 * 1024 * 1024 # 100MB
if file.file.__sizeof__() > max_file_size:
raise HTTPException(status_code=400, detail="File size exceeds the limit of 100MB")
# Check the file type
mime_type = get_mime_type(file)
print(f"Detected MIME type: {mime_type}")
# Save the uploaded file to a temporary location
with open(file.filename, "wb") as f:
f.write(file.file.read())
# Continue with the processing logic
# Run the post-treatment Bash script
logs = subprocess.run(["bash", "addfile.sh", file.filename, mime_type, convert_to], capture_output=True, text=True).stdout
# Optionally, you can remove the temporary file
os.remove(file.filename)
return JSONResponse(content={"filename": file.filename, "mime_type": mime_type, "convert_to": convert_to, "message": "File processed successfully.", "logs": logs})
if __name__ == "__main__":
import uvicorn
uvicorn.run(app, host="0.0.0.0", port=10101)

View File

@ -57,18 +57,18 @@ mot_passe_vocal(){
# Début du jeu
clear
echo "
_| _|
_| _| _|_| _| _| _|_|_| _|_|_|
_| _| _| _| _| _| _| _| _|
_| _| _| _| _| _| _| _| _|
_| _|_| _|_|_| _| _| _|_|_|
_|
_|_|
_| _| _|
_| _| _|_|_| _|_|_| _| _| _|_| _| _|_|
_|_|_|_| _| _| _| _|_| _|_|_|_| _|_|
_| _| _| _| _| _| _| _| _|
_| _| _|_|_| _|_|_| _| _| _|_|_| _|
_| _|
_| _| _|_| _| _| _|_|_| _|_|_|
_| _| _| _| _| _| _| _| _|
_| _| _| _| _| _| _| _| _|
_| _|_| _|_|_| _| _| _|_|_|
_|
_|_|
_| _| _|
_| _| _|_|_| _|_|_| _| _| _|_| _| _|_|
_|_|_|_| _| _| _| _|_| _|_|_|_| _|_|
_| _| _| _| _| _| _| _| _|
_| _| _|_|_| _|_|_| _| _| _|_|_| _|
"
sleep 1

View File

@ -0,0 +1,26 @@
# Rémi Montagut
# CONSIGNES
* Connaître les commandes de base de PowerShell ou Shell pour un usage quotidien
* Gérer les utilisateurs avec des scripts
* Automatiser ladministration des stations de travail et des serveurs
* Ecrire des scripts sous Windows avec PowerShell
* Savoir programmer et debugger un shellscript
Expériences
--
Alternance en tant qu'ingénieur devops, SHELL, Jenkis, Ansible
OS
--
Mac OS ( ARM ) / Proxmox à disposition pour virtualiser
Votre machine ou celle de votre boite ?
la mienne
Activité de votre alternance ?
ingénieur devops