Spaces:
Sleeping
Sleeping
Create main.py
Browse files
main.py
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from llama_cpp.server.app import create_app, Settings
|
| 2 |
+
from fastapi.responses import HTMLResponse
|
| 3 |
+
from fastapi.middleware.cors import CORSMiddleware
|
| 4 |
+
from fastapi.responses import RedirectResponse
|
| 5 |
+
import os
|
| 6 |
+
|
| 7 |
+
try:
|
| 8 |
+
print(os.system('ls'))
|
| 9 |
+
except:
|
| 10 |
+
print('could Not print')
|
| 11 |
+
|
| 12 |
+
model_path = "qwen2-1.5b-instruct-function-calling-v1.Q2_K (1).gguf"
|
| 13 |
+
|
| 14 |
+
app = create_app(
|
| 15 |
+
Settings(
|
| 16 |
+
n_threads=4,
|
| 17 |
+
model=model_path,
|
| 18 |
+
embedding=True,
|
| 19 |
+
n_gpu_layers=33
|
| 20 |
+
)
|
| 21 |
+
)
|
| 22 |
+
app.add_middleware(
|
| 23 |
+
CORSMiddleware,
|
| 24 |
+
allow_origins=["*"],
|
| 25 |
+
allow_credentials=True,
|
| 26 |
+
allow_methods=["*"],
|
| 27 |
+
allow_headers=["*"],
|
| 28 |
+
)
|
| 29 |
+
|
| 30 |
+
@app.get("/")
|
| 31 |
+
async def redirect_root_to_docs():
|
| 32 |
+
return RedirectResponse("/docs")
|
| 33 |
+
|
| 34 |
+
if __name__ == "__main__":
|
| 35 |
+
import uvicorn
|
| 36 |
+
uvicorn.run(app, host="0.0.0.0", port=7860)
|