|
|
|
|
|
|
|
import torch |
|
from transformers import pipeline |
|
from fastapi import FastAPI |
|
|
|
app = FastAPI() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pipe = pipeline("text-generation", model="HuggingFaceH4/zephyr-7b-alpha", torch_dtype=torch.bfloat16, device_map="auto") |
|
|
|
|
|
messages = [ |
|
{ |
|
"role": "system", |
|
"content": "You are a Spiritual Coach who always responds in the most profound and poetic style", |
|
}, |
|
{"role": "user", "content": "What is Life?"}, |
|
] |
|
prompt = pipe.tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True) |
|
outputs = pipe(prompt, max_new_tokens=2560, do_sample=True, temperature=0.7, top_k=50, top_p=0.95) |
|
print(outputs[0]["generated_text"]) |
|
|
|
|
|
@app.get("/") |
|
async def root(): |
|
return {"message": "Hello World"} |
|
|
|
|
|
@app.post("/predict") |
|
async def root(text): |
|
|
|
|
|
return outputs[0]["generated_text"] |