-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
110 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters