Spaces:
Sleeping
Sleeping
File size: 839 Bytes
416bd58 |
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 30 31 32 33 34 |
from fastapi import FastAPI
from fastapi.responses import HTMLResponse
from transformers import pipeline
import cohere
import os
app = FastAPI()
pipe = pipeline("text2text-generation", model="Helsinki-NLP/opus-mt-en-es")
co = cohere.Client(api_key="mrCaHsq1SlpANdsCyu6lII16xxsBq2IULQxZ9hfq")
@app.get("/", response_class=HTMLResponse)
def get_home():
with open("index.html") as f:
return HTMLResponse(content=f.read())
@app.get("/generate/")
def generate(text: str):
output = pipe(text)
return {"output": output[0]['generated_text']}
@app.get("/cohereai/")
def cohereai(text: str):
response = co.generate(
model='command-r-plus',
prompt=text,
temperature=0.3,
max_tokens=100,
)
return {"output": response.generations[0].text.strip()}
|