Spaces:
Runtime error
Runtime error
Download app.py from danosethrus/EthioDocs: direct link, hf CLI and curl.
- Browser
- Download file 866 Bytes
-
https://huggingface.co/spaces/danosethrus/EthioDocs/resolve/main/app.py
- Command line
-
hf download hf://spaces/danosethrus/EthioDocs/app.py
-
curl -L -o app.py https://huggingface.co/spaces/danosethrus/EthioDocs/resolve/main/app.py
866 Bytes
| import os | |
| from fastapi import FastAPI, Request | |
| from fastapi.responses import JSONResponse, HTMLResponse | |
| from transformers import pipeline | |
| app = FastAPI() | |
| # This loads the model directly into the Space's memory instead of calling an API | |
| # NOTE: This might crash the Space if you don't have enough RAM! | |
| try: | |
| pipe = pipeline("text-generation", model="danosethrus/EthioDoc", device_map="auto") | |
| except Exception as e: | |
| pipe = None | |
| print(f"Model Load Error: {e}") | |
| async def home(): | |
| with open("index.html") as f: | |
| return f.read() | |
| async def ask_ai(request: Request): | |
| data = await request.json() | |
| if pipe is None: | |
| return JSONResponse({"error": "Model failed to load in memory"}, status_code=500) | |
| output = pipe(data.get("inputs", ""), max_new_tokens=100) | |
| return JSONResponse(content=output) |