othmanezaid77 commited on
Commit
16cdb8a
·
verified ·
1 Parent(s): 09751df

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -0
app.py ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI
2
+ from llama_cpp import Llama
3
+
4
+ app = FastAPI()
5
+
6
+ # تحميل الموديل من Hugging Face أوتماتيكياً
7
+ llm = Llama.from_pretrained(
8
+ repo_id="Orenguteng/Llama-3-8B-Lexi-Uncensored-GGUF",
9
+ filename="Llama-3-8B-Lexi-Uncensored.Q4_K_M.gguf",
10
+ n_ctx=2048,
11
+ n_threads=2 # باش ما يتقالوش السيرفر فابور
12
+ )
13
+
14
+ @app.get("/")
15
+ def home():
16
+ return {"message": "EVA AI Server is Running!"}
17
+
18
+ @app.post("/chat")
19
+ async def chat(data: dict):
20
+ prompt = data.get("prompt", "")
21
+ # ستايل الحوار
22
+ full_prompt = f"<|im_start|>user\n{prompt}<|im_end|>\n<|im_start|>assistant\n"
23
+
24
+ output = llm(
25
+ full_prompt,
26
+ max_tokens=500,
27
+ stop=["<|im_end|>"],
28
+ echo=False
29
+ )
30
+ return {"response": output['choices'][0]['text']}