Upload 4 files
Browse files- Dockerfile +14 -0
- app.py +64 -0
- firebase-key.json +13 -0
- requirements.txt +7 -0
Dockerfile
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM python:3.9-slim
|
| 2 |
+
|
| 3 |
+
# Instala Tesseract OCR y dependencias del sistema
|
| 4 |
+
RUN apt-get update && apt-get install -y \
|
| 5 |
+
tesseract-ocr \
|
| 6 |
+
libtesseract-dev \
|
| 7 |
+
&& rm -rf /var/lib/apt/lists/*
|
| 8 |
+
|
| 9 |
+
WORKDIR /app
|
| 10 |
+
COPY requirements.txt .
|
| 11 |
+
COPY firebase-key.json .
|
| 12 |
+
RUN pip install --no-cache-dir -r requirements.txt
|
| 13 |
+
COPY . .
|
| 14 |
+
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "8000"]
|
app.py
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import FastAPI, UploadFile, File # Importa File
|
| 2 |
+
from PIL import Image
|
| 3 |
+
import pytesseract
|
| 4 |
+
from serpapi import GoogleSearch
|
| 5 |
+
|
| 6 |
+
app = FastAPI()
|
| 7 |
+
|
| 8 |
+
# Endpoint raíz
|
| 9 |
+
@app.get("/")
|
| 10 |
+
def raiz():
|
| 11 |
+
return {"Mensaje": "¡V3G4 funciona! Creada por 4n0n1m0-117"}
|
| 12 |
+
|
| 13 |
+
# Búsqueda web
|
| 14 |
+
@app.post("/buscar")
|
| 15 |
+
async def buscar(query: str):
|
| 16 |
+
params = {
|
| 17 |
+
"q": query,
|
| 18 |
+
"api_key": "ea1f3826de0370e1421bbb257b5a03e30aaa6ae084f656742935a13a3a8a65a2", # ¡Reemplaza con tu clave de SerpAPI!
|
| 19 |
+
"engine": "google"
|
| 20 |
+
}
|
| 21 |
+
search = GoogleSearch(params)
|
| 22 |
+
results = search.get_dict()
|
| 23 |
+
return {"respuesta": results["organic_results"][0]["snippet"]}
|
| 24 |
+
|
| 25 |
+
# Análisis de imágenes
|
| 26 |
+
@app.post("/analizar-imagen")
|
| 27 |
+
async def analizar_imagen(imagen: UploadFile = File(...)): # File está definido
|
| 28 |
+
img = Image.open(imagen.file)
|
| 29 |
+
texto = pytesseract.image_to_string(img)
|
| 30 |
+
return {"texto": texto}
|
| 31 |
+
|
| 32 |
+
from fastapi import FastAPI, UploadFile, File # <-- ¡Añade File aquí!
|
| 33 |
+
from PIL import Image
|
| 34 |
+
import pytesseract
|
| 35 |
+
|
| 36 |
+
app = FastAPI()
|
| 37 |
+
|
| 38 |
+
# Endpoint de prueba
|
| 39 |
+
@app.get("/")
|
| 40 |
+
def raiz():
|
| 41 |
+
return {"Mensaje": "¡V3G4 funciona! Creada por 4n0n1m0-117"}
|
| 42 |
+
|
| 43 |
+
# Endpoint para análisis de imágenes
|
| 44 |
+
@app.post("/analizar-imagen")
|
| 45 |
+
async def analizar_imagen(imagen: UploadFile = File(...)): # <-- File ahora está definido
|
| 46 |
+
img = Image.open(imagen.file)
|
| 47 |
+
texto = pytesseract.image_to_string(img)
|
| 48 |
+
return {"texto": texto}
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
import firebase_admin
|
| 52 |
+
from firebase_admin import auth, credentials
|
| 53 |
+
|
| 54 |
+
cred = credentials.Certificate("/app/firebase-key.json") # Descarga el JSON desde Firebase
|
| 55 |
+
firebase_admin.initialize_app(cred)
|
| 56 |
+
|
| 57 |
+
@app.post("/login")
|
| 58 |
+
async def login(token: str):
|
| 59 |
+
try:
|
| 60 |
+
usuario = auth.verify_id_token(token)
|
| 61 |
+
return {"uid": usuario["uid"]}
|
| 62 |
+
except:
|
| 63 |
+
return {"error": "Autenticación fallida"}
|
| 64 |
+
|
firebase-key.json
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"type": "service_account",
|
| 3 |
+
"project_id": "v3g4-27ac0",
|
| 4 |
+
"private_key_id": "3de70865c59d8a842d9d4704e1c3ada78ff8c523",
|
| 5 |
+
"private_key": "-----BEGIN PRIVATE KEY-----\nMIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQCx2+8oqA8g6oU8\n4WTi5JQD41+f6MhpmYWo0H7XEWPvpB6fBdS+N82VI1duORBxGwpjW/WTVVeXtdr5\nk5d9dhSY5hSznu+0zZTDREJq/NEKt3S56HekjBLsDmz1fjYcjWmlh+5c4d2QPMFS\nmovuhCBBVi1rg3FayYzB1coLR2efWuIeakPTnBmbc3JNS0Tsn7GB4HT7qtxayKeJ\njlTUkF0QBDd63Zakd+Hc+BcOJvIuUQc87PCN3FWPcenBFHB/87rq8Z9/DvAUCtvi\nQfhd+8DzQrfwUnu2671y5IRRo9UYaSnLljYlrYTJaqvz71AdnbsiKWUEb2469b16\nMODG1HeTAgMBAAECggEAFwIamCnVey6bedq2kFt9gltBnZAhjPedQM9n+S54vSGA\nDJZWhRz27VobD1k2dUtINr5IsHyTzj5qS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KxzxK/OMFGO8S50u7PZi7nYbr+y98\nP03l+yY7M0ZiR6+eXjfA1EQ6nI9v/ZaHTpw3cF8u9QtfaA9c4D1oZV+6pV+D7BGu\ntHaqQuKDK4pKEL4574HbS9xY\n-----END PRIVATE KEY-----\n",
|
| 6 |
+
"client_email": "firebase-adminsdk-fbsvc@v3g4-27ac0.iam.gserviceaccount.com",
|
| 7 |
+
"client_id": "109984358561416331831",
|
| 8 |
+
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
|
| 9 |
+
"token_uri": "https://oauth2.googleapis.com/token",
|
| 10 |
+
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
|
| 11 |
+
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/firebase-adminsdk-fbsvc%40v3g4-27ac0.iam.gserviceaccount.com",
|
| 12 |
+
"universe_domain": "googleapis.com"
|
| 13 |
+
}
|
requirements.txt
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
fastapi==0.103.1
|
| 2 |
+
uvicorn==0.23.2
|
| 3 |
+
python-multipart==0.0.6
|
| 4 |
+
pytesseract==0.3.10
|
| 5 |
+
pillow==10.0.1
|
| 6 |
+
google-search-results==2.4.2
|
| 7 |
+
firebase-admin==6.2.0
|