Spaces:
Sleeping
Sleeping
Commit
·
4a916a6
1
Parent(s):
cff1a2a
Deploy to Hugging Face Spaces with Docker config
Browse files- Dockerfile +36 -0
- README.md +27 -0
- app.py +1 -1
- render.yaml +7 -1
- requirements.txt +0 -4
Dockerfile
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Use an official Python runtime as a parent image
|
| 2 |
+
FROM python:3.10-slim
|
| 3 |
+
|
| 4 |
+
# Set the working directory in the container
|
| 5 |
+
WORKDIR /app
|
| 6 |
+
|
| 7 |
+
# Install system dependencies for audio and document processing
|
| 8 |
+
RUN apt-get update && apt-get install -y \
|
| 9 |
+
build-essential \
|
| 10 |
+
libasound2-dev \
|
| 11 |
+
portaudio19-dev \
|
| 12 |
+
&& rm -rf /var/lib/apt/lists/*
|
| 13 |
+
|
| 14 |
+
# Copy the requirements file into the container
|
| 15 |
+
COPY requirements.txt .
|
| 16 |
+
|
| 17 |
+
# Install any needed packages specified in requirements.txt
|
| 18 |
+
RUN pip install --no-cache-dir -r requirements.txt
|
| 19 |
+
|
| 20 |
+
# Copy the rest of the application code
|
| 21 |
+
COPY . .
|
| 22 |
+
|
| 23 |
+
# Create directory for models/cache with full permissions
|
| 24 |
+
RUN mkdir -p /.cache && chmod -R 777 /.cache
|
| 25 |
+
|
| 26 |
+
# Set environment variables for memory efficiency
|
| 27 |
+
ENV MKL_NUM_THREADS=1
|
| 28 |
+
ENV OMP_NUM_THREADS=1
|
| 29 |
+
ENV TRANSFORMERS_CACHE=/.cache
|
| 30 |
+
ENV HF_HOME=/.cache
|
| 31 |
+
|
| 32 |
+
# Hugging Face Spaces uses port 7860 by default
|
| 33 |
+
EXPOSE 7860
|
| 34 |
+
|
| 35 |
+
# Run the application
|
| 36 |
+
CMD ["gunicorn", "--bind", "0.0.0.0:7860", "app:app", "--timeout", "120", "--workers", "1", "--threads", "4"]
|
README.md
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: Insurance Brochure RAG
|
| 3 |
+
emoji: 🛡️
|
| 4 |
+
colorFrom: green
|
| 5 |
+
colorTo: blue
|
| 6 |
+
sdk: docker
|
| 7 |
+
app_port: 7860
|
| 8 |
+
pinned: false
|
| 9 |
+
---
|
| 10 |
+
|
| 11 |
+
# Insurance Brochure RAG Application
|
| 12 |
+
|
| 13 |
+
An AI-powered RAG system for analyzing insurance brochures and documents.
|
| 14 |
+
|
| 15 |
+
## Local Development
|
| 16 |
+
|
| 17 |
+
1. Install requirements: `pip install -r requirements.txt`
|
| 18 |
+
2. Set `.env` variables (see `.env.example`)
|
| 19 |
+
3. Run `python app.py`
|
| 20 |
+
|
| 21 |
+
## Hugging Face Deployment
|
| 22 |
+
|
| 23 |
+
This app is configured to run on Hugging Face Spaces using the **Docker SDK**.
|
| 24 |
+
|
| 25 |
+
### Configuration
|
| 26 |
+
- **Instance Type**: 16GB RAM (CPU Basic) or higher.
|
| 27 |
+
- **Secrets**: Add `GROQ_API_KEY` in the Space settings.
|
app.py
CHANGED
|
@@ -262,5 +262,5 @@ def list_files():
|
|
| 262 |
return jsonify({"files": []})
|
| 263 |
|
| 264 |
if __name__ == "__main__":
|
| 265 |
-
port = int(os.environ.get("PORT",
|
| 266 |
app.run(host="0.0.0.0", port=port)
|
|
|
|
| 262 |
return jsonify({"files": []})
|
| 263 |
|
| 264 |
if __name__ == "__main__":
|
| 265 |
+
port = int(os.environ.get("PORT", 7860))
|
| 266 |
app.run(host="0.0.0.0", port=port)
|
render.yaml
CHANGED
|
@@ -3,9 +3,15 @@ services:
|
|
| 3 |
name: brochure-rag
|
| 4 |
env: python
|
| 5 |
buildCommand: pip install -r requirements.txt
|
| 6 |
-
startCommand: gunicorn app:app
|
| 7 |
envVars:
|
| 8 |
- key: PYTHON_VERSION
|
| 9 |
value: 3.10.0
|
| 10 |
- key: PORT
|
| 11 |
value: 10000
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
name: brochure-rag
|
| 4 |
env: python
|
| 5 |
buildCommand: pip install -r requirements.txt
|
| 6 |
+
startCommand: gunicorn app:app --workers 1 --threads 2 --timeout 120
|
| 7 |
envVars:
|
| 8 |
- key: PYTHON_VERSION
|
| 9 |
value: 3.10.0
|
| 10 |
- key: PORT
|
| 11 |
value: 10000
|
| 12 |
+
- key: MKL_NUM_THREADS
|
| 13 |
+
value: "1"
|
| 14 |
+
- key: OMP_NUM_THREADS
|
| 15 |
+
value: "1"
|
| 16 |
+
- key: TRANSFORMERS_OFFLINE
|
| 17 |
+
value: "1"
|
requirements.txt
CHANGED
|
@@ -1,9 +1,6 @@
|
|
| 1 |
flask
|
| 2 |
gunicorn
|
| 3 |
flask-cors
|
| 4 |
-
fastapi
|
| 5 |
-
uvicorn
|
| 6 |
-
python-multipart
|
| 7 |
langchain
|
| 8 |
langchain-community
|
| 9 |
langchain-core
|
|
@@ -19,7 +16,6 @@ tqdm
|
|
| 19 |
langchain-huggingface
|
| 20 |
SpeechRecognition
|
| 21 |
langchain-groq
|
| 22 |
-
streamlit
|
| 23 |
requests
|
| 24 |
pdfplumber
|
| 25 |
python-docx
|
|
|
|
| 1 |
flask
|
| 2 |
gunicorn
|
| 3 |
flask-cors
|
|
|
|
|
|
|
|
|
|
| 4 |
langchain
|
| 5 |
langchain-community
|
| 6 |
langchain-core
|
|
|
|
| 16 |
langchain-huggingface
|
| 17 |
SpeechRecognition
|
| 18 |
langchain-groq
|
|
|
|
| 19 |
requests
|
| 20 |
pdfplumber
|
| 21 |
python-docx
|