File size: 951 Bytes
724cc35
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 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)