Skip to content

Commit

Permalink
ci/cd
Browse files Browse the repository at this point in the history
  • Loading branch information
Ashad001 committed Oct 19, 2024
1 parent 2faea6a commit 29e8ba2
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 1 deletion.
25 changes: 25 additions & 0 deletions .github/workflows/sync2hf.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Sync to Hugging Face hub

on:
push:
branches: [main]
workflow_dispatch:

jobs:
sync-to-hub:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Push to Hugging Face hub
env:
HF_TOKEN: ${{ secrets.HF_SECRET }}
run: |
git remote remove origin || true
git remote add origin https://Ashad001:${{ secrets.HF_SECRET }}@huggingface.co/spaces/Ashad001/roomaligner
git add .
git commit -m "Sync code to Hugging Face Hub" || true
git push --force origin main
13 changes: 13 additions & 0 deletions DOCKERFILE
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM python:3.12

RUN useradd -m -u 1000 user
USER user
ENV PATH="/home/user/.local/bin:$PATH"

WORKDIR /app

COPY --chown=user ./requirements.txt requirements.txt
RUN pip install --no-cache-dir --upgrade -r requirements.txt

COPY --chown=user . /app
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
70 changes: 70 additions & 0 deletions app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import os
import base64
import json
from io import BytesIO
from fastapi import FastAPI, UploadFile, File, HTTPException
from fastapi.responses import JSONResponse
from fastapi.middleware.cors import CORSMiddleware
from dotenv import load_dotenv
from plan.agents import GeneratePlan, GenerateSuggestions
from plan.image_analyzer import ImageAnalyzer
from raster.raster import InferenceClient
from utils.preprocess_data import preprocess_data
from PIL import Image

load_dotenv()

app = FastAPI(title="Interior Designer API")

app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)

# required classes
inference_client = InferenceClient()
plan_generator = GeneratePlan()
image_analyzer = ImageAnalyzer()
suggestions_generator = GenerateSuggestions()

@app.post("/upload-room-image/")
async def upload_image(file: UploadFile = File(...)):
"""
Upload room image and get natural language description and suggested room layout.
"""
try:
contents = await file.read()
img = Image.open(BytesIO(contents))

# Convert image to base64
buffered = BytesIO()
img.save(buffered, format="JPEG")
image_base64 = base64.b64encode(buffered.getvalue()).decode('utf-8')

# Step 1: Classify objects in the image
result = inference_client.infer_image(image_base64)
data = preprocess_data(result)

# Step 2: Generate a natural language description
nl_description = plan_generator.forward(data)

# Step 3: Analyze room structure and generate suggestions
room_structure = image_analyzer.generate_floor_plan_details(image_base64, nl_description)
suggested_structure = suggestions_generator.forward(room_structure.content)

# Return response as JSON
return JSONResponse(content={
"natural_language_description": nl_description,
"room_structure": room_structure.content,
"suggested_structure": suggested_structure
})

except Exception as e:
raise HTTPException(status_code=500, detail=f"An error occurred: {e}")

@app.get("/")
def read_root():
return {"message": "Welcome to the Interior Designer API!"}
1 change: 0 additions & 1 deletion plan/agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from typing import List, Dict, Any

load_dotenv(".env")
print(os.getenv("OPENAI_API_KEY"))
lm = dspy.OpenAI(model="gpt-4o-mini", api_key=os.getenv("OPENAI_API_KEY"), max_tokens=4096)
dspy.settings.configure(lm=lm)

Expand Down
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ dill==0.3.8
diskcache==5.6.3
distro==1.9.0
dspy==2.5.3
fastapi==0.115.2
filelock==3.16.1
fonttools==4.54.1
frozenlist==1.4.1
Expand Down Expand Up @@ -87,6 +88,7 @@ six==1.16.0
smmap==5.0.1
sniffio==1.3.1
SQLAlchemy==2.0.35
starlette==0.40.0
streamlit==1.39.0
structlog==24.4.0
supervision==0.23.0
Expand Down

0 comments on commit 29e8ba2

Please sign in to comment.