Spaces:
Runtime error
Runtime error
shubhankars
commited on
created app.py
Browse files
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}
|