ArxAlfa commited on
Commit ·
9d63bd4
1
Parent(s): aad9eca
Fix Dockerfile formatting and remove unused code
Browse filesFiles changed (4)
- Dockerfile+5-5
- app.py+1-13
- docker-compose.ymlAdded+13
- requirements.txt+1-1
9 unmodified lines10111213141516171819202122232425269 unmodified lines# Install requirements.txtRUN pip install --no-cache-dir --upgrade -r /code/requirements.txt# Set up a new user named "user" with user ID 1000RUN useradd -m -u 1000 user# Switch to the "user" userUSER user# Set home to the user's home directoryENV HOME=/home/user PATH=/home/user/.local/bin:$PATH# Set the working directory to the user's home directoryWORKDIR $HOME/app# Copy the current directory contents into the container at $HOME/app setting the owner to the userCOPY --chown=user . $HOME/app# Start the FastAPI app on port 7860, the default port expected by Spaces9 unmodified lines10111213141516171819202122232425269 unmodified lines# Install requirements.txtRUN pip install --no-cache-dir --upgrade -r /code/requirements.txt# # Set up a new user named "user" with user ID 1000RUN useradd -m -u 1000 user# # Switch to the "user" userUSER user# # Set home to the user's home directoryENV HOME=/home/user PATH=/home/user/.local/bin:$PATH# # Set the working directory to the user's home directoryWORKDIR $HOME/app# # Copy the current directory contents into the container at $HOME/app setting the owner to the userCOPY --chown=user . $HOME/app# Start the FastAPI app on port 7860, the default port expected by Spaces
1234567891011121314151617181920212223from fastapi import FastAPIfrom transformers import pipelinefrom transformers import T5Tokenizer, T5ForConditionalGeneration# Create a new FastAPI app instanceapp = FastAPI(docs_url="/", redoc_url="/new_redoc")# Create a translation pipelinetokenizer = T5Tokenizer.from_pretrained("google/flan-t5-small")model = T5ForConditionalGeneration.from_pretrained("google/flan-t5-small")# Create a POST endpoint@app.get("/generate")def generate(text: str):"""Traduce del castellano al inglés"""input_text = "translate Spanish to English: " + textinput_ids = tokenizer(input_text, return_tensors="pt").input_idsoutputs = model.generate(input_ids)print(tokenizer.decode(outputs[0]))return {"output": tokenizer.decode(outputs[0])}1234567891011from fastapi import FastAPI# Create a new FastAPI app instanceapp = FastAPI(docs_url="/", redoc_url="/new_redoc")# Create a POST endpoint@app.get("/generate")def generate(text: str):"""Traduce del castellano al inglés"""return {"output": text}
12345678910111213version: '3.8'services: your-service: image: prueba-ia ports: - "7860:7860" deploy: resources: reservations: devices: - driver: nvidia count: 1 capabilities: [ gpu ]2 unmodified lines34562 unmodified linesuvicorn[standard]==0.17.*sentencepiece==0.1.*torch==1.11.*transformers==4.*2 unmodified lines34562 unmodified linesuvicorn[standard]==0.17.*sentencepiece==0.1.*torch==1.11.*#transformers==4.*
Dockerfile+5-5
app.py+1-13
docker-compose.ymlAdded+13
requirements.txt+1-1