Spaces:
Runtime error
Runtime error
File size: 874 Bytes
9bf2007 bff48c8 dcd2d54 3e6fc0f 9bf2007 e5e2748 dcd2d54 e5e2748 c31fdd4 bff48c8 3e6fc0f 9bf2007 bff48c8 9bf2007 e5e2748 9bf2007 ed0c347 9bf2007 b554914 9bf2007 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
import transformers
import torch
import os
from fastapi import FastAPI
from transformers import AutoTokenizer
# Load the model
app = FastAPI()
model = "meta-llama/Llama-2-7b-hf"
access_token = os.getenv("access_token")
@app.get("/")
def llama():
tokenizer = AutoTokenizer.from_pretrained(model,token=access_token)
pipeline = transformers.pipeline("text-generation" ,model=model ,torch_dtype=torch.float16 ,device_map="auto" , )
sequences = pipeline(
'I liked "Breaking Bad" and "Band of Brothers". Do you have any recommendations of other shows I might like?\n',
do_sample=True,
top_k=10,
num_return_sequences=1,
eos_token_id=tokenizer.eos_token_id,
max_length=200,
)
for seq in sequences:
print("Result: {seq['generated_text']}")
return {"output": sequences[0]["generated_text"]}
|