Spaces:
Build error
Build error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import FastAPI
|
| 2 |
+
from llama_cpp import Llama
|
| 3 |
+
import uvicorn
|
| 4 |
+
|
| 5 |
+
app = FastAPI()
|
| 6 |
+
|
| 7 |
+
# This loads the model we will download in the Dockerfile
|
| 8 |
+
llm = Llama(model_path="./model.gguf", n_ctx=2048)
|
| 9 |
+
|
| 10 |
+
@app.get("/")
|
| 11 |
+
def home():
|
| 12 |
+
return {"status": "PIBIT NANO GPT is Online"}
|
| 13 |
+
|
| 14 |
+
@app.post("/ask")
|
| 15 |
+
async def ask_ai(data: dict):
|
| 16 |
+
prompt = data.get("prompt", "")
|
| 17 |
+
output = llm(f"User: {prompt}\nAI:", max_tokens=150, stop=["User:"], echo=False)
|
| 18 |
+
return {"response": output["choices"][0]["text"]}
|
| 19 |
+
|
| 20 |
+
if __name__ == "__main__":
|
| 21 |
+
uvicorn.run(app, host="0.0.0.0", port=7860)
|