Spaces:
Runtime error
Runtime error
Upload 3 files
Browse files- Dockerfile +31 -4
- app.py +16 -1
- requirements.txt +3 -1
Dockerfile
CHANGED
@@ -1,6 +1,3 @@
|
|
1 |
-
# read the doc: https://huggingface.co/docs/hub/spaces-sdks-docker
|
2 |
-
# you will also find guides on how best to write your Dockerfile
|
3 |
-
|
4 |
FROM python:3.9
|
5 |
|
6 |
RUN useradd -m -u 1000 user
|
@@ -13,4 +10,34 @@ COPY --chown=user ./requirements.txt requirements.txt
|
|
13 |
RUN pip install --no-cache-dir --upgrade -r requirements.txt
|
14 |
|
15 |
COPY --chown=user . /app
|
16 |
-
CMD ["uvicorn", "
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
FROM python:3.9
|
2 |
|
3 |
RUN useradd -m -u 1000 user
|
|
|
10 |
RUN pip install --no-cache-dir --upgrade -r requirements.txt
|
11 |
|
12 |
COPY --chown=user . /app
|
13 |
+
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
|
14 |
+
|
15 |
+
|
16 |
+
# FROM python:3.9
|
17 |
+
|
18 |
+
# # Set environment variables
|
19 |
+
# ENV MODEL_NAME="meta-llama/Meta-Llama-3-8B-Instruct"
|
20 |
+
# ENV TRANSFORMERS_CACHE="/app/transformers_cache"
|
21 |
+
# ENV LC_ALL=C.UTF-8
|
22 |
+
# ENV LANG=C.UTF-8
|
23 |
+
|
24 |
+
# # Install additional dependencies if needed
|
25 |
+
# RUN pip install --no-cache-dir fastapi uvicorn
|
26 |
+
|
27 |
+
# # Create the app directory and set permissions
|
28 |
+
# RUN mkdir /app && chmod -R 777 /app
|
29 |
+
|
30 |
+
# # Set the working directory
|
31 |
+
# WORKDIR /app
|
32 |
+
|
33 |
+
# # Copy your model and code to the container
|
34 |
+
# COPY ./app.py /app
|
35 |
+
# COPY ./Dockerfile /app
|
36 |
+
# COPY ./requirements.txt /app
|
37 |
+
|
38 |
+
|
39 |
+
# # Expose the port FastAPI will run on
|
40 |
+
# EXPOSE 8000
|
41 |
+
|
42 |
+
# # Run FastAPI server
|
43 |
+
# CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "8000"]
|
app.py
CHANGED
@@ -1,7 +1,22 @@
|
|
1 |
-
from fastapi import FastAPI
|
|
|
2 |
|
3 |
app = FastAPI()
|
4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
@app.get("/")
|
6 |
def greet_json():
|
7 |
return {"Hello": "World!"}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from fastapi import FastAPI, HTTPException
|
2 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline
|
3 |
|
4 |
app = FastAPI()
|
5 |
|
6 |
+
# Load model and tokenizer
|
7 |
+
model_name = "meta-llama/Meta-Llama-3-8B-Instruct"
|
8 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
9 |
+
model = AutoModelForCausalLM.from_pretrained(model_name)
|
10 |
+
generator = pipeline("text-generation", model=model, tokenizer=tokenizer)
|
11 |
+
|
12 |
@app.get("/")
|
13 |
def greet_json():
|
14 |
return {"Hello": "World!"}
|
15 |
+
|
16 |
+
@app.post("/generate")
|
17 |
+
def generate_text(prompt: str):
|
18 |
+
try:
|
19 |
+
generated_text = generator(prompt, max_length=50)
|
20 |
+
return {"generated_text": generated_text[0]['generated_text']}
|
21 |
+
except Exception as e:
|
22 |
+
raise HTTPException(status_code=500, detail=str(e))
|
requirements.txt
CHANGED
@@ -1,2 +1,4 @@
|
|
1 |
fastapi
|
2 |
-
|
|
|
|
|
|
1 |
fastapi
|
2 |
+
transformers
|
3 |
+
uvicorn
|
4 |
+
torch
|