Spaces:
Runtime error
Runtime error
Download app.py from ahsansaeed/AI-Translation-Chatbot: direct link, hf CLI and curl.
- Browser
- Download file 839 Bytes
-
https://huggingface.co/spaces/ahsansaeed/AI-Translation-Chatbot/resolve/main/app.py
- Command line
-
hf download hf://spaces/ahsansaeed/AI-Translation-Chatbot/app.py
-
curl -L -o app.py https://huggingface.co/spaces/ahsansaeed/AI-Translation-Chatbot/resolve/main/app.py
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") | |
| 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()} | |