AutoCoder_QW_7B / app.py
Aleksey22's picture
Add application file
724cc35
raw
history blame contribute delete
951 Bytes
from transformers import AutoTokenizer, AutoModelForCausalLM
from fastapi import FastAPI
from pydantic import BaseModel
import uvicorn
# Cargar el modelo y el tokenizador
model_name = "Bin12345/AutoCoder_QW_7B"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(model_name)
# Definir la clase para la solicitud
class Message(BaseModel):
content: str
# Crear la aplicaci贸n FastAPI
app = FastAPI()
# Definir el endpoint para la generaci贸n de texto
@app.post("/generate/")
async def generate_text(message: Message):
inputs = tokenizer.encode(message.content, return_tensors='pt')
outputs = model.generate(inputs, max_length=50, num_return_sequences=1)
generated_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
return {"generated_text": generated_text}
# Ejecutar la aplicaci贸n con uvicorn
if __name__ == "__main__":
uvicorn.run(app, host="0.0.0.0", port=7860)