Spaces:
Sleeping
Sleeping
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") | |
def get_home(): | |
with open("index.html") as f: | |
return HTMLResponse(content=f.read()) | |
def generate(text: str): | |
output = pipe(text) | |
return {"output": output[0]['generated_text']} | |
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()} | |