Text Generation
Transformers
Safetensors
English
phi3
phi
nlp
math
code
chat
conversational
reasoning
text-generation-inference
Instructions to use Ashok75/base2 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Ashok75/base2 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="Ashok75/base2") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("Ashok75/base2") model = AutoModelForCausalLM.from_pretrained("Ashok75/base2", device_map="auto") messages = [ {"role": "user", "content": "Who are you?"}, ] inputs = tokenizer.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=40) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use Ashok75/base2 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "Ashok75/base2" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Ashok75/base2", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/Ashok75/base2
- SGLang
How to use Ashok75/base2 with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "Ashok75/base2" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Ashok75/base2", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "Ashok75/base2" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Ashok75/base2", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use Ashok75/base2 with Docker Model Runner:
docker model run hf.co/Ashok75/base2
| #!/usr/bin/env python3 | |
| """ | |
| run.py - FastAPI backend + frontend server for GAKR AI | |
| Features: | |
| - Serves templates/chat.html at "/" | |
| - /api/analyze: | |
| - prompt: required (must not be empty) | |
| - files: optional list[UploadFile] (0, 1, many; any type) | |
| - api_key: required | |
| - If files are present β file-analysis mode (different system prompt) | |
| - If no files β general assistant mode | |
| - Detailed exceptions and logs for easier debugging | |
| """ | |
| from typing import List, Optional | |
| import json | |
| import traceback | |
| from fastapi import ( | |
| FastAPI, | |
| HTTPException, | |
| Form, | |
| UploadFile, | |
| File, | |
| Request, | |
| ) | |
| from fastapi.middleware.cors import CORSMiddleware | |
| from fastapi.responses import HTMLResponse, JSONResponse, StreamingResponse | |
| from fastapi.templating import Jinja2Templates | |
| import uvicorn | |
| from load_model import init_model | |
| from generate import generate_response | |
| from file_pipeline import process_files | |
| # ============================================================ | |
| # APP SETUP | |
| # ============================================================ | |
| app = FastAPI(title="GAKR AI") | |
| # Templates (chat.html lives in ./templates) | |
| templates = Jinja2Templates(directory="templates") | |
| # CORS (open for dev; restrict origins in production) | |
| app.add_middleware( | |
| CORSMiddleware, | |
| allow_origins=["*"], # change to specific origin in production | |
| allow_credentials=True, | |
| allow_methods=["*"], | |
| allow_headers=["*"], | |
| ) | |
| # API Key | |
| API_KEY = "gakr-ai-2025-secret" | |
| # Load model ONCE at startup | |
| print("π Starting GAKR AI Backend...") | |
| try: | |
| model, tokenizer = init_model(".") | |
| print("β Model initialized successfully") | |
| except Exception as e: | |
| print("β Failed to load model at startup:") | |
| traceback.print_exc() | |
| raise e | |
| # ============================================================ | |
| # ROUTES | |
| # ============================================================ | |
| async def home(request: Request): | |
| """ | |
| Serve chat.html as homepage. | |
| """ | |
| try: | |
| return templates.TemplateResponse("chat.html", {"request": request}) | |
| except Exception as e: | |
| # If template not found or other template error | |
| traceback.print_exc() | |
| raise HTTPException( | |
| status_code=500, | |
| detail=f"Failed to render chat.html: {str(e)}", | |
| ) | |
| async def analyze_endpoint( | |
| prompt: str = Form(...), # required | |
| api_key: str = Form(...), | |
| files: Optional[List[UploadFile]] = File(None), # optional | |
| ): | |
| """ | |
| Main analysis endpoint. | |
| Cases: | |
| - prompt only (no files) β general assistant mode | |
| - prompt + one/many files β file-analysis mode (uses file context) | |
| """ | |
| try: | |
| # ---------- Basic validation ---------- | |
| if api_key != API_KEY: | |
| raise HTTPException(status_code=401, detail="Invalid API key") | |
| if prompt is None: | |
| raise HTTPException(status_code=400, detail="Prompt is missing") | |
| if not prompt.strip(): | |
| raise HTTPException(status_code=400, detail="Prompt cannot be empty") | |
| files = files or [] | |
| # ---------- Branch by presence of files ---------- | |
| if files: | |
| # ----- CASE 1: prompt + files ----- | |
| try: | |
| context = await process_files(files) | |
| except Exception as extract_err: | |
| traceback.print_exc() | |
| raise HTTPException( | |
| status_code=500, | |
| detail=f"Error while processing uploaded files: {str(extract_err)}", | |
| ) | |
| context_text = json.dumps(context, indent=2, ensure_ascii=False) | |
| combined_user_prompt = f""" | |
| User question: | |
| {prompt} | |
| Below is structured information extracted from the user's uploaded files. | |
| The extraction was done by automated tools. | |
| Your task: | |
| 1. Answer the user's question as accurately as possible. | |
| 2. Use the context when it is relevant. | |
| 3. Highlight important patterns, risks, or opportunities. | |
| 4. If some information is missing or uncertain, say so honestly. | |
| Context: | |
| {context_text} | |
| """ | |
| system_prompt = ( | |
| "You are GAKR AI, a careful and honest analysis assistant that works with " | |
| "structured summaries of files (tables, PDFs, documents, images, audio, video, etc.). " | |
| "You never assume file contents beyond what the provided context states. " | |
| "You are a reasoning-focused AI assistant. " | |
| "Think carefully before answering. " | |
| "Provide clear, correct answers with brief explanations when helpful. " | |
| ) | |
| else: | |
| # ----- CASE 2: prompt only ----- | |
| context = {"files": []} # keep structure consistent | |
| combined_user_prompt = prompt | |
| system_prompt = ( | |
| "You are GAKR AI, a reasoning-focused AI assistant. " | |
| "Think carefully before answering. " | |
| "Provide clear, correct answers with brief explanations when helpful. " | |
| ) | |
| # ---------- Generate with Phi-4 ---------- | |
| try: | |
| response_generator = generate_response( | |
| user_prompt=combined_user_prompt, | |
| system_prompt=system_prompt, | |
| max_tokens=32768, | |
| stream=True, | |
| ) | |
| except Exception as gen_err: | |
| traceback.print_exc() | |
| raise HTTPException( | |
| status_code=500, | |
| detail=f"Error during model generation: {str(gen_err)}", | |
| ) | |
| return StreamingResponse( | |
| response_generator, | |
| media_type="text/plain", | |
| ) | |
| except HTTPException: | |
| # Let FastAPI handle HTTPException as-is | |
| raise | |
| except Exception as e: | |
| # Unexpected error: log full traceback and return 500 | |
| traceback.print_exc() | |
| raise HTTPException( | |
| status_code=500, | |
| detail=f"Unexpected backend error: {str(e)}", | |
| ) | |
| async def health_check(): | |
| """ | |
| Simple health check. | |
| """ | |
| return {"status": "healthy", "model_loaded": True} | |
| # ============================================================ | |
| # ENTRY POINT | |
| # ============================================================ | |
| if __name__ == "__main__": | |
| print("\n" + "=" * 60) | |
| print("π SERVER & CHAT LOCATION") | |
| print("=" * 60) | |
| print("π CHAT INTERFACE: http://localhost:8080") | |
| print("π± ALTERNATIVE URL: http://127.0.0.1:8080") | |
| print("π§ API DOCUMENTATION: http://localhost:8080/docs") | |
| print("β CHAT.HTML SERVED: templates/chat.html") | |
| print("π TEMPLATES FOLDER: ./templates/") | |
| print("=" * 60 + "\n") | |
| uvicorn.run(app, host="0.0.0.0", port=8080) | |