Kaan
Update app.py
e3d6e0d verified
raw
history blame
872 Bytes
from fastapi import FastAPI
from transformers import AutoModelForCausalLM, AutoTokenizer
from llama_cpp import Llama
from huggingface_hub import hf_hub_download
app = FastAPI()
@app.get("/")
async def install_model():
#hf_hub_download(repo_id="TheBloke/Mistral-7B-v0.1-GGUF", filename="mistral-7b-v0.1.Q4_K_M.gguf")
prompt = "Once upon a time, there was a"
# Tokenize the prompt
inputs = tokenizer(prompt, return_tensors="pt")
# Generate text
output = model.generate(input_ids=inputs["input_ids"], max_length=50, num_return_sequences=3, temperature=0.7)
# Decode the generated sequences
generated_texts = tokenizer.batch_decode(output, skip_special_tokens=True)
# Print the generated sequences
for i, text in enumerate(generated_texts):
print(f"Generated Text {i+1}: {text}")
return generated_texts