ahsansaeed's picture
upload files
416bd58 verified
raw
history blame contribute delete
839 Bytes
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()}