minzo456 commited on
Commit
461fffe
·
verified ·
1 Parent(s): 69f2a7f

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -0
app.py ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI, Request
2
+ from huggingface_hub import InferenceClient
3
+ import os
4
+
5
+ app = FastAPI()
6
+
7
+ # ඔබ පියවර 1 දී ගත් Token එක Space එකේ 'Secrets' වල HF_TOKEN නමින් දාන්න ඕනේ
8
+ client = InferenceClient("MiniMaxAI/MiniMax-M2.7", token=os.getenv("HF_TOKEN"))
9
+
10
+ @app.post("/generate")
11
+ async def generate(request: Request):
12
+ data = await request.json()
13
+ prompt = data.get("prompt")
14
+
15
+ try:
16
+ response = client.chat_completion(
17
+ messages=[
18
+ {"role": "system", "content": "You are Elephant AI Pro, a specialist coding and logic engine by MINZO-PRIME."},
19
+ {"role": "user", "content": prompt}
20
+ ],
21
+ max_tokens=1000
22
+ )
23
+ return {"response": response.choices[0].message.content}
24
+ except Exception as e:
25
+ return {"error": str(e)}
26
+
27
+ if __name__ == "__main__":
28
+ import uvicorn
29
+ uvicorn.run(app, host="0.0.0.0", port=7860)