Download app/main.py from Waredocs/model1: direct link, hf CLI and curl.
- Browser
- Download file 825 Bytes
-
https://huggingface.co/spaces/Waredocs/model1/resolve/main/app/main.py
- Command line
-
hf download hf://spaces/Waredocs/model1/app/main.py
-
curl -L -o main.py https://huggingface.co/spaces/Waredocs/model1/resolve/main/app/main.py
825 Bytes
| from fastapi import FastAPI | |
| from pydantic import BaseModel | |
| from transformers import pipeline, AutoTokenizer, AutoModelForCausalLM | |
| from huggingface_hub import login | |
| import os | |
| # Authenticate with Hugging Face | |
| login(token=os.getenv("HF_TOKEN")) | |
| app = FastAPI() | |
| pipe = pipeline("text-generation", model="mistralai/Mistral-Small-24B-Instruct-2501") | |
| tokenizer = AutoTokenizer.from_pretrained("mistralai/Mistral-Small-24B-Instruct-2501") | |
| model = AutoModelForCausalLM.from_pretrained("mistralai/Mistral-Small-24B-Instruct-2501") | |
| class ChatRequest(BaseModel): | |
| messages: list | |
| def read_root(): | |
| return {"message": "Waredocs LLM API is running!"} | |
| def ask_question(prompt: str): | |
| messages = [{"role": "user", "content": prompt}] | |
| result = pipe(prompt, max_length=200) | |
| return result[0] |