yarb / app.py
yazied49's picture
Update app.py
ebb39a6 verified
raw
history blame contribute delete
731 Bytes
import os
os.environ['TRANSFORMERS_CACHE'] = './cache' # تغيير مكان الكاش
from fastapi import FastAPI
from transformers import AutoTokenizer, AutoModelForCausalLM
app = FastAPI()
model_name = "microsoft/BioGPT-Large"
# تحميل النموذج والمفردات
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(model_name)
@app.get("/")
def read_root():
return {"message": "BioGPT is ready!"}
@app.post("/generate")
def generate_text(prompt: str):
inputs = tokenizer(prompt, return_tensors="pt")
outputs = model.generate(**inputs, max_length=50)
result = tokenizer.decode(outputs[0], skip_special_tokens=True)
return {"response": result}