Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
carlossergiorodrigo committed Sep 28, 2024
1 parent 184e432 commit d20dfe4
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 28 deletions.
7 changes: 7 additions & 0 deletions backend/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
__pycache__
*.pyc
*.pyo
*.pyd
.env
.git
.gitignore
38 changes: 24 additions & 14 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,23 +1,33 @@
# Use an official Python runtime as the base image
FROM python:3.9-slim
FROM python:3.9

# Set environment variables
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1

# Install system dependencies and Rust compiler
RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential \
curl \
&& curl https://sh.rustup.rs -sSf | sh -s -- -y \
&& rm -rf /var/lib/apt/lists/*

# Add Rust to PATH
ENV PATH="/root/.cargo/bin:${PATH}"

# Set the working directory in the container
WORKDIR /app

# Copy the requirements file into the container
# Install Python dependencies
COPY requirements.txt .
RUN pip install --upgrade pip && \
pip install --no-cache-dir -r requirements.txt

# Install the Python dependencies
RUN pip install --no-cache-dir -r requirements.txt

# Copy the rest of the backend code into the container
# Copy project files
COPY . .

# Expose the port that your backend app will run on
EXPOSE 8000
# Create directory for audio files
RUN mkdir -p /app/audio

# Command to run the application using uvicorn
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000", "--reload"]
EXPOSE 8000

# Set environment variable (this is a default value, will be overwritten by docker run command)
ENV ELEVENLABS_API_KEY=""
# Run the application
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]
7 changes: 4 additions & 3 deletions backend/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@
app = FastAPI()

# Initialize the Ollama model
llm = ollama.Ollama(model="mistral-nemo")
llm = ollama.Ollama(model="llama3.1")

# Create a prompt template
story_prompt = PromptTemplate(
input_variables=["topic"],
template=(
"Write a short children's story about {topic}. "
"The story should be engaging and suitable for young children, "
"The story should be in Spanish. "
"approximately 5 minutes long when read aloud, and in the language of the topic. "
"Enclose the story within <story> </story> tags. "
"Avoid using special characters like <, >, {{, }}, or *."
Expand Down Expand Up @@ -63,7 +64,7 @@ async def generate_story(request: StoryRequest):
async def generate_audio(request: AudioRequest):
try:
# Get the ElevenLabs API key from environment variable
elevenlabs_api_key = os.environ.get('ELEVENLABS_API_KEY')
elevenlabs_api_key = "sk_b4df0b781f836c29510b133018b6ac710988fec67ea1f071" #os.environ.get('ELEVENLABS_API_KEY')
if not elevenlabs_api_key:
raise ValueError("ELEVENLABS_API_KEY environment variable is not set")
client = ElevenLabs(api_key=elevenlabs_api_key)
Expand Down Expand Up @@ -136,7 +137,7 @@ def mix_audio(speech_file, music_file):
# Add CORS middleware
app.add_middleware(
CORSMiddleware,
allow_origins=["http://localhost:3000"], # Replace with your frontend URL
allow_origins=["http://localhost:3001"], # Replace with your frontend URL
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
Expand Down
3 changes: 2 additions & 1 deletion backend/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ pydub
TTS
ffmpeg-python
elevenlabs
aiofiles
aiofiles
numpy
7 changes: 3 additions & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@ services:
build: ./frontend
ports:
- "3001:3001"
volumes:
- ./frontend:/app
- /app/node_modules
command: npm run dev -- -p 3001
environment:
- PORT=3001
command: [ "npm", "start" ]

volumes:
node_modules:
6 changes: 6 additions & 0 deletions frontend/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
node_modules
.next
.git
*.log
# Ensure the following line is NOT present
# public
28 changes: 25 additions & 3 deletions frontend/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,35 @@
FROM node:14
# Stage 1: Build
FROM node:18.17.0 AS builder

WORKDIR /app

# Install dependencies
COPY package*.json ./

RUN npm install

# Copy source code and build
COPY . .
RUN npm run build

# Stage 2: Production
FROM node:18.17.0

WORKDIR /app

# Install only production dependencies
COPY package*.json ./
RUN npm install --only=production

# Copy built application from builder
COPY --from=builder /app/.next ./.next
COPY --from=builder /app/public ./public
COPY --from=builder /app/next.config.js ./next.config.js

# Set environment variable for port
ENV PORT=3001

# Expose port
EXPOSE 3001

CMD ["npm", "run", "dev", "--", "-p", "3001"]
# Start the application
CMD ["npm", "start"]
4 changes: 1 addition & 3 deletions frontend/next.config.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
/** @type {import('next').NextConfig} */
const nextConfig = {
reactStrictMode: true,
server: {
port: 3001
}
// Removed the 'server' key as it's invalid in Next.js configuration
}

module.exports = nextConfig

0 comments on commit d20dfe4

Please sign in to comment.