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