Spaces:
Runtime error
Runtime error
Upload 3 files
Browse files- Dockerfile +14 -0
- api.py +50 -0
- requirements.txt +0 -0
Dockerfile
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM python:3.9
|
| 2 |
+
|
| 3 |
+
RUN useradd -m -u 1000 user
|
| 4 |
+
USER user
|
| 5 |
+
ENV PATH="/home/user/.local/bin:$PATH"
|
| 6 |
+
|
| 7 |
+
WORKDIR /app
|
| 8 |
+
|
| 9 |
+
COPY --chown=user ./requirements.txt requirements.txt
|
| 10 |
+
RUN pip install --no-cache-dir --upgrade -r requirements.txt
|
| 11 |
+
|
| 12 |
+
COPY --chown=user . /app
|
| 13 |
+
CMD ["uvicorn", "api:app", "--host", "0.0.0.0", "--port", "7860"]
|
| 14 |
+
|
api.py
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import FastAPI
|
| 2 |
+
from pydantic import BaseModel
|
| 3 |
+
from huggingface_hub import hf_hub_download
|
| 4 |
+
from llama_cpp import Llama
|
| 5 |
+
|
| 6 |
+
# Defini莽茫o do modelo de dados de entrada
|
| 7 |
+
class Question(BaseModel):
|
| 8 |
+
text: str
|
| 9 |
+
|
| 10 |
+
# Inicializando o FastAPI
|
| 11 |
+
app = FastAPI()
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
llm = Llama.from_pretrained(
|
| 15 |
+
repo_id="FabioSantos/curso_llama3.2_Finetune",
|
| 16 |
+
filename="unsloth.Q8_0.gguf",
|
| 17 |
+
)
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
def get_response(text: str) -> str:
|
| 21 |
+
|
| 22 |
+
response = llm.create_chat_completion(
|
| 23 |
+
messages=[
|
| 24 |
+
{
|
| 25 |
+
"role": "user",
|
| 26 |
+
"content": text # Corre莽茫o: Remover as chaves {} que estavam criando um set
|
| 27 |
+
}
|
| 28 |
+
]
|
| 29 |
+
)
|
| 30 |
+
|
| 31 |
+
response_text = response['choices'][0]['text']
|
| 32 |
+
|
| 33 |
+
# Extrair a resposta ap贸s "### Response:"
|
| 34 |
+
if "### Response:" in response_text:
|
| 35 |
+
answer = response_text.split("### Response:")[1].strip()
|
| 36 |
+
else:
|
| 37 |
+
answer = response_text.strip()
|
| 38 |
+
|
| 39 |
+
print(f"Final Answer: {answer}")
|
| 40 |
+
return answer
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
# Endpoint para receber uma quest茫o e retornar a resposta
|
| 44 |
+
@app.post("/ask")
|
| 45 |
+
def ask_question(question: Question):
|
| 46 |
+
response = get_response(question.text)
|
| 47 |
+
return {"response": response}
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
|
requirements.txt
ADDED
|
Binary file (140 Bytes). View file
|
|
|