varsshancoder commited on
Commit
ab50d18
·
verified ·
1 Parent(s): aef49fe

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -0
app.py ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI, Header, HTTPException
2
+ from transformers import pipeline
3
+
4
+ API_KEY = "CHANGE_THIS_KEY"
5
+
6
+ app = FastAPI()
7
+
8
+ generator = pipeline(
9
+ "text-generation",
10
+ model="mistralai/Mistral-7B-Instruct-v0.3",
11
+ max_new_tokens=256
12
+ )
13
+
14
+ @app.post("/generate")
15
+ def generate(prompt: str, x_api_key: str = Header(None)):
16
+ if x_api_key != API_KEY:
17
+ raise HTTPException(status_code=401, detail="Invalid API Key")
18
+
19
+ output = generator(prompt)
20
+ return {"response": output[0]["generated_text"]}