Spaces:
Sleeping
Sleeping
File size: 828 Bytes
bc5f9c0 31cc367 bc5f9c0 31cc367 bc5f9c0 |
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 |
from fastapi import FastAPI
from transformers import AutoTokenizer, AutoModelForCausalLM
import torch
import os
# Set cache directory for Hugging Face Transformers
os.environ["TRANSFORMERS_CACHE"] = "/home/user/.cache"
# Load the tokenizer and model
tokenizer = AutoTokenizer.from_pretrained("matsant01/STEMerald-2b")
model = AutoModelForCausalLM.from_pretrained("matsant01/STEMerald-2b")
# Initialize FastAPI app
app = FastAPI()
@app.get("/")
def read_root():
return {"message": "Welcome to the STEMerald-2b API"}
#@app.post("/generate/")
#def generate_text(prompt: str):
# inputs = tokenizer(prompt, return_tensors="pt")
# outputs = model.generate(inputs["input_ids"], max_length=50)
# generated_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
# return {"generated_text": generated_text} |