Daniele
commited on
Commit
Β·
9594324
1
Parent(s):
baf362a
port change
Browse files- API_EXAMPLES.md +24 -24
- Dockerfile +3 -3
- app.py +1 -1
- start_server.py +4 -4
- test_api.py +1 -1
API_EXAMPLES.md
CHANGED
|
@@ -3,26 +3,26 @@
|
|
| 3 |
## Health Check
|
| 4 |
|
| 5 |
```bash
|
| 6 |
-
curl -X GET "http://localhost:
|
| 7 |
```
|
| 8 |
|
| 9 |
## Ottenere le lingue supportate
|
| 10 |
|
| 11 |
```bash
|
| 12 |
-
curl -X GET "http://localhost:
|
| 13 |
```
|
| 14 |
|
| 15 |
## Traduzione singola (GET con parametri)
|
| 16 |
|
| 17 |
```bash
|
| 18 |
# Traduzione semplice
|
| 19 |
-
curl -X POST "http://localhost:
|
| 20 |
|
| 21 |
# Traduzione con HTML
|
| 22 |
-
curl -X POST "http://localhost:
|
| 23 |
|
| 24 |
# Traduzione con placeholder
|
| 25 |
-
curl -X POST "http://localhost:
|
| 26 |
```
|
| 27 |
|
| 28 |
## Traduzione di oggetti locale complessi
|
|
@@ -30,7 +30,7 @@ curl -X POST "http://localhost:8000/translate-single?text=Ciao%20%7Bname%7D%2C%2
|
|
| 30 |
### Esempio base
|
| 31 |
|
| 32 |
```bash
|
| 33 |
-
curl -X POST "http://localhost:
|
| 34 |
-H "Content-Type: application/json" \
|
| 35 |
-d '{
|
| 36 |
"locales": {
|
|
@@ -44,7 +44,7 @@ curl -X POST "http://localhost:8000/translate?target_language=en" \
|
|
| 44 |
### Esempio con HTML e placeholder
|
| 45 |
|
| 46 |
```bash
|
| 47 |
-
curl -X POST "http://localhost:
|
| 48 |
-H "Content-Type: application/json" \
|
| 49 |
-d '{
|
| 50 |
"locales": {
|
|
@@ -60,7 +60,7 @@ curl -X POST "http://localhost:8000/translate?target_language=fr" \
|
|
| 60 |
### Esempio per applicazione web complessa
|
| 61 |
|
| 62 |
```bash
|
| 63 |
-
curl -X POST "http://localhost:
|
| 64 |
-H "Content-Type: application/json" \
|
| 65 |
-d '{
|
| 66 |
"locales": {
|
|
@@ -90,37 +90,37 @@ curl -X POST "http://localhost:8000/translate?target_language=de" \
|
|
| 90 |
|
| 91 |
```bash
|
| 92 |
# Inglese
|
| 93 |
-
curl -X POST "http://localhost:
|
| 94 |
-H "Content-Type: application/json" \
|
| 95 |
-d '{"locales": {"greeting": "Buongiorno!", "goodbye": "Arrivederci!"}}'
|
| 96 |
|
| 97 |
# Francese
|
| 98 |
-
curl -X POST "http://localhost:
|
| 99 |
-H "Content-Type: application/json" \
|
| 100 |
-d '{"locales": {"greeting": "Buongiorno!", "goodbye": "Arrivederci!"}}'
|
| 101 |
|
| 102 |
# Tedesco
|
| 103 |
-
curl -X POST "http://localhost:
|
| 104 |
-H "Content-Type: application/json" \
|
| 105 |
-d '{"locales": {"greeting": "Buongiorno!", "goodbye": "Arrivederci!"}}'
|
| 106 |
|
| 107 |
# Spagnolo
|
| 108 |
-
curl -X POST "http://localhost:
|
| 109 |
-H "Content-Type: application/json" \
|
| 110 |
-d '{"locales": {"greeting": "Buongiorno!", "goodbye": "Arrivederci!"}}'
|
| 111 |
|
| 112 |
# Russo
|
| 113 |
-
curl -X POST "http://localhost:
|
| 114 |
-H "Content-Type: application/json" \
|
| 115 |
-d '{"locales": {"greeting": "Buongiorno!", "goodbye": "Arrivederci!"}}'
|
| 116 |
|
| 117 |
# Giapponese
|
| 118 |
-
curl -X POST "http://localhost:
|
| 119 |
-H "Content-Type: application/json" \
|
| 120 |
-d '{"locales": {"greeting": "Buongiorno!", "goodbye": "Arrivederci!"}}'
|
| 121 |
|
| 122 |
# Cinese
|
| 123 |
-
curl -X POST "http://localhost:
|
| 124 |
-H "Content-Type: application/json" \
|
| 125 |
-d '{"locales": {"greeting": "Buongiorno!", "goodbye": "Arrivederci!"}}'
|
| 126 |
```
|
|
@@ -130,7 +130,7 @@ curl -X POST "http://localhost:8000/translate?target_language=zh" \
|
|
| 130 |
### Lingua non supportata
|
| 131 |
|
| 132 |
```bash
|
| 133 |
-
curl -X POST "http://localhost:
|
| 134 |
-H "Content-Type: application/json" \
|
| 135 |
-d '{"locales": {"test": "Ciao"}}'
|
| 136 |
```
|
|
@@ -138,7 +138,7 @@ curl -X POST "http://localhost:8000/translate?target_language=xyz" \
|
|
| 138 |
### Body malformato
|
| 139 |
|
| 140 |
```bash
|
| 141 |
-
curl -X POST "http://localhost:
|
| 142 |
-H "Content-Type: application/json" \
|
| 143 |
-d '{"wrong_field": "test"}'
|
| 144 |
```
|
|
@@ -146,7 +146,7 @@ curl -X POST "http://localhost:8000/translate?target_language=en" \
|
|
| 146 |
### Parametro mancante
|
| 147 |
|
| 148 |
```bash
|
| 149 |
-
curl -X POST "http://localhost:
|
| 150 |
-H "Content-Type: application/json" \
|
| 151 |
-d '{"locales": {"test": "Ciao"}}'
|
| 152 |
```
|
|
@@ -157,7 +157,7 @@ curl -X POST "http://localhost:8000/translate" \
|
|
| 157 |
// Traduzione di oggetti locale
|
| 158 |
const translateLocales = async () => {
|
| 159 |
const response = await fetch(
|
| 160 |
-
"http://localhost:
|
| 161 |
{
|
| 162 |
method: "POST",
|
| 163 |
headers: {
|
|
@@ -179,7 +179,7 @@ const translateLocales = async () => {
|
|
| 179 |
|
| 180 |
// Ottenere lingue supportate
|
| 181 |
const getSupportedLanguages = async () => {
|
| 182 |
-
const response = await fetch("http://localhost:
|
| 183 |
const data = await response.json();
|
| 184 |
console.log("Lingue supportate:", data.supported_languages);
|
| 185 |
};
|
|
@@ -187,7 +187,7 @@ const getSupportedLanguages = async () => {
|
|
| 187 |
// Traduzione singola
|
| 188 |
const translateSingle = async () => {
|
| 189 |
const response = await fetch(
|
| 190 |
-
"http://localhost:
|
| 191 |
{
|
| 192 |
method: "POST",
|
| 193 |
}
|
|
@@ -204,7 +204,7 @@ import requests
|
|
| 204 |
|
| 205 |
# Traduzione di oggetti locale
|
| 206 |
def translate_locales():
|
| 207 |
-
url = "http://localhost:
|
| 208 |
params = {"target_language": "en"}
|
| 209 |
data = {
|
| 210 |
"locales": {
|
|
@@ -219,12 +219,12 @@ def translate_locales():
|
|
| 219 |
|
| 220 |
# Ottenere lingue supportate
|
| 221 |
def get_supported_languages():
|
| 222 |
-
response = requests.get("http://localhost:
|
| 223 |
print(response.json())
|
| 224 |
|
| 225 |
# Traduzione singola
|
| 226 |
def translate_single():
|
| 227 |
-
url = "http://localhost:
|
| 228 |
params = {
|
| 229 |
"text": "Ciao mondo",
|
| 230 |
"target_language": "en"
|
|
|
|
| 3 |
## Health Check
|
| 4 |
|
| 5 |
```bash
|
| 6 |
+
curl -X GET "http://localhost:7860/"
|
| 7 |
```
|
| 8 |
|
| 9 |
## Ottenere le lingue supportate
|
| 10 |
|
| 11 |
```bash
|
| 12 |
+
curl -X GET "http://localhost:7860/languages"
|
| 13 |
```
|
| 14 |
|
| 15 |
## Traduzione singola (GET con parametri)
|
| 16 |
|
| 17 |
```bash
|
| 18 |
# Traduzione semplice
|
| 19 |
+
curl -X POST "http://localhost:7860/translate-single?text=Ciao%20mondo&target_language=en"
|
| 20 |
|
| 21 |
# Traduzione con HTML
|
| 22 |
+
curl -X POST "http://localhost:7860/translate-single?text=%3Cp%3ECiao%20%3Cstrong%3Emondo%3C/strong%3E%3C/p%3E&target_language=fr"
|
| 23 |
|
| 24 |
# Traduzione con placeholder
|
| 25 |
+
curl -X POST "http://localhost:7860/translate-single?text=Ciao%20%7Bname%7D%2C%20come%20stai%3F&target_language=de"
|
| 26 |
```
|
| 27 |
|
| 28 |
## Traduzione di oggetti locale complessi
|
|
|
|
| 30 |
### Esempio base
|
| 31 |
|
| 32 |
```bash
|
| 33 |
+
curl -X POST "http://localhost:7860/translate?target_language=en" \
|
| 34 |
-H "Content-Type: application/json" \
|
| 35 |
-d '{
|
| 36 |
"locales": {
|
|
|
|
| 44 |
### Esempio con HTML e placeholder
|
| 45 |
|
| 46 |
```bash
|
| 47 |
+
curl -X POST "http://localhost:7860/translate?target_language=fr" \
|
| 48 |
-H "Content-Type: application/json" \
|
| 49 |
-d '{
|
| 50 |
"locales": {
|
|
|
|
| 60 |
### Esempio per applicazione web complessa
|
| 61 |
|
| 62 |
```bash
|
| 63 |
+
curl -X POST "http://localhost:7860/translate?target_language=de" \
|
| 64 |
-H "Content-Type: application/json" \
|
| 65 |
-d '{
|
| 66 |
"locales": {
|
|
|
|
| 90 |
|
| 91 |
```bash
|
| 92 |
# Inglese
|
| 93 |
+
curl -X POST "http://localhost:7860/translate?target_language=en" \
|
| 94 |
-H "Content-Type: application/json" \
|
| 95 |
-d '{"locales": {"greeting": "Buongiorno!", "goodbye": "Arrivederci!"}}'
|
| 96 |
|
| 97 |
# Francese
|
| 98 |
+
curl -X POST "http://localhost:7860/translate?target_language=fr" \
|
| 99 |
-H "Content-Type: application/json" \
|
| 100 |
-d '{"locales": {"greeting": "Buongiorno!", "goodbye": "Arrivederci!"}}'
|
| 101 |
|
| 102 |
# Tedesco
|
| 103 |
+
curl -X POST "http://localhost:7860/translate?target_language=de" \
|
| 104 |
-H "Content-Type: application/json" \
|
| 105 |
-d '{"locales": {"greeting": "Buongiorno!", "goodbye": "Arrivederci!"}}'
|
| 106 |
|
| 107 |
# Spagnolo
|
| 108 |
+
curl -X POST "http://localhost:7860/translate?target_language=es" \
|
| 109 |
-H "Content-Type: application/json" \
|
| 110 |
-d '{"locales": {"greeting": "Buongiorno!", "goodbye": "Arrivederci!"}}'
|
| 111 |
|
| 112 |
# Russo
|
| 113 |
+
curl -X POST "http://localhost:7860/translate?target_language=ru" \
|
| 114 |
-H "Content-Type: application/json" \
|
| 115 |
-d '{"locales": {"greeting": "Buongiorno!", "goodbye": "Arrivederci!"}}'
|
| 116 |
|
| 117 |
# Giapponese
|
| 118 |
+
curl -X POST "http://localhost:7860/translate?target_language=ja" \
|
| 119 |
-H "Content-Type: application/json" \
|
| 120 |
-d '{"locales": {"greeting": "Buongiorno!", "goodbye": "Arrivederci!"}}'
|
| 121 |
|
| 122 |
# Cinese
|
| 123 |
+
curl -X POST "http://localhost:7860/translate?target_language=zh" \
|
| 124 |
-H "Content-Type: application/json" \
|
| 125 |
-d '{"locales": {"greeting": "Buongiorno!", "goodbye": "Arrivederci!"}}'
|
| 126 |
```
|
|
|
|
| 130 |
### Lingua non supportata
|
| 131 |
|
| 132 |
```bash
|
| 133 |
+
curl -X POST "http://localhost:7860/translate?target_language=xyz" \
|
| 134 |
-H "Content-Type: application/json" \
|
| 135 |
-d '{"locales": {"test": "Ciao"}}'
|
| 136 |
```
|
|
|
|
| 138 |
### Body malformato
|
| 139 |
|
| 140 |
```bash
|
| 141 |
+
curl -X POST "http://localhost:7860/translate?target_language=en" \
|
| 142 |
-H "Content-Type: application/json" \
|
| 143 |
-d '{"wrong_field": "test"}'
|
| 144 |
```
|
|
|
|
| 146 |
### Parametro mancante
|
| 147 |
|
| 148 |
```bash
|
| 149 |
+
curl -X POST "http://localhost:7860/translate" \
|
| 150 |
-H "Content-Type: application/json" \
|
| 151 |
-d '{"locales": {"test": "Ciao"}}'
|
| 152 |
```
|
|
|
|
| 157 |
// Traduzione di oggetti locale
|
| 158 |
const translateLocales = async () => {
|
| 159 |
const response = await fetch(
|
| 160 |
+
"http://localhost:7860/translate?target_language=en",
|
| 161 |
{
|
| 162 |
method: "POST",
|
| 163 |
headers: {
|
|
|
|
| 179 |
|
| 180 |
// Ottenere lingue supportate
|
| 181 |
const getSupportedLanguages = async () => {
|
| 182 |
+
const response = await fetch("http://localhost:7860/languages");
|
| 183 |
const data = await response.json();
|
| 184 |
console.log("Lingue supportate:", data.supported_languages);
|
| 185 |
};
|
|
|
|
| 187 |
// Traduzione singola
|
| 188 |
const translateSingle = async () => {
|
| 189 |
const response = await fetch(
|
| 190 |
+
"http://localhost:7860/translate-single?text=Ciao mondo&target_language=en",
|
| 191 |
{
|
| 192 |
method: "POST",
|
| 193 |
}
|
|
|
|
| 204 |
|
| 205 |
# Traduzione di oggetti locale
|
| 206 |
def translate_locales():
|
| 207 |
+
url = "http://localhost:7860/translate"
|
| 208 |
params = {"target_language": "en"}
|
| 209 |
data = {
|
| 210 |
"locales": {
|
|
|
|
| 219 |
|
| 220 |
# Ottenere lingue supportate
|
| 221 |
def get_supported_languages():
|
| 222 |
+
response = requests.get("http://localhost:7860/languages")
|
| 223 |
print(response.json())
|
| 224 |
|
| 225 |
# Traduzione singola
|
| 226 |
def translate_single():
|
| 227 |
+
url = "http://localhost:7860/translate-single"
|
| 228 |
params = {
|
| 229 |
"text": "Ciao mondo",
|
| 230 |
"target_language": "en"
|
Dockerfile
CHANGED
|
@@ -20,8 +20,8 @@ RUN pip install --no-cache-dir --upgrade -r requirements.txt
|
|
| 20 |
# Copia il codice dell'applicazione
|
| 21 |
COPY --chown=user . /app
|
| 22 |
|
| 23 |
-
# Espone la porta
|
| 24 |
-
EXPOSE
|
| 25 |
|
| 26 |
# Avvia il server
|
| 27 |
-
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "
|
|
|
|
| 20 |
# Copia il codice dell'applicazione
|
| 21 |
COPY --chown=user . /app
|
| 22 |
|
| 23 |
+
# Espone la porta 7860
|
| 24 |
+
EXPOSE 7860
|
| 25 |
|
| 26 |
# Avvia il server
|
| 27 |
+
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
|
app.py
CHANGED
|
@@ -182,4 +182,4 @@ async def translate_single_text(
|
|
| 182 |
|
| 183 |
if __name__ == "__main__":
|
| 184 |
import uvicorn
|
| 185 |
-
uvicorn.run(app, host="0.0.0.0", port=
|
|
|
|
| 182 |
|
| 183 |
if __name__ == "__main__":
|
| 184 |
import uvicorn
|
| 185 |
+
uvicorn.run(app, host="0.0.0.0", port=7860)
|
start_server.py
CHANGED
|
@@ -8,15 +8,15 @@ from app import app
|
|
| 8 |
|
| 9 |
if __name__ == "__main__":
|
| 10 |
print("π Avvio Local Translation Server...")
|
| 11 |
-
print("π‘ Server disponibile su: http://localhost:
|
| 12 |
-
print("π Documentazione API: http://localhost:
|
| 13 |
-
print("π Interfaccia Redoc: http://localhost:
|
| 14 |
print("\n" + "="*50)
|
| 15 |
|
| 16 |
uvicorn.run(
|
| 17 |
app,
|
| 18 |
host="0.0.0.0",
|
| 19 |
-
port=
|
| 20 |
log_level="info",
|
| 21 |
reload=False # Disabilita il reload automatico in produzione
|
| 22 |
)
|
|
|
|
| 8 |
|
| 9 |
if __name__ == "__main__":
|
| 10 |
print("π Avvio Local Translation Server...")
|
| 11 |
+
print("π‘ Server disponibile su: http://localhost:7860")
|
| 12 |
+
print("π Documentazione API: http://localhost:7860/docs")
|
| 13 |
+
print("π Interfaccia Redoc: http://localhost:7860/redoc")
|
| 14 |
print("\n" + "="*50)
|
| 15 |
|
| 16 |
uvicorn.run(
|
| 17 |
app,
|
| 18 |
host="0.0.0.0",
|
| 19 |
+
port=7860,
|
| 20 |
log_level="info",
|
| 21 |
reload=False # Disabilita il reload automatico in produzione
|
| 22 |
)
|
test_api.py
CHANGED
|
@@ -9,7 +9,7 @@ import json
|
|
| 9 |
import time
|
| 10 |
|
| 11 |
# Configurazione
|
| 12 |
-
BASE_URL = "http://localhost:
|
| 13 |
|
| 14 |
def test_health_check():
|
| 15 |
"""Testa l'endpoint di health check."""
|
|
|
|
| 9 |
import time
|
| 10 |
|
| 11 |
# Configurazione
|
| 12 |
+
BASE_URL = "http://localhost:7860"
|
| 13 |
|
| 14 |
def test_health_check():
|
| 15 |
"""Testa l'endpoint di health check."""
|