Spaces:
Sleeping
Sleeping
Download app.py from VortexHunter23/tesstapi: direct link, hf CLI and curl.
- Browser
- Download file 969 Bytes
-
https://huggingface.co/spaces/VortexHunter23/tesstapi/resolve/main/app.py
- Command line
-
hf download hf://spaces/VortexHunter23/tesstapi/app.py
-
curl -L -o app.py https://huggingface.co/spaces/VortexHunter23/tesstapi/resolve/main/app.py
969 Bytes
| import os | |
| import logging | |
| from fastapi import FastAPI, HTTPException | |
| from fastapi.responses import StreamingResponse | |
| from pydantic import BaseModel | |
| from langchain_community.llms import Ollama | |
| from langchain.callbacks.manager import CallbackManager | |
| from langchain.callbacks.streaming_stdout import StreamingStdOutCallbackHandler | |
| logging.basicConfig(level=logging.INFO) | |
| logger = logging.getLogger(__name__) | |
| app = FastAPI() | |
| MODEL_NAME = 'tinyllama' | |
| def get_llm(): | |
| callback_manager = CallbackManager([StreamingStdOutCallbackHandler()]) | |
| return Ollama(model=MODEL_NAME, callback_manager=callback_manager) | |
| class Question(BaseModel): | |
| text: str | |
| def read_root(): | |
| return {"Hello": f"Welcome to {MODEL_NAME} FastAPI"} | |
| async def startup_event(): | |
| logger.info(f"Starting up with model: {MODEL_NAME}") | |
| async def shutdown_event(): | |
| logger.info("Shutting down") |