Download app.py from Lilpulgp/dgffdfdf: direct link, hf CLI and curl.
- Browser
- Download file 1.13 kB
-
https://huggingface.co/spaces/Lilpulgp/dgffdfdf/resolve/main/app.py
- Command line
-
hf download hf://spaces/Lilpulgp/dgffdfdf/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Lilpulgp/dgffdfdf/resolve/main/app.py
1.13 kB
| from fastapi import FastAPI, HTTPException | |
| from pydantic import BaseModel | |
| from langchain_community.llms import Ollama | |
| import uvicorn | |
| import asyncio | |
| import os | |
| import sys | |
| app = FastAPI() | |
| os.system("ollama serve &") | |
| os.system("ollama pull hf.co/mradermacher/Llama-3.2-8X3B-MOE-Dark-Champion-Instruct-uncensored-abliterated-18.4B-i1-GGUF:IQ1_S") | |
| # Initialize Ollama outside the endpoint (only once at startup) | |
| llm = Ollama(model="hf.co/mradermacher/Llama-3.2-8X3B-MOE-Dark-Champion-Instruct-uncensored-abliterated-18.4B-i1-GGUF:IQ1_S") | |
| class QueryRequest(BaseModel): | |
| query: str | |
| async def generate_text(request: QueryRequest): | |
| """ | |
| Endpoint to generate text using Ollama. | |
| Receives a JSON payload with a 'query' field. | |
| Returns: | |
| dict: A JSON response containing the original query and the generated text. | |
| """ | |
| try: | |
| result = await asyncio.to_thread(llm.invoke, request.query) | |
| return {result} | |
| except Exception as e: | |
| raise HTTPException(status_code=500, detail=str(e)) | |
| if __name__ == "__main__": | |
| uvicorn.run(app, host="0.0.0.0", port=7860) |