Spaces:
Sleeping
Sleeping
Upload 3 files
Browse files- Dockerfile +16 -0
- main.py +26 -0
- requirements.txt +3 -0
Dockerfile
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Usa una imagen base de Python
|
| 2 |
+
FROM python:3.9
|
| 3 |
+
# Establece el directorio de trabajo
|
| 4 |
+
WORKDIR /code
|
| 5 |
+
|
| 6 |
+
# Copia los archivos necesarios al contenedor
|
| 7 |
+
COPY ./requirements.txt /code/requirements.txt
|
| 8 |
+
RUN pip install --no-cache-dir -r /code/requirements.txt
|
| 9 |
+
|
| 10 |
+
COPY . .
|
| 11 |
+
|
| 12 |
+
RUN chmod -R 777 /code
|
| 13 |
+
|
| 14 |
+
# Comando para ejecutar la aplicaci贸n
|
| 15 |
+
# CMD ["python", "app.py"]
|
| 16 |
+
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
|
main.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import FastAPI, File, UploadFile
|
| 2 |
+
from fastapi.responses import JSONResponse
|
| 3 |
+
import shutil
|
| 4 |
+
import os
|
| 5 |
+
|
| 6 |
+
app = FastAPI()
|
| 7 |
+
|
| 8 |
+
# Carpeta para almacenar las im谩genes
|
| 9 |
+
UPLOAD_FOLDER = "uploaded_images"
|
| 10 |
+
os.makedirs(UPLOAD_FOLDER, exist_ok=True)
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
@app.post("/upload/")
|
| 14 |
+
async def upload_image(file: UploadFile = File(...)):
|
| 15 |
+
"""
|
| 16 |
+
Sube una imagen y devuelve una URL p煤blica accesible desde Hugging Face.
|
| 17 |
+
"""
|
| 18 |
+
file_path = os.path.join(UPLOAD_FOLDER, file.filename)
|
| 19 |
+
with open(file_path, "wb") as buffer:
|
| 20 |
+
shutil.copyfileobj(file.file, buffer)
|
| 21 |
+
|
| 22 |
+
space_name = "img"
|
| 23 |
+
base_url = f"https://jairodanielmt-{space_name}.hf.space"
|
| 24 |
+
image_url = f"{base_url}/uploaded_images/{file.filename}"
|
| 25 |
+
|
| 26 |
+
return JSONResponse(content={"url": image_url})
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
fastapi
|
| 2 |
+
uvicorn
|
| 3 |
+
python-multipart
|