Spaces:
Runtime error
Runtime error
Download summary_api.py from abhidgp1978/AskGemma: direct link, hf CLI and curl.
- Browser
- Download file 863 Bytes
-
https://huggingface.co/spaces/abhidgp1978/AskGemma/resolve/main/summary_api.py
- Command line
-
hf download hf://spaces/abhidgp1978/AskGemma/summary_api.py
-
curl -L -o summary_api.py https://huggingface.co/spaces/abhidgp1978/AskGemma/resolve/main/summary_api.py
863 Bytes
| # ✅ summary_api.py | |
| from fastapi import FastAPI, Request | |
| from pydantic import BaseModel | |
| from ctransformers import AutoModelForCausalLM | |
| import uvicorn | |
| app = FastAPI() | |
| # 🔗 Load model directly from Hugging Face Hub repo | |
| MODEL_REPO = "abhidgp1978/mistral-local" | |
| MODEL_FILE = "gemma-2b-it.gguf" | |
| llm = AutoModelForCausalLM.from_pretrained( | |
| MODEL_REPO, | |
| model_file=MODEL_FILE, | |
| model_type="gemma", | |
| local_files_only=False | |
| ) | |
| class PromptInput(BaseModel): | |
| data: list[str] | |
| def generate_summary(req: PromptInput): | |
| prompt = req.data[0].strip() | |
| if not prompt: | |
| return ["⚠️ Empty input."] | |
| output = llm(prompt, max_new_tokens=256, temperature=0.7) | |
| return [output.strip() if output else "⚠️ No output generated."] | |
| if __name__ == "__main__": | |
| uvicorn.run(app, host="0.0.0.0", port=7860) | |