shubhankars commited on
Commit
768bab4
·
verified ·
1 Parent(s): 5bd3076

created 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
2
+ from transformers import AutoTokenizer, AutoModelForCausalLM
3
+
4
+ # Load the model and tokenizer
5
+ model_name = "sander-wood/bgpt"
6
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
7
+ model = AutoModelForCausalLM.from_pretrained(model_name)
8
+
9
+ app = FastAPI()
10
+
11
+ @app.get("/")
12
+ def greet_json():
13
+ return {"Hello": "World!"}
14
+
15
+ @app.get("/generate/")
16
+ def generate_text(prompt: str):
17
+ inputs = tokenizer(prompt, return_tensors="pt")
18
+ outputs = model.generate(inputs["input_ids"], max_length=100, num_return_sequences=1)
19
+ generated_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
20
+ return {"Generated Text": generated_text}