Upload 3 files
Browse files- Dockerfile +20 -0
- main.py +20 -0
- requirements.txt +0 -0
Dockerfile
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Use an official Python runtime as a base image
|
| 2 |
+
FROM python:3.9-slim
|
| 3 |
+
|
| 4 |
+
# Set the working directory in the container
|
| 5 |
+
WORKDIR /app
|
| 6 |
+
|
| 7 |
+
# Copy the requirements file into the container
|
| 8 |
+
COPY requirements.txt .
|
| 9 |
+
|
| 10 |
+
# Install the dependencies
|
| 11 |
+
RUN pip install --no-cache-dir -r requirements.txt
|
| 12 |
+
|
| 13 |
+
# Copy the FastAPI app into the container
|
| 14 |
+
COPY . .
|
| 15 |
+
|
| 16 |
+
# Expose port 7860 (the default port for Hugging Face Spaces)
|
| 17 |
+
EXPOSE 7860
|
| 18 |
+
|
| 19 |
+
# Command to run the FastAPI app with Uvicorn
|
| 20 |
+
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
|
main.py
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import FastAPI, HTTPException, Response
|
| 2 |
+
from pydantic import BaseModel
|
| 3 |
+
from plantuml import PlantUML
|
| 4 |
+
|
| 5 |
+
app = FastAPI()
|
| 6 |
+
|
| 7 |
+
class PlantUMLRequest(BaseModel):
|
| 8 |
+
script: str
|
| 9 |
+
|
| 10 |
+
# Initialize the PlantUML server URL
|
| 11 |
+
plantuml_server = PlantUML(url="http://www.plantuml.com/plantuml/png/")
|
| 12 |
+
|
| 13 |
+
@app.post("/generate-image/")
|
| 14 |
+
async def generate_image(request: PlantUMLRequest):
|
| 15 |
+
try:
|
| 16 |
+
# Use the `processes` function to get the raw PNG data
|
| 17 |
+
image_data = plantuml_server.processes(request.script)
|
| 18 |
+
return Response(content=image_data, media_type="image/png")
|
| 19 |
+
except Exception as e:
|
| 20 |
+
raise HTTPException(status_code=500, detail=str(e))
|
requirements.txt
ADDED
|
Binary file (608 Bytes). View file
|
|
|